Thursday 25 April 2019

CMIS: Get repository information extensions


Below statements are used to get the extensions at repository level.

RepositoryInfo repoInfo = session.getRepositoryInfo();
List<CmisExtensionElement> extensions = repoInfo.getExtensions();

Find the below working application.

Test.java
package cmis_client.cmis_client;

import java.util.HashMap;
import java.util.List;
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.CmisExtensionElement;
import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
import org.apache.chemistry.opencmis.commons.enums.BindingType;

public class Test {

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

 private static void printExtensions(List<CmisExtensionElement> extensions, String space) {

  for (CmisExtensionElement extension : extensions) {
   List<CmisExtensionElement> extensionChildren = extension.getChildren();

   if (extensionChildren == null || extensionChildren.isEmpty()) {
    String name = extension.getName();
    String value = extension.getValue();
    System.out.println(name + " : " + value);

   } else {
    printExtensions(extensionChildren, space + " ");
   }
  }
 }

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

  RepositoryInfo repoInfo = session.getRepositoryInfo();

  List<CmisExtensionElement> extensions = repoInfo.getExtensions();

  if (extensions == null) {
   System.out.println("Repository do not have extensions");
   return;
  }
  printExtensions(extensions, " ");
 }
}



Previous                                                 Next                                                 Home

No comments:

Post a Comment