Monday, February 28, 2011

Updating Aspect Properties in Alfresco with CMIS

The current CMIS 1.0 specification does not address the dynamic metadata assignment like the concept of aspects used within Alfresco. In the Alfresco 3.4d Community release, an attempt to send a CMIS request to update metadata properties on fields which have been assigned via aspects fails.

For example, in developing the Formtek EDM module, we attempted to send a request to update the value for a property which was assigned to a document through the addition of an aspect.

An example of the CMIS request to update metadata and the associated ATOM document are as follows:

PUT /alfresco/s/cmis/s/workspace:SpacesStore/i/4073281a-5e9c-45cc-966a-4a2f32a933b8

<entry xmlns="http://www.w3.org/2005/Atom"
  xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/" 
  xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/" 
  xmlns:alf="http://www.alfresco.org">
    <title>2d_house_plan.dwg</title>
    <cmisra:object>
      <cmis:properties>
        <cmis:propertyString propertyDefinitionId="edm:program_project"
 queryName="edm:program_project"><cmis:value>2d_house_plan.dwg</cmis:value>
        </cmis:propertyString>
          </cmis:properties>
    </cmisra:object>
</entry>

Here the property edm:program_project is a property of a custom document type associated with the document via a mandatory aspect.

The request fails with the following error:

The WebScript has responded with a status of 400 - Bad Request.
400 Description: Request sent by the client was syntactically incorrect.
Message: Property edm:program_project is not a known property for type D:edm:engineeringDrawing


I was able to fix this by replacing lines 227-228 of the file /tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/cmis/lib/modify.lib.js


// is this a valid property?
var propDef = typeDef == null ? cmis.queryProperty(propName) : typeDef.propertyDefinitions[propName];

with this:

// is this a valid property?
var propDef;
if(typeDef != null)
{
    propDef = typeDef.propertyDefinitions[propName];
}
    if(propDef == null)
{
    propDef = cmis.queryProperty(propName);
}