In this post I am going to explain how to create a folder
inside a repository step by step.
Step 1: Get the
parent folder reference, where you want to create new folder. Suppose if you
want to create a folder inside root folder, get the root folder reference.
Folder rootFolder = session.getRootFolder();
Step 2: Create a
map, and populate the properties like folder name and type of the cmis object.
Map<String, String> properties = new
HashMap<>();
properties.put("cmis:objectTypeId",
"cmis:folder");
properties.put("cmis:name", "My
Folder");
Step 3: Call the
createFolder method to create folder.
Folder folder = rootFolder.createFolder(properties);
Following is the complete working application.
TestCmis.java
package com.sample.util; import java.util.HashMap; import java.util.Map; 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"; 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(); Folder rootFolder = session.getRootFolder(); Map<String, String> properties = new HashMap<>(); properties.put("cmis:objectTypeId", "cmis:folder"); properties.put("cmis:name", "My Folder"); Folder folder = rootFolder.createFolder(properties); System.out.println("Name Of the Folder " + folder.getName()); System.out.println("Path Of the Folder " + folder.getPaths().get(0)); } }
Output
Name Of the Folder My Folder
Path Of the Folder /My Folder
No comments:
Post a Comment