1. Overview

In this tutorial, we will delete a DMS object of which we know the value for system:objectId.

2. Requirements

Please work through the following tutorials to get prepared:

3. Java Libraries

Import the following Java libraries (if not already done).

Used Java Libraries
import okhttp3.*;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.util.Base64;

4. Variables with Login and Content Types Configuration

Specify your access credentials and content type configurations (if not already done).

Specify the objectId variable.

Definition of Variables
public static final String username = "root";
public static final String userpassword = "changeme";
public static final String auth = "Basic "+ Base64.getEncoder().encodeToString((username+":"+userpassword).getBytes());
public static final String tenant = "myfirsttenant";
public static final String baseUrl = "http://123.456.78.9:30080";

public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
public static final MediaType PLAINTEXT = MediaType.parse("text/plain; charset=utf-8");

public static final String objectId = "ecc0f6cc-7467-4e02-9903-073b893afdfd";

5. Client

To send our requests, we again use the Java client.

Client with Cookie Handling
try {
    CookieJar cookieJar = new JavaNetCookieJar(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
    OkHttpClient client = new OkHttpClient.Builder().cookieJar(cookieJar).build();

} catch (Exception e) {
    e.printStackTrace();

}

6. Deleting a Single Object

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.

Deleting a Document
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();

7. 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.

Deleting a Version of a Document
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();

8. 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.

9. 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.

10. 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.