Retrieving Content of a Document Revision

Assuming you have a specific number n of versions of a document in the repository. Now you like to retrieve the contents of a particular revision of that document.

Solution Code

To retrieve the content of a particular revision we use the retrieveDocumentContent() method of the DocumentManagementService and pass the RevisionId.

The sample code looks like below:

package com.sungard.bootcamp.client;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.stardust.engine.api.runtime.DmsUtils;
import org.eclipse.stardust.engine.api.runtime.Document;
import org.eclipse.stardust.engine.api.runtime.DocumentInfo;
import org.eclipse.stardust.engine.api.runtime.DocumentManagementService;
import org.eclipse.stardust.engine.api.runtime.ServiceFactory;
import org.eclipse.stardust.engine.api.runtime.ServiceFactoryLocator;
import ag.carnot.workflow.runtime.beans.removethis.SecurityProperties;

public class DMSClient {
   public static void main(String[] args) {
      // Obtain a reference to the ServiceFactory
      ServiceFactory sf = getServiceFactory(null, null, null, "motu", "motu");
      DocumentManagementService dmsService = sf.getDocumentManagementService(); 
      // pass the documentId to get the document versions of that document 
      List<Document> list = dmsService.getDocumentVersions("{jcrUuid}05044280-8411-4fd8-8927-99b23560e4c3"); 
      for(int i=0;i<list.size();i++){
         Document document = (Document)list.get(i);
         System.out.println("DocumentID :: " + document.getId()); 
         System.out.println("Document RevisionId :: " +document.getRevisionId());
         System.out.println("Document RevisionName :: "+ document.getRevisionName());
         System.out.println("Document Contents :: " + new String(
   // Return ServiceFactory
   private static ServiceFactory getServiceFactory(String partition,
   String domain, String realm, String user, String password) {
      Map properties = new HashMap();
      properties.put(SecurityProperties.PARTITION, partition);
      properties.put(SecurityProperties.DOMAIN, domain);
      properties.put(SecurityProperties.REALM, realm);
      return ServiceFactoryLocator.get(user, password, properties);

The following API is used in this example:

Example Output

The output of the above program could look similar like below. We are assuming that there exist two versions of the document.

DocumentID :: {jcrUuid}05044280-8411-4fd8-8927-99b23560e4c3
Document RevisionId :: {jcrRev}eb025fef-5609-4f42-911c-abd0ba1125bb
Document RevisionName :: 1.0
Document Contents :: This is a test document.. 
DocumentID :: {jcrUuid}05044280-8411-4fd8-8927-99b23560e4c3
Document RevisionId :: {jcrRev}1cc5d11a-9dbd-4733-b451-c0732458c36f
Document RevisionName :: 1.1
Document Contents :: This is the UPDATED document..