cancel
Showing results for 
Search instead for 
Did you mean: 

Setting an aspect property using CMIS

srowsell
Champ in-the-making
Champ in-the-making
So I'm working with Alfresco 4.1.7.3, and therefore CMIS 1.0, which means that I'm using the Alfresco CMIS Extension (as I have to work with aspects).  I've been figuring out what I can from online resources, and I bought the book by Jeff Potts and others, which is excellent.  But I'm trying to change a property of an aspect in this way:

if (alfDoc.hasAspect("P:ra:reportProperties"))
          {
             Map<String, Object> properties = new HashMap<String, Object>();
             properties.put("ra:department", "Accounting");
             alfDoc.updateProperties(properties);
          }


The last line of that IF block throws the following exception:

<blockquote>Exception in thread "main" java.lang.IllegalArgumentException: Property 'ra:department' is not valid for this type or one of the secondary types!
   at org.apache.chemistry.opencmis.client.runtime.repository.ObjectFactoryImpl.convertProperties(ObjectFactoryImpl.java:398)
   at org.apache.chemistry.opencmis.client.runtime.AbstractCmisObject.updateProperties(AbstractCmisObject.java:343)
   at org.alfresco.cmis.client.impl.AlfrescoDocumentImpl.updateProperties(AlfrescoDocumentImpl.java:66)
   at org.apache.chemistry.opencmis.client.runtime.AbstractCmisObject.updateProperties(AbstractCmisObject.java:307)
   at com.someco.cmis.examples.CmisExampleNew.showFolderContents(CmisExampleNew.java:128)
   at com.someco.cmis.examples.CmisExampleNew.main(CmisExampleNew.java:65)
</blockquote>

I can state with confidence that the model supports this property.  Here it is:

<?xml version="1.0" encoding="UTF-8"?>
<!– First namespace prefix in namespace array is used for model prefix –>
<model xmlns="http://www.alfresco.org/model/dictionary/1.0" name="ra:reportAspect">
   <description>Alfresco Form Builder Project</description>
   <author>admin</author>
   <version>1.0</version>
   <imports>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
   </imports>
   <namespaces>
      <namespace uri="ra.model" prefix="ra" />
   </namespaces>
   <aspects>
      <aspect name="ra:reportProperties">
         <title>reportProperties</title>
         <properties>
            <property name="ra:reportName">
               <title>Report Name</title>
               <type>d:text</type>
            </property>
            <property name="ra:department">
               <title>Department</title>
               <type>d:text</type>
            </property>
            <property name="ra:frequency">
               <title>Frequency</title>
               <type>d:text</type>
            </property>
            <property name="ra:suffix">
               <title>Suffix</title>
               <type>d:text</type>
            </property>
            <property name="ra:uniqueIdentifier">
               <title>Report Unique Identifier</title>
               <type>d:text</type>
            </property>
            <property name="ra:date">
               <title>Report Date</title>
               <type>d:date</type>
            </property>
            <property name="ra:notInWorkflow">
               <title>Not In Workflow</title>
               <type>d:boolean</type>
            </property>
         </properties>
      </aspect>
   </aspects>
</model>


I'm hoping that someone can point out what I'm doing wrong in that last line of the IF block, because it looks to me like it ought to work.

Thanks,

Steve
6 REPLIES 6

kaynezhang
World-Class Innovator
World-Class Innovator
Since you are using cmis1.0  secondaryTypes is no avialable ,you can use Aspect Extensions,add update aspect properties like folloing

   List<CmisExtensionElement> extensions = new ArrayList<CmisExtensionElement>();

        CmisExtensionElement valueElem = new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, "value", null, "Accounting");
        List<CmisExtensionElement> valueElems = new ArrayList<CmisExtensionElement>();
        valueElems.add(valueElem);

        List<CmisExtensionElement> children = new ArrayList<CmisExtensionElement>();
        Map<String, String> attributes = new HashMap<String, String>();
        attributes.put("propertyDefinitionId", "ra:department");
        children.add(new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, "propertyString", attributes, valueElems));

        List<CmisExtensionElement> propertyValuesExtension = new ArrayList<CmisExtensionElement>();
        propertyValuesExtension.add(new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, CMISConnector.PROPERTIES, null, children));

        CmisExtensionElement setAspectsExtension = new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, CMISConnector.SET_ASPECTS, null, propertyValuesExtension);
        extensions.add(setAspectsExtension);

I suggest you use a utils class  org.alfresco.cmis.client.impl.AlfrescoAspectsUtils,which is very convenient to   manipulate Aspect Extensions

srowsell
Champ in-the-making
Champ in-the-making
kaynezhang…

Thanks for your reply.  It's not clear to me where the CMISConnector class comes from.  It looks like it ought to be in org.alfresco.opencmis, but that import doesn't get me that class.

Steve

kaynezhang
World-Class Innovator
World-Class Innovator
CMISConnector class is used by alfresco server to adapt Alfresco and OpenCMIS。
I don't think you will need it in openCmis Client.

srowsell
Champ in-the-making
Champ in-the-making
I ask because it's there in your sample code, and if it's not an imported class it's not clear how it works.

Steve

kaynezhang
World-Class Innovator
World-Class Innovator
I'm sorry ,my mistake.We don't need CMISConnector class, we only need several constants that define in it,they are ALFRESCO_EXTENSION_NAMESPACE,SET_ASPECTS,PROPERTIES.I have already extract them.
I have modified and tested the code ,you can copy and modify according your requirement


      String ALFRESCO_EXTENSION_NAMESPACE = "http://www.alfresco.org";
      String SET_ASPECTS = "setAspects";
      String PROPERTIES = "properties";
      String VALUE = "value";
      String PROPERTY_DEFINITION_ID="propertyDefinitionId";
      String PROPERTY_STRING="propertyString";
      String servalUrl = "http://localhost:8080/alfresco/cmisatom";
      String userName = "admin";
      String password = "admin";

      Session session = getSession(servalUrl, userName, password);
      AlfrescoDocument alfDoc = (AlfrescoDocument) session
      .getObjectByPath("/TESTFOLDER1/20130822.doc");
      
      Properties properties = new PropertiesImpl();
        List<CmisExtensionElement> extensions = new ArrayList<CmisExtensionElement>();

        CmisExtensionElement valueElem = new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, VALUE, null, "Accounting"); //property value of custom property ra:department is accounting
        List<CmisExtensionElement> valueElems = new ArrayList<CmisExtensionElement>();
        valueElems.add(valueElem);

        List<CmisExtensionElement> children = new ArrayList<CmisExtensionElement>();
        Map<String, String> attributes = new HashMap<String, String>();
        attributes.put(PROPERTY_DEFINITION_ID, "ra:department");//property name is ra:department
        children.add(new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, PROPERTY_STRING, attributes, valueElems));

       
        List<CmisExtensionElement> propertyValuesExtension = new ArrayList<CmisExtensionElement>();
        propertyValuesExtension.add(new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, PROPERTIES, null, children));

       
        CmisExtensionElement setAspectsExtension = new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, SET_ASPECTS, null, propertyValuesExtension);
        extensions.add(setAspectsExtension);
        System.out.println(extensions);
        properties.setExtensions(extensions);
        String repId = session.getRepositoryInfo().getId();
        Holder<String> objectIdHolder = new Holder<String>(alfDoc.getId());
        session.getBinding().getObjectService().updateProperties(repId, objectIdHolder, null, properties, null);

srowsell
Champ in-the-making
Champ in-the-making
Thanks, that works nicely.

Steve