Wednesday, 17 April 2019

openCmis: Working with metadata


Metadata is data about data, it describes about the document like last modification date, content updated by whom, is document can be version able, MIME type of the document etc.,

Why do we require metadata?
By using metadata we can make the search fast, we can check when the document is updated, we can check whether the object we had is the latest or not etc.,

Classification of object in CMIS
CMIS defines two classification of objects
a.   Type Objects
b.   Data Objects

Type Objects
Type objects are used to define schema (metadata) of data objects. You can assume, Type objects are collection of properties, that describes data objects.

Data Objects
Data objects hold actual content. For example, Folders and Documents are data objects. Data Object is described by Type Object. Every data object has one type object, to describe about them.

Each data object is associated with a type object with them. Type object associated with the data object describe about the object. Types inherit the properties from their parent types.

Following application print all the types and their children types.

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.ObjectType;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.api.Tree;
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";

 public 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 printType(Tree<ObjectType> types, String space) {

  ObjectType objType = types.getItem();

  System.out.println(space + "[id : " + objType.getId() + "], [Display Name : " + objType.getDisplayName()
    + "], [Description : " + objType.getDescription() + "]");

  List<Tree<ObjectType>> objTypes = types.getChildren();

  for (Tree<ObjectType> objTypeTemp : objTypes) {
   printType(objTypeTemp, space + " ");
  }
 }

 public static void main(String args[]) throws IOException {
  Session session = getSession();

  List<Tree<ObjectType>> types = session.getTypeDescendants(null, -1, true);

  for (Tree<ObjectType> typeTemp : types) {
   printType(typeTemp, "");
  }

 }
}


Output
[id : cmis:secondary], [Display Name : Secondary], [Description : Secondary]
 [id : MySecondaryType], [Display Name : MySecondaryType], [Description : Builtin InMemory type definition MySecondaryType]
[id : cmis:item], [Display Name : Item], [Description : Item]
 [id : MyItemType], [Display Name : MyItemType], [Description : Builtin InMemory type definition MyItemType]
[id : cmis:relationship], [Display Name : Relationship], [Description : Relationship]
 [id : CrossReferenceType], [Display Name : CrossReferenceType], [Description : Builtin InMemory type definition CrossReferenceType]
[id : cmis:policy], [Display Name : Policy], [Description : Policy]
 [id : AuditPolicy], [Display Name : Audit Policy], [Description : Builtin InMemory type definition AuditPolicy]
[id : cmis:folder], [Display Name : Folder], [Description : Folder]
[id : cmis:document], [Display Name : Document], [Description : Document]
 [id : MyDocType1], [Display Name : My Type 1 Level 1], [Description : Builtin InMemory type definition MyDocType1]
  [id : MyDocType1.1], [Display Name : My Type 3 Level 2], [Description : Builtin InMemory type definition MyDocType1.1]
   [id : MyDocType1.1.1], [Display Name : My Type 4 Level 3], [Description : Builtin InMemory type definition MyDocType1.1.1]
   [id : MyDocType1.1.2], [Display Name : My Type 5 Level 3], [Description : Builtin InMemory type definition MyDocType1.1.2]
  [id : MyDocType1.2], [Display Name : My Type 6 Level 2], [Description : Builtin InMemory type definition MyDocType1.2]
 [id : MyDocType2], [Display Name : My Type 2 Level 1], [Description : Builtin InMemory type definition MyDocType2]
  [id : MyDocType2.1], [Display Name : My Type 7 Level 2], [Description : Builtin InMemory type definition MyDocType2.1]
  [id : MyDocType2.2], [Display Name : My Type 8 Level 2], [Description : Builtin InMemory type definition MyDocType2.2]
  [id : MyDocType2.3], [Display Name : My Type 9 Level 2], [Description : Builtin InMemory type definition MyDocType2.3]
  [id : MyDocType2.4], [Display Name : My Type 10 Level 2], [Description : Builtin InMemory type definition MyDocType2.4]
  [id : MyDocType2.5], [Display Name : My Type 11 Level 2], [Description : Builtin InMemory type definition MyDocType2.5]
  [id : MyDocType2.6], [Display Name : My Type 12 Level 2], [Description : Builtin InMemory type definition MyDocType2.6]
  [id : MyDocType2.7], [Display Name : My Type 13 Level 2], [Description : Builtin InMemory type definition MyDocType2.7]
  [id : MyDocType2.8], [Display Name : My Type 14 Level 2], [Description : Builtin InMemory type definition MyDocType2.8]
  [id : MyDocType2.9], [Display Name : My Type 15 Level 2], [Description : Builtin InMemory type definition MyDocType2.9]
 [id : ComplexType], [Display Name : Complex type with properties, Level 1], [Description : Builtin InMemory type definition ComplexType]
 [id : DocumentTopLevel], [Display Name : Document type with properties, Level 1], [Description : Builtin InMemory type definition DocumentTopLevel]
  [id : DocumentLevel1], [Display Name : Document type with inherited properties, Level 2], [Description : Builtin InMemory type definition DocumentLevel1]
   [id : DocumentLevel2], [Display Name : Document type with inherited properties, Level 3], [Description : Builtin InMemory type definition DocumentLevel2]
 [id : VersionableType], [Display Name : Versioned Type], [Description : Builtin InMemory type definition VersionableType]
 [id : BigContentFakeType], [Display Name : BigContentFakeType], [Description : Builtin InMemory type definition for big content streams. Content is ignored and replaced by random bytes]
 [id : audioFile], [Display Name : Audio File], [Description : Audio Content (compressed or uncompressed)]
 [id : emailDocument], [Display Name : Email Document], [Description : Document of type Email]
 [id : exifImage], [Display Name : EXIF Image], [Description : Image with EXIF tags]
 [id : officeDocument], [Display Name : Office Document], [Description : Document of type Office]
  [id : pdfDocument], [Display Name : PDF Document], [Description : Document of type PDF]
 [id : videoFile], [Display Name : Video File], [Description : Video Movies]

