Wednesday 3 April 2019

openCMIS: Working with document content stream


Every document has a content stream associated with it, it is a binary stream. openCMIS provides following method to perform CRUD operations on content streams.
         a. Setting the content stream for the document
         b. Getitng the content stream of the document
         c. Append content stream to the document
         d. Delete content stream of the document

Not all the repositories allow you to set, delete the content stream. RepositoryCapabilities interface provides 'getContentStreamUpdatesCapability' method to check whether repository supports content stream updates or not.

Example
CapabilityContentStreamUpdates capabilityContentStreamUpdates = session.getRepositoryInfo().getCapabilities().getContentStreamUpdatesCapability();

Following are the valid values of CapabilityContentStreamUpdates.
Value
Description
none
The content stream may never be updated.
anytime
The content stream may be updated any time.
pwconly
The content stream may be updated only when checked out.

Below snippet is used to check the level of content stream support by the repository.

                  CapabilityContentStreamUpdates capabilityContentStreamUpdates = session.getRepositoryInfo().getCapabilities().getContentStreamUpdatesCapability();

                  if (capabilityContentStreamUpdates == null) {
                           System.out.println("Repository do not provide this value");
                  } else if (CapabilityContentStreamUpdates.NONE == capabilityContentStreamUpdates) {
                           System.out.println("Content stream may never be updated.");
                  } else if (CapabilityContentStreamUpdates.ANYTIME == capabilityContentStreamUpdates) {
                           System.out.println("Content stream can be updated any time.");
                  } else if (CapabilityContentStreamUpdates.PWCONLY == capabilityContentStreamUpdates) {
                           System.out.println("Content stream is updated only when the document is checked out. PWC stands for Private Working Copy.");
                  } else {
                           System.out.println("It is not implemented as per the CMIS Specification");
                  }
                 
Following is the complete working application.

TestCmis.java

package com.sample.util;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.enums.CapabilityContentStreamUpdates;

public class TestCmis {

 private static String serverURL = "http://localhost:8080/chemistry-opencmis-server-inmemory-1.1.0/browser";
 private static String repositoryId = "A1";

 private static Session getSession() {
  Map<String, String> parameters = new HashMap<>();
  parameters.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());

  parameters.put(SessionParameter.USER, "");
  parameters.put(SessionParameter.PASSWORD, "");

  parameters.put(SessionParameter.REPOSITORY_ID, repositoryId);
  parameters.put(SessionParameter.BROWSER_URL, serverURL);

  SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
  return sessionFactory.createSession(parameters);
 }

 public static void main(String args[]) throws IOException {

  Session session = getSession();

  CapabilityContentStreamUpdates capabilityContentStreamUpdates = session.getRepositoryInfo().getCapabilities().getContentStreamUpdatesCapability();

  if (capabilityContentStreamUpdates == null) {
   System.out.println("Repository do not provide this value");
  } else if (CapabilityContentStreamUpdates.NONE == capabilityContentStreamUpdates) {
   System.out.println("Content stream may never be updated.");
  } else if (CapabilityContentStreamUpdates.ANYTIME == capabilityContentStreamUpdates) {
   System.out.println("Content stream can be updated any time.");
  } else if (CapabilityContentStreamUpdates.PWCONLY == capabilityContentStreamUpdates) {
   System.out.println("Content stream is updated only when the document is checked out. PWC stands for Private Working Copy.");
  } else {
   System.out.println("It is not implemented as per the CMIS Specification");
  }
 }

}

Output
Content stream can be updated any time.        



Previous                                                 Next                                                 Home

No comments:

Post a Comment