08-22-2016 05:53 AM
08-23-2016 05:48 AM
08-24-2016 06:55 AM
08-25-2016 11:30 AM
09-21-2016 11:57 AM
You can use getChildByName function
09-21-2016 02:14 PM
Here's a runnable class that leverages OpenCMIS to check for the presence of a folder with a given name.
package com.someco.cmis.examples;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.chemistry.opencmis.client.api.ItemIterable;
import org.apache.chemistry.opencmis.client.api.QueryResult;
import org.apache.chemistry.opencmis.client.api.Repository;
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 FolderChecker {
private String serviceUrl = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser";
private Session session = null;
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("USAGE: java FolderChecker [folder name]");
System.exit(-1);
}
FolderChecker fc = new FolderChecker();
System.out.println("Does folder: " + args[0] + " exist? " + fc.doesFolderExist(args[0]));
}
public boolean doesFolderExist(String folderName) {
String queryString = "select cmis:objectId from cmis:folder where cmis:name = '" + folderName + "'";
ItemIterable<QueryResult> results = getSession().query(queryString, false);
if (results.getTotalNumItems() > 0) {
return true;
} else {
return false;
}
}
public Session getSession() {
if (session == null) {
// default factory implementation
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> parameter = new HashMap<String, String>();
// user credentials
parameter.put(SessionParameter.USER, "admin"); // <-- Replace
parameter.put(SessionParameter.PASSWORD, "admin"); // <-- Replace
// connection settings
parameter.put(SessionParameter.BROWSER_URL, this.serviceUrl); // Uncomment for Atom Pub binding
parameter.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value()); // Uncomment for Atom Pub binding
List<Repository> repositories = factory.getRepositories(parameter);
this.session = repositories.get(0).createSession();
}
return this.session;
}
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.