Property Definitions
As I said, every data object is described by type object. Type object is described by collection of properties, whereas every property is properly defined by using property definitions.

For example,
Document object is described by document type, where as document type has following properties.

cmis:name
cmis:description
cmis:objectId
cmis:baseTypeId
cmis:objectTypeId
cmis:secondaryObjectTypeIds
cmis:createdBy
cmis:creationDate
cmis:lastModifiedBy
cmis:lastModificationDate
cmis:changeToken
cmis:isImmutable
cmis:isLatestVersion
cmis:isMajorVersion
cmis:isLatestMajorVersion
cmis:isPrivateWorkingCopy
cmis:versionLabel
cmis:versionSeriesId
cmis:isVersionSeriesCheckedOut
cmis:versionSeriesCheckedOutBy
cmis:versionSeriesCheckedOutId
cmis:checkinComment
cmis:contentStreamLength
cmis:contentStreamMimeType
cmis:contentStreamFileName
cmis:contentStreamId

Where as each property is well defined. For example, the property ‘cmis:name’ is described by attributes like ‘displayName’, ‘type’ of the property (like integer, boolean, string), ‘id’ of the property (id is used to uniquely identify the property), default value associated with this property etc.,


For example, following are the property definitions for above properties.

id : cmis:name, displayName : Name, propertyType : STRING, defaultValue : []
id : cmis:description, displayName : Description, propertyType : STRING, defaultValue : []
id : cmis:objectId, displayName : Object Id, propertyType : ID, defaultValue : []
id : cmis:baseTypeId, displayName : Base Type Id, propertyType : ID, defaultValue : []
id : cmis:objectTypeId, displayName : Object Type Id, propertyType : ID, defaultValue : []
id : cmis:secondaryObjectTypeIds, displayName : Secondary Type Ids, propertyType : ID, defaultValue : []
id : cmis:createdBy, displayName : Created By, propertyType : STRING, defaultValue : []
id : cmis:creationDate, displayName : Creation Date, propertyType : DATETIME, defaultValue : []
id : cmis:lastModifiedBy, displayName : Last Modified By, propertyType : STRING, defaultValue : []
id : cmis:lastModificationDate, displayName : Last Modification Date, propertyType : DATETIME, defaultValue : []
id : cmis:changeToken, displayName : Change Token, propertyType : STRING, defaultValue : []
id : cmis:isImmutable, displayName : Is Immutable, propertyType : BOOLEAN, defaultValue : []
id : cmis:isLatestVersion, displayName : Is Latest Version, propertyType : BOOLEAN, defaultValue : []
id : cmis:isMajorVersion, displayName : Is Major Version, propertyType : BOOLEAN, defaultValue : []
id : cmis:isLatestMajorVersion, displayName : Is Latest Major Version, propertyType : BOOLEAN, defaultValue : []
id : cmis:isPrivateWorkingCopy, displayName : Is Private Working Copy, propertyType : BOOLEAN, defaultValue : []
id : cmis:versionLabel, displayName : Version Label, propertyType : STRING, defaultValue : []
id : cmis:versionSeriesId, displayName : Version Series Id, propertyType : ID, defaultValue : []
id : cmis:isVersionSeriesCheckedOut, displayName : Is Verison Series Checked Out, propertyType : BOOLEAN, defaultValue : []
id : cmis:versionSeriesCheckedOutBy, displayName : Version Series Checked Out By, propertyType : STRING, defaultValue : []
id : cmis:versionSeriesCheckedOutId, displayName : Version Series Checked Out Id, propertyType : ID, defaultValue : []
id : cmis:checkinComment, displayName : Checkin Comment, propertyType : STRING, defaultValue : []
id : cmis:contentStreamLength, displayName : Content Stream Length, propertyType : INTEGER, defaultValue : []
id : cmis:contentStreamMimeType, displayName : MIME Type, propertyType : STRING, defaultValue : []
id : cmis:contentStreamFileName, displayName : Filename, propertyType : STRING, defaultValue : []
id : cmis:contentStreamId, displayName : Content Stream Id, propertyType : ID, defaultValue : []

Following is the complete working application that displays each type in the openCMIS and corresponding properties and their property definitions.


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.ObjectType;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.api.Tree;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
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";

 public 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 printType(Tree<ObjectType> types, String space) {

  ObjectType objType = types.getItem();

  Map<String, PropertyDefinition<?>> propertyDefinitions = objType.getPropertyDefinitions();

  System.out.println("Property Definitions for " + objType.getId());
  System.out.println("****************************************************");
  for (String key : propertyDefinitions.keySet()) {
   PropertyDefinition<?> definition = propertyDefinitions.get(key);

   System.out.println("id : " + definition.getId() + ", displayName : " + definition.getDisplayName()
     + ", propertyType : " + definition.getPropertyType() + ", defaultValue : "
     + definition.getDefaultValue());

  }

  List<Tree<ObjectType>> objTypes = types.getChildren();

  for (Tree<ObjectType> objTypeTemp : objTypes) {
   printType(objTypeTemp, space + " ");
  }
 }

 public static void main(String args[]) throws IOException {
  Session session = getSession();

  List<Tree<ObjectType>> types = session.getTypeDescendants(null, -1, true);

  for (Tree<ObjectType> typeTemp : types) {
   printType(typeTemp, "");
  }

 }
}



Previous                                                 Next                                                 Home

No comments:

Post a Comment