1. Overview
This tutorial explains how documents can be deleted using the Core API with the help of a Java client. This tutorial requires basic knowledge of importing documents using the Core API.
Check out our graphical overview of the architecture which describes the basic use case flow for deleting content.
2. Requirements
To work through this tutorial, the following is required:
-
Set-up yuuvis® API system (see Installation Guide)
-
A user with at least read permissions on a document type in the system (see tutorial for permissions)
-
Simple Maven project
3. Maven Configuration
Our Java client will submit its requests to the Core API using OkHttp 3.12 by Square, Inc. Therefore, the following block must be added to the Maven dependencies in the pom.xml
of the project:
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.12.0</version>
</dependency>
4. Client Configuration
To interact with the yuuvis® API system via the Core API, we use an OkHttp3 client to send HTTP requests and read their responses.
String baseUrl = "http://127.0.0.1"; //baseUrl of gateway: "http://<host>:<port>"
String username = "clouduser";
String userpassword = "secret";
String tenant = "default";
String auth = java.util.Base64.getEncoder().encodeToString((username + ":" + userpassword).getBytes());
OkHttpClient.Builder builder = new OkHttpClient.Builder();
OkHttpClient client = builder.build();
For more information on setting up the OkHttp3 client with cookie handling, please refer to this Login Tutorial.
5. Deleting a Document
To delete a document from the system, a DELETE request must be sent to the endpoint /api/dms/objects/{objectId}
for the corresponding object ID. This deletes the metadata record and, if present, the content file.
Request deleteRequest = new Request.Builder()
.header("Authorization", "Basic "+ auth)
.header("X-ID-TENANT-NAME", tenant)
.url(baseUrl + "/api/dms/objects/" + objectId) //baseUrl: "http://<host>:<port>"
.delete().build();
6. Deleting a Version of a Document
To delete a version of a document from the system, a DELETE request must be sent to the endpoint /api/dms/objects/{objectId}/versions/{versionNr}
. The corresponding version number must exist for the document. If the specified version number indicates the current version of the document, the entire document including all associated versions will be deleted.
Request deleteVersionRequest = new Request.Builder()
.header("X-ID-TENANT-NAME", "default")
.header("Authorization", "Basic "+ auth)
.url(baseUrl + "objects/"+objectId+"/versions/1") //baseUrl: "http://<host>:<port>"
.delete().build();
Response deleteVersionResponse = client.newCall(deleteVersionRequest).execute();
7. Deleting a Document with Binary Content
During the deletion of documents with binary content, yuuvis® Momentum searches for other documents that might refer to the same binary content file. It is identified by the content stream properties contentStreamId
and repositoryId
. Current object versions are considered as well as older versions.
-
If there are NO further references on the binary content, the document’s metadata AND binary content are deleted.
-
If there is at least one reference on the binary content, ONLY the metadata of the requested object are deleted.
Thus, the binary content is available for all remaining documents (an document versions) that still refer to it.
8. Deleting Compound Documents
Deleting compound documents is a special case of deleting documents with binary content. The chapter Using Compound Documents describes what compound documents are and what to consider when deleting compound documents.
9. Summary
In this tutorial an OkHttpClient with cookie handling was used to delete an object or a certain version of the object.
The complete code example can be found in the Git repository.