AnsweredAssumed Answered

Set properties in aspect using OpenCMIS

Question asked by amincheva on Jan 30, 2017

Hello, Guys! 

I'm new to Alfresco and I'm trying to set aspect properties using OpenCmis Java libraries through Bonita BPM. My code right now looks like this:

 

Map<String, String> sessionParameters = new HashMap<String, String>();
sessionParameters.put(SessionParameter.USER, "admin");
sessionParameters.put(SessionParameter.PASSWORD, "password");
sessionParameters.put(SessionParameter.ATOMPUB_URL, "http://citstnlab02:9080/alfresco/api/-default-/public/cmis/versions/1.1/atom");
sessionParameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Session lSession = sessionFactory.getRepositories(sessionParameters).get(0).createSession();
Folder root = lSession.getRootFolder();

Map<String, Object> folderProperties = new HashMap<String, Object>();
folderProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
folderProperties.put(PropertyIds.NAME, "NewFolder2");
Folder newFolder = root.createFolder(folderProperties);

Map<String, Object> lProperties = new HashMap<String, Object>();
String name = "testdocument2.txt";

lProperties.put(PropertyIds.DESCRIPTION,"Testing file");
lProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
lProperties.put(PropertyIds.NAME, name);


byte[] content = "CMIS Testdata One".getBytes();
InputStream stream = new ByteArrayInputStream(content);
ContentStream contentStream = new ContentStreamImpl(name, new BigInteger(content), "text/plain", stream);
Document newContent1 = newFolder.createDocument(lProperties, contentStream, null);

List<Object> aspects = newContent1.getProperty("cmis:secondaryObjectTypeIds").getValues();
aspects.add("P:cn:webable");
HashMap<String, Object> props = new HashMap<String, Object>();
props.put("cmis:secondaryObjectTypeIds", aspects);
newContent1.updateProperties(props);

 

It creates a folder and a .txt file in it. it also set the aspect, but I can not fill out the properties in this aspect. 

PS: I created my custom aspect through the Alfresco Share UI.

I will really appreciate your help!

Thanks,

Albena Mincheva!

Outcomes