08-07-2013 02:39 AM
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.cmis.client.AlfrescoFolder;
import org.apache.chemistry.opencmis.client.api.Folder;
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.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
public class Test
{
private Session getSession(String serverUrl, String username, String password)
{
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map<String, String> params = new HashMap<String, String>();
params.put(SessionParameter.USER, username);
params.put(SessionParameter.PASSWORD, password);
params.put(SessionParameter.ATOMPUB_URL, serverUrl);
params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
params.put (SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
List<Repository> repos = sessionFactory.getRepositories(params);
if (repos.isEmpty()) {
throw new RuntimeException("Server has no repositories!");
}
return repos.get(0).createSession();
}
public void createFolder()
{
String servalUrl="http://localhost:8080/alfresco/cmisatom";
String userName="admin";
String password="admin";
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder,P:cm:titled");
properties.put(PropertyIds.NAME,"TESTFOLDER2");
properties.put(PropertyIds.CREATED_BY, "admin");
properties.put("cm:title", "Title");
properties.put("cm:description", "Desc");
Session session=getSession(servalUrl, userName, password);
AlfrescoFolder root=(AlfrescoFolder) session.getRootFolder();
System.out.println("The Name:"+root.getId()+root.getName());
AlfrescoFolder newFolder=(AlfrescoFolder) root.createFolder(properties);
System.out.println(newFolder.getName());
}
08-07-2013 03:21 AM
package org.alfresco.sample.webservice;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.cmis.client.AlfrescoFolder;
import org.apache.chemistry.opencmis.client.api.Folder;
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.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
public class Test
{
private Session getSession(String serverUrl, String username,
String password)
{
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map<String, String> params = new HashMap<String, String>();
params.put(SessionParameter.USER, username);
params.put(SessionParameter.PASSWORD, password);
params.put(SessionParameter.ATOMPUB_URL, serverUrl);
params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
params.put(SessionParameter.OBJECT_FACTORY_CLASS,
"org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
List<Repository> repos = sessionFactory.getRepositories(params);
if (repos.isEmpty()) {
throw new RuntimeException("Server has no repositories!");
}
return repos.get(0).createSession();
}
public void createFolder()
{
String servalUrl = "http://localhost:8080/alfresco/cmisatom";
String userName = "admin";
String password = "admin";
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder,P:cm:titled");
properties.put(PropertyIds.NAME, "TESTFOLDER2");
properties.put(PropertyIds.CREATED_BY, "admin");
properties.put("cm:title", "Title");
properties.put("cm:description", "Desc");
Session session = getSession(servalUrl, userName, password);
AlfrescoFolder root = (AlfrescoFolder) session.getRootFolder();
System.out.println("The Name:" + root.getId() + root.getName());
AlfrescoFolder newFolder = (AlfrescoFolder) root
.createFolder(properties);
System.out.println(newFolder.getName());
System.out.println(newFolder.getId());
}
public static void main(String[] args){
Test t = new Test();
t.createFolder();
}
}
08-12-2013 12:41 AM
08-12-2013 04:11 AM
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.