Wednesday 24 April 2019

CMIS: getTypeDescendants: Get the type descendants of a type


Session interface provides 'getTypeDescendants' method to get all the descendants of given type.

List<Tree<ObjectType>> getTypeDescendants(String typeId, int depth, boolean includePropertyDefinitions)
Following table summarizes the arguments of the method 'getTypeDescendants'.

Argument
Description
typeId
If the typeId is null, then the Repository return all types and ignore the value of the depth parameter, else it returns all of descendant types of the specified type.
depth
number of levels of depth in the type hierarchy from which to return results.

If depth is 1, it returns only types that are children of the type.

Id depth is n (a positive integer), it returns descendant types at all 'n' levels in the CMIS hierarchy.

If depth is -1, it returns ALL descendant types at all depth levels in the CMIS hierarchy.
includePropertyDefinitions
If it is true, then the property definitions are included in the result, else not.

Following application prints all the base types and their descendants.

TestCmis.java
package com.sample.util;

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 printTypes(List<Tree<ObjectType>> objectTypes, String space) {

  for (Tree<ObjectType> objType : objectTypes) {
   ObjectType objectType = objType.getItem();
   System.out.println(space + objectType.getDisplayName());

   printTypes(objType.getChildren(), "  " + space);
  }
 }

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

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

  printTypes(objectTypes, "");

 }

}


Output

Secondary
  MySecondaryType
Item
  MyItemType
Relationship
  CrossReferenceType
Policy
  Audit Policy
Folder
Document
  My Type 1 Level 1
    My Type 3 Level 2
      My Type 4 Level 3
      My Type 5 Level 3
    My Type 6 Level 2
  My Type 2 Level 1
    My Type 7 Level 2
    My Type 8 Level 2
    My Type 9 Level 2
    My Type 10 Level 2
    My Type 11 Level 2
    My Type 12 Level 2
    My Type 13 Level 2
    My Type 14 Level 2
    My Type 15 Level 2
  Complex type with properties, Level 1
  Document type with properties, Level 1
    Document type with inherited properties, Level 2
      Document type with inherited properties, Level 3
  Versioned Type
  BigContentFakeType
  Audio File
  Email Document
  EXIF Image
  Office Document
    PDF Document
  Video File



Previous                                                 Next                                                 Home

No comments:

Post a Comment