The following groovy demonstrates the problem I'm having:
import org.apache.chemistry.opencmis.commons.* import org.apache.chemistry.opencmis.commons.data.* import org.apache.chemistry.opencmis.commons.enums.* import org.apache.chemistry.opencmis.client.api.* def cmis = new scripts.CMIS(session) Folder folder = cmis.getFolder("/Shared") final String textFileName = "test.txt" Document doc try{ doc = (Document) session.getObjectByPath(folder.getPath()+"/"+textFileName) }catch(Err){} if (doc != null){ doc.delete(true) } String mimetype = "text/plain; charset=UTF-8" String content = "This is some test content" String filename = textFileName byte[] buf = content.getBytes("UTF-8") ByteArrayInputStream input = new ByteArrayInputStream(buf) ContentStream contentStream = session.getObjectFactory().createContentStream(filename, buf.length, mimetype, input) Map<String, Object> props = new HashMap<String, Object>() props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document") props.put(PropertyIds.NAME, filename) doc = folder.createDocument(props, contentStream, VersioningState.MAJOR) List<String> aspects = doc.getPropertyValue("cmis:secondaryObjectTypeIds") println(aspects) List<String> toAdd props.clear() if (!aspects.contains("R:ncsrel:related")) { toAdd = ["P:ncsrel:related"] doc = doc.updateProperties(props, toAdd, null) } aspects = doc.getPropertyValue("cmis:secondaryObjectTypeIds") println(aspects) //problem, adding this aspect removes the R:ncsrel:related if (!aspects.contains("P:cm:dublincore")) { toAdd = ["P:cm:dublincore"] doc = doc.updateProperties(props, toAdd, null) } aspects = doc.getPropertyValue("cmis:secondaryObjectTypeIds") println(aspects)
The output is:
[P:cm:titled, P:sys:localized, P:cm:author]
[P:cm:titled, R:ncsrel:related, P:sys:localized, P:cm:author]
[P:cm:titled, P:cm:dublincore, P:sys:localized, P:cm:author]
Adding P:cm:dublincore deleted R:ncsrel:related.
The R:ncsrel:related aspect definition:
<aspects> <aspect name="ncsrel:related"> <title>NCS Related</title> <associations> <association name="ncsrel:related"> <title>Related Content</title> <source> <mandatory>false</mandatory> <many>true</many> </source> <target> <class>cm:content</class> <mandatory>false</mandatory> <many>true</many> </target> </association> </associations> </aspect> </aspects> c cts>
Has anyone any thoughts?
In fact the "aspectsToAdd" is a detail of the CMIS client library and is not transmitted to Alfresco that way. The CMIS specification only provides an updateProperties operation where ALL secondaryTypes / aspects need to be included that should still be applied after the operation (current + new). In case the client library does not correctly merge the existing and aspects to add, Alfresco may remove those aspects that are not in the cmis:secondaryObjectTypeIds list. This is implemented in the CMISConnector.processSecondaryTypes operation.
I would check the HTTP request the client library sends to Alfresco if it contains all the aspects that were applied before PLUS the aspects you want to add.