Document (or) folder can be identified by absolute path.
Below are the rules in constructing paths.
a.
Root folder has the path ‘/’.
b.
All the paths must start with root folder
‘/’.
c.
If folder A is under the root, and folder B
is under A, then the path would be /A/B.
How to get an object
by path
Session interface provides 'getObjectByPath' method to
get the cmis object by using path.
Session session = getSession();
CmisObject cmisObject =
session.getObjectByPath("/My_Folder-0-0");
Below is the complete working application.
TestCmis.java
package com.sample.util; import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.apache.chemistry.opencmis.client.api.CmisObject; 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"; private 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[]) throws IOException { Session session = getSession(); CmisObject cmisObject = session.getObjectByPath("/My_Folder-0-0"); System.out.println("Name : " + cmisObject.getName()); System.out.println("Type : " + cmisObject.getType()); } }
Output
Name : My_Folder-0-0 Type : Type Definition [base id=CMIS_FOLDER, id=cmis:folder, display Name=Folder, description=Folder, local name=cmis:folder, local namespace=http://apache.org, query name=cmis:folder, parent id=null, is controllable ACL=true, is controllable policy=true, is creatable=true, is fileable=true, is fulltext indexed=false, is included in supertype query=true, is queryable=true, property definitions={cmis:name=Property Definition [id=cmis:name, display name=Name, description=Name, local name=cmis:name, local namespace=null, query name=cmis:name, property type=STRING, cardinality=SINGLE, choice list=null, default value=null, is inherited=false, is open choice=null, is queryable=true, is required=true, updatability=READWRITE][extensions=null], cmis:description=Property Definition [id=cmis:description, display name=Description, description=Description, local name=cmis:description, local namespace=null, query name=cmis:description, property type=STRING, cardinality=SINGLE, choice list=null, default value=null, is inherited=false, is open choice=null, is queryable=false, is required=false, updatability=READWRITE][extensions=null], cmis:objectId=Property Definition [id=cmis:objectId, display name=Object Id, description=Object Id, local name=cmis:objectId, local namespace=null, query name=cmis:objectId, property type=ID, cardinality=SINGLE, choice list=null, default value=null, is inherited=false, is open choice=null, is queryable=true, is required=false, updatability=READONLY][extensions=null], cmis:baseTypeId=Property Definition [id=cmis:baseTypeId, display name=Base Type Id, description=Base Type Id, local name=cmis:baseTypeId, local namespace=null, query name=cmis:baseTypeId, property type=ID, cardinality=SINGLE, choice list=null, default value=null, is inherited=false, is open choice=null, is queryable=true, is required=false, updatability=READONLY][extensions=null], cmis:objectTypeId=Property Definition [id=cmis:objectTypeId, display name=Object Type Id, description=Object Type Id, local name=cmis:objectTypeId, local namespace=null, query name=cmis:objectTypeId, property type=ID, cardinality=SINGLE, choice list=null, default value=null, is inherited=false, is open choice=null, is queryable=true, is required=true, updatability=ONCREATE][extensions=null], cmis:secondaryObjectTypeIds=Property Definition [id=cmis:secondaryObjectTypeIds, display name=Secondary Type Ids, description=Secondary Type Ids, local name=cmis:secondaryObjectTypeIds, local namespace=null, query name=cmis:secondaryObjectTypeIds, property type=ID, cardinality=MULTI, choice list=null, default value=[], is inherited=false, is open choice=null, is queryable=true, is required=false, updatability=READWRITE][extensions=null], cmis:createdBy=Property Definition [id=cmis:createdBy, display name=Created By, description=Created By, local name=cmis:createdBy, local namespace=null, query name=cmis:createdBy, property type=STRING, cardinality=SINGLE, choice list=null, default value=null, is inherited=false, is open choice=null, is queryable=true, is required=false, updatability=READONLY][extensions=null], cmis:creationDate=Property Definition [id=cmis:creationDate, display name=Creation Date, description=Creation Date, local name=cmis:creationDate, local namespace=null, query name=cmis:creationDate, property type=DATETIME, cardinality=SINGLE, choice list=null, default value=null, is inherited=false, is open choice=null, is queryable=true, is required=false, updatability=READONLY][extensions=null], cmis:lastModifiedBy=Property Definition [id=cmis:lastModifiedBy, display name=Last Modified By, description=Last Modified By, local name=cmis:lastModifiedBy, local namespace=null, query name=cmis:lastModifiedBy, property type=STRING, cardinality=SINGLE, choice list=null, default value=null, is inherited=false, is open choice=null, is queryable=true, is required=false, updatability=READONLY][extensions=null], cmis:lastModificationDate=Property Definition [id=cmis:lastModificationDate, display name=Last Modification Date, description=Last Modification Date, local name=cmis:lastModificationDate, local namespace=null, query name=cmis:lastModificationDate, property type=DATETIME, cardinality=SINGLE, choice list=null, default value=null, is inherited=false, is open choice=null, is queryable=true, is required=false, updatability=READONLY][extensions=null], cmis:changeToken=Property Definition [id=cmis:changeToken, display name=Change Token, description=Change Token, local name=cmis:changeToken, local namespace=null, query name=cmis:changeToken, property type=STRING, cardinality=SINGLE, choice list=null, default value=null, is inherited=false, is open choice=null, is queryable=false, is required=false, updatability=READONLY][extensions=null], cmis:parentId=Property Definition [id=cmis:parentId, display name=Parent Id, description=Parent Id, local name=cmis:parentId, local namespace=null, query name=cmis:parentId, property type=ID, cardinality=SINGLE, choice list=null, default value=null, is inherited=false, is open choice=null, is queryable=false, is required=false, updatability=READONLY][extensions=null], cmis:path=Property Definition [id=cmis:path, display name=Path, description=Path, local name=cmis:path, local namespace=null, query name=cmis:path, property type=STRING, cardinality=SINGLE, choice list=null, default value=null, is inherited=false, is open choice=null, is queryable=false, is required=false, updatability=READONLY][extensions=null], cmis:allowedChildObjectTypeIds=Property Definition [id=cmis:allowedChildObjectTypeIds, display name=Allowed Child Object Type Ids, description=Allowed Child Object Type Ids, local name=cmis:allowedChildObjectTypeIds, local namespace=null, query name=cmis:allowedChildObjectTypeIds, property type=ID, cardinality=MULTI, choice list=null, default value=[], is inherited=false, is open choice=null, is queryable=false, is required=false, updatability=READONLY][extensions=null]}, typeMutability=TypeMutability [canCreate=true, canUpdate=false, canDelete=false][extensions=null]][extensions=null]
Every fileable object
provides ‘getParents’ method to get all the parents associated with it.
Document document =
(Document)session.getObjectByPath("/My_Folder-0-0/My_Folder-1-0/Hello.txt");
List<Folder> folders = document.getParents();
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.Document; import org.apache.chemistry.opencmis.client.api.Folder; 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"; private 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[]) throws IOException { Session session = getSession(); Document document = (Document)session.getObjectByPath("/My_Folder-0-0/My_Folder-1-0/Hello.txt"); List<Folder> folders = document.getParents(); for(Folder folder : folders){ System.out.println(folder.getPath()); } } }
No comments:
Post a Comment