Sunday 7 April 2019

openCMIS: Get the attributes associated with the rendition


How to get the renditions associated with a document?
Document, Folders interfaces provides 'getRenditions()' method to retrieve all the renditions associated with them.

List<Rendition> getRenditions()
Returns the renditions if they have been fetched for this object, else return null if the renditions have not been requested or no renditions exist for this object

Following snippet prints all the renditions associated with a document, same is the case with folders also.

                  List<Rendition> renditions = document.getRenditions();
                 
                  if(renditions == null){
                           System.out.println("No renditions are existed for this object");
                           return;
                  }
                 
                  for(Rendition rendition: renditions){
                           System.out.println(rendition);
                  }

Find the following working application.

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.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){
   System.out.println(rendition);
  }
  
 }

}

Below table summarizes the attributes that are associated with a rendition.

Attribute
Description
Data type
streamId
Identifies the rendition stream.
Id
mimeType
The MIME type of the rendition stream.
String
length
The length of the rendition stream in bytes.
Integer
title
Human readable information about the rendition.
String (optional)

kind
A categorization String associated with the rendition.
String
height
Typically used for 'image' renditions (expressed as pixels). SHOULD be present if kind = cmis:thumbnail.

Integer (optional)
width
Typically used for 'image' renditions (expressed as pixels).
SHOULD be present if kind = cmis:thumbnail.
Integer (optional)
renditionDocumentId
If 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. Referential integrity of this id is repository specific.
Id (optional)

Below function prints the attributes associated with rendition.

         private static void printRendition(Rendition rendition) {
                  BigInteger bigHeight = rendition.getBigHeight();
                  BigInteger bigLength = rendition.getBigLength();
                  BigInteger bigWidth = rendition.getBigWidth();
                  String contentURL = rendition.getContentUrl();
                  long height = rendition.getHeight();

                  String kind = rendition.getKind();
                  long length = rendition.getLength();
                  String mimeType = rendition.getMimeType();
                  String documentId = rendition.getRenditionDocumentId();
                  String streamId = rendition.getStreamId();
                  String title = rendition.getTitle();
                  long width = rendition.getWidth();

                  System.out.println("bigHeight : " + bigHeight);
                  System.out.println("bigLength : " + bigLength);
                  System.out.println("bigWidth : " + bigWidth);
                  System.out.println("contentURL : " + contentURL);
                  System.out.println("height : " + height);
                  System.out.println("kind : " + kind);
                  System.out.println("length : " + length);
                  System.out.println("mimeType : " + mimeType);
                  System.out.println("documentId : " + documentId);
                  System.out.println("streamId : " + streamId);
                  System.out.println("title : " + title);
                  System.out.println("width : " + width);

         }

Following is the complete working application.


TestCmis.java

package com.sample.util;

import java.io.IOException;
import java.math.BigInteger;
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.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);
 }

 private static void printRendition(Rendition rendition) {
  BigInteger bigHeight = rendition.getBigHeight();
  BigInteger bigLength = rendition.getBigLength();
  BigInteger bigWidth = rendition.getBigWidth();
  String contentURL = rendition.getContentUrl();
  long height = rendition.getHeight();

  String kind = rendition.getKind();
  long length = rendition.getLength();
  String mimeType = rendition.getMimeType();
  String documentId = rendition.getRenditionDocumentId();
  String streamId = rendition.getStreamId();
  String title = rendition.getTitle();
  long width = rendition.getWidth();

  System.out.println("bigHeight : " + bigHeight);
  System.out.println("bigLength : " + bigLength);
  System.out.println("bigWidth : " + bigWidth);
  System.out.println("contentURL : " + contentURL);
  System.out.println("height : " + height);
  System.out.println("kind : " + kind);
  System.out.println("length : " + length);
  System.out.println("mimeType : " + mimeType);
  System.out.println("documentId : " + documentId);
  System.out.println("streamId : " + streamId);
  System.out.println("title : " + title);
  System.out.println("width : " + width);

 }

 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) {
   printRendition(rendition);
  }

 }

}




Previous                                                 Next                                                 Home

No comments:

Post a Comment