Monday, 8 April 2019

openCMIS: Access the content associated with rendition


There are three ways to access a document associated with a rendition.

a. By using the rendition stream id
b. By calling the 'getRenditionDocument()' method on Rendition instance.
c. By using the 'renditionDocumentId'.

By using the rendition stream id
A rendition stream can be retrieved using the getContentStream service with the rendition's streamId parameter.

Following statements are used to get the content stream associated with renditon.

String rendtionStreamId = rendition.getStreamId();
ContentStream contentStream = session.getContentStream(new ObjectIdImpl(document.getId()), rendtionStreamId,null, null);

TestCmis.java
package com.sample.util;

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

import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Rendition;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.enums.BindingType;

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();

  Document document = (Document) session.getObjectByPath("/sampleDoc.json");

  List<Rendition> renditions = document.getRenditions();

  if (renditions == null) {
   System.out.println("No renditions are existed for this object");
   return;
  }

  for (Rendition rendition : renditions) {
   String rendtionStreamId = rendition.getStreamId();
   ContentStream contentStream = session.getContentStream(new ObjectIdImpl(document.getId()), rendtionStreamId,
     null, null);
  }

 }

}

By calling the 'getRenditionDocument()' method on Rendition instance.

Following statements are used to get the content stream associated with rendition.

Document rendtionDocument = rendition.getRenditionDocument();
ContentStream contentStream = rendtionDocument.getContentStream();


TestCmis.java
package com.sample.util;

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

import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Rendition;
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.data.ContentStream;
import org.apache.chemistry.opencmis.commons.enums.BindingType;

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();

  Document document = (Document) session.getObjectByPath("/sampleDoc.json");

  List<Rendition> renditions = document.getRenditions();

  if (renditions == null) {
   System.out.println("No renditions are existed for this object");
   return;
  }

  for (Rendition rendition : renditions) {
   Document rendtionDocument = rendition.getRenditionDocument();
   ContentStream contentStream = rendtionDocument.getContentStream();

  }

 }

}

By using the 'renditionDocumentId'.
If 'renditionDocumentId' is specified, then the rendition can also be accessed as a document object in the CMIS services. If not set, then the rendition can only be accessed via the rendition services.

Following statements are used to get the cmis object associated with given renditon id.

                           String renditionDocId = rendition.getRenditionDocumentId();
                          
                           if(renditionDocId == null){
                                    continue;
                           }
                          
                           CmisObject cmisObject = session.getObject(renditionDocId);


TestCmis.java
package com.sample.util;

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

import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Rendition;
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;

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();

  Document document = (Document) session.getObjectByPath("/sampleDoc.json");

  List<Rendition> renditions = document.getRenditions();

  if (renditions == null) {
   System.out.println("No renditions are existed for this object");
   return;
  }

  for (Rendition rendition : renditions) {
   String renditionDocId = rendition.getRenditionDocumentId();
   
   if(renditionDocId == null){
    continue;
   }
   
   CmisObject cmisObject = session.getObject(renditionDocId);
  }

 }

}




Previous                                                 Next                                                 Home

No comments:

Post a Comment