AnsweredAssumed Answered

creating a document log per document using CMIS

Question asked by wemu on Apr 12, 2013
Latest reply on Apr 16, 2013 by sujaypillai

I'm new to CMIS so please be a little patient with me :)

We use Alfresco 4.x to store our documents and Apache Chemistry to communicate with Alfresco.

We added a new document type into alfresco to store tif images along with some meta data. I now want to add some log-statements to these documents. Here is the model:

<?xml version="1.0" encoding="UTF-8"?>
<!– Definition of new Model –>
<model name="zpe:zpeModel" xmlns="">
   <!– Optional meta-data about the model –>
   <description>ZPE Model</description>
      <import uri="" prefix="d"/>
      <import uri="" prefix="cm"/>
      <import uri="" prefix="sys" />
      <namespace uri="" prefix="zpe"/>

      <type name="zpe:zpeDocument">
         <title>ZPE document</title>
            <property name="zpe:centId">
            <property name="zpe:documentType">
            <property name="zpe:documentStatus">
            Quite a few more
            <child-association name="zpe:documentLogs">

      <type name="zpe:documentLog">
         <title>Document log</title>
            <property name="zpe:logText">
               <index enabled="false" />
            <property name="zpe:logUsername">
               <index enabled="false" />
            <property name="zpe:logDate">
               <index enabled="false" />

I want to use CMIS to add several "zpe:documentLogs" to a "zpe:zpeDocument" (the tif image)

Currently the zpe:zpeDocument are in Alfresco but I struggle to get used to the CMIS API:

private String createCmisNode(final String folderIdString) {
   ObjectId folderId = new ObjectId() {
      public String getId() {
         return folderIdString;
   Map<String, Object> properties = new HashMap<>();
   properties.put(PropertyIds.OBJECT_TYPE_ID, ZpeAlfType.ZPE_DOCUMENT_LOG.getTypeName());
   properties.put(PropertyIds.NAME, "zpeDocumentLogName");

   ContentStream contentStream = null;

   ObjectId objectNode = session.createDocument(properties, folderId, contentStream, VersioningState.NONE);
   return  objectNode.getId();

public void createZpeDocumentLog(final String cmisObjectId, Map<String, Object> properties, String documentType) throws IOException {

   // cmisObjectId = "workspace://SpacesStore/addb1495-90a4-4842-8bf0-b3b27de56410"

   OperationContext operationContext = session.createOperationContext();


    CmisObject cmisObject = session.getObject(cmisObjectId);
   AlfrescoDocument tiffAlfDoc = (AlfrescoDocument) cmisObject;
   List<Folder> parents = tiffAlfDoc.getParents(operationContext); // TODO: takes several seconds!
   if (CollectionUtils.isEmpty(parents)) {
      throw new IOException("The given cmoObjectId has no parent folder");
   Folder tiffFileParentFolder = parents.get(0);
   String propertyValue = tiffFileParentFolder.getPropertyValue(PropertyIds.OBJECT_ID);

   // create cmisObject of type "Node" to be able to add the documentLog there
   // later create a relation / association between the tif cmisObject and this node cmisObject
   final String cmisLogNodeObjectId = createCmisNode(propertyValue);
   // create relation:
   Document doc = (Document)session.getObject(new ObjectId() {
      public String getId() {
         return cmisObjectId; // tiff image

   //Retrieve or create the log/logs

   CmisObject log = session.getObject(new ObjectId() {
      public String getId() {
         return cmisLogNodeObjectId; // log document

   AlfrescoDocument alfDoc = (AlfrescoDocument) doc;
   Map<String, String> relProps = new HashMap<String, String>();
   relProps.put("cmis:sourceId", doc.getId());
   relProps.put("cmis:targetId", log.getId());
   relProps.put("cmis:objectTypeId", "zpe:documentLogs");
   session.createRelationship(relProps, null, null, null);


There are some issues with this:
it throws an exception: org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException: Invalid typeId zpe:documentLogs

AlfrescoDocument.getParents is very slow. Several seconds. Is there an easy / quick way to use the cmisObjectId of a document to retrieve its parent folder?

It now creates a document in alfresco using name "zpeDocumentLogName". This fails for the second documentLog (the name is already used).
But I want to have it added as Metadata to the tif-document and not as some "file" beside it.

Is there a way to add the documentLog entries into the metadata of the tif image? Or do I need to create a document?
And what is a smart way to create unique names then? (application is clustered so I dont want to use timestamps)

Or is the model not ok and instead of types we should use something else?

thanks a lot!