Thursday 25 April 2019

CMIS: Change log support


By using CMIS 'change log' mechanism, application can discover the set of changes that have occurred to objects stored in the repository from a given point of time.

Change log is a collection change events. one change event corresponds to one cmis object.

Note
As per the specification, the change events in the change log MUST be returned in ascending order from the time when the change event occurred.

Is change log can give all the changes?
It depends on the repository. Repositories can have an entry for every change ever made to content in the repository, or may only be able to return an entry for all changes made since a particular point in time.

RepositoryInfo interface provides 'getChangesIncomplete' method, to check whether the entries in the change log are incomplete or complete.

Boolean getChangesIncomplete()
Rreturn true if the changes are incomplete, false if the changes are complete, or null if the repository didn't provide this flag

TestCmis.java
package com.sample.util;

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;

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 main(String args[]) {
  Session session = getSession();

  Boolean isChangesInComplete = session.getRepositoryInfo().getChangesIncomplete();
  
  if(isChangesInComplete){
   System.out.println("Changes in the changelog are incomplte");
   return;
  }
  
  System.out.println("Changes in the change log are complete");
 }

}

Output
Changes in the changelog are incomplete

Get the level of change log support by the repository
RepositoryCapabilities interface provides 'getChangesCapability' method to check the level of change log support by the repository. Following table summarizes the possible values.

Value
Description
none
The repository does not support the change log feature.
objectidsonly
The change log can return only the object ids for changed objects in the repository and an indication of the type of change, not details of the actual change.
properties
The change log can return properties and the object id for the changed objects.
all
The change log can return the object ids for changed objects in the repository and more information about the actual change.

Example
                  CapabilityChanges capabilityChanges = repoInfo.getCapabilities().getChangesCapability();

                  if(capabilityChanges == null){
                           System.out.println("Repository is not providing this value");
                  }else if(capabilityChanges == CapabilityChanges.NONE){
                           System.out.println("The repository does not support the change log feature");
                  }else if(capabilityChanges == CapabilityChanges.OBJECTIDSONLY){
                           System.out.println("The change log can return only the object ids for changed objects in the repository and an indication of the type of change, not details of the actual change.");
                  }else if(capabilityChanges == CapabilityChanges.PROPERTIES){
                           System.out.println("The change log can return properties and the object id for the changed objects.");
                  }else if(capabilityChanges == CapabilityChanges.ALL){
                           System.out.println("The change log can return the object ids for changed objects in the repository and more information about the actual change.");
                  }


TestCmis.java
package com.sample.util;

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.data.RepositoryInfo;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.enums.CapabilityChanges;

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 main(String args[]) {
  Session session = getSession();

  RepositoryInfo repoInfo = session.getRepositoryInfo();

  CapabilityChanges capabilityChanges = repoInfo.getCapabilities().getChangesCapability();

  if(capabilityChanges == null){
   System.out.println("Repository is not providing this value");
  }else if(capabilityChanges == CapabilityChanges.NONE){
   System.out.println("The repository does not support the change log feature");
  }else if(capabilityChanges == CapabilityChanges.OBJECTIDSONLY){
   System.out.println("The change log can return only the object ids for changed objects in the repository and an indication of the type of change, not details of the actual change.");
  }else if(capabilityChanges == CapabilityChanges.PROPERTIES){
   System.out.println("The change log can return properties and the object id for the changed objects.");
  }else if(capabilityChanges == CapabilityChanges.ALL){
   System.out.println("The change log can return the object ids for changed objects in the repository and more information about the actual change.");
  }
 }

}

Output
The change log can return only the object ids for changed objects in the repository and an indication of the type of change, not details of the actual change.

Change log token
Change log token is an opaque string that uniquely identifies a particular change in the change log.

How to get latest Change log token?
RepositoryInfo interface provides 'getLatestChangeLogToken' method to get the latest change log token.

String latestChangeLogToken = session.getRepositoryInfo().getLatestChangeLogToken();


Previous                                                 Next                                                 Home

No comments:

Post a Comment