cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCMIS - adding aspects with properties

bazter
Champ in-the-making
Champ in-the-making
This post is for all the people who are having problems with setting aspect-based properties via OpenCMIS. I post this just because I had really annoying experience while trying to create new file with custom aspects and properties and it might help some people out there. I spent hours and hours trying to figure out why my aspect-based properties appear to be null even tho I don't get anny error in console.

At first, you need Alfresco OpenCMIS extension and add the jar to the classpath.

Second step is to add the object factory class as follows:

<blockcode>SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map parameters = new HashMap();

parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

Repository repository = (Repository)sessionFactory.getRepositories(parameters).get(0);
Session session = repository.createSession();
</blockcode>

With this you are now able to work with aspects (adding them, setting aspect-based properties as usual properties etc.)

<blockcode>Map properties = new HashMap();
      properties.put("cmis:name", name);
      properties.put("cmisSmiley SurprisedbjectTypeId", "D:custom:customType, P:custom:customAspect");
      properties.put("custom:customProperty", "custom property value");
      createDocument(properties, null, null);</blockcode>

Pretty straightforward sofar. Except the fact it didn't work for me and even tho all seemd to be ok, the aspects didn't really appear where they should and when I tried to get the property value, i got null value. Weird. After few hours of desparate attempts I started trying different atompub urls while connecting to the repository and I found out that the only one url actually working is this one:

<blockcode> parameters.put("org.apache.chemistry.opencmis.binding.atompub.url", "http://hostname:8080/alfresco/api/-default-/cmis/versions/1.1/browser");
</blockcode>

and that's pretty much it, any other atompub url didn't work for me. Hope it helps.

Cheers


edit: Bam, tried it for the second time and i got this while connecting to repository:
Unexpected document! Received: something unknown


well.. I'm done here, any help would be much appreciated

edit 2: I tried these parameters
<blockcode>parameters.put("org.apache.chemistry.opencmis.binding.spi.type", BindingType.BROWSER.value());
parameters.put("org.apache.chemistry.opencmis.binding.browser.url", "http://hostname:8080/alfresco/api/-default-/cmis/versions/1.1/browser");</blockcode>

It does connect, I get same results as before tho (aspects are not added or their values are null). It's funny how it worked only once 😕

edit 3: ok, the old url actually works fine, lol

<blockcode>
parameters.put("org.apache.chemistry.opencmis.binding.atompub.url", "http://hostname:8080/alfresco/cmisatom");
</blockcode>

I still don't get why the new urls posted in this section in pinned topic don't work!
3 REPLIES 3

kaynezhang
World-Class Innovator
World-Class Innovator
Since you are using atom bingding ,you should provide atom url instead of browser url


parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
parameters.put("org.apache.chemistry.opencmis.binding.atompub.url", "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom");

Map properties = new HashMap();
      properties.put("cmis:name", name);
      properties.put("cmis:objectTypeId", "D:custom:customType, P:custom:customAspect");
      properties.put("custom:customProperty", "custom property value");

rahulalfresco
Champ in-the-making
Champ in-the-making
I also spend many hrs to implement this. At last landed on your post.. it helped me.. Thanks Smiley Happy
Why we need to use old url, did you find any information?

pco
Champ in-the-making
Champ in-the-making
Great summary that will be of much help for many. May I add, for CMIS 1.1 (Alf 5.0.a), Groovy:


            def properties = new HashMap<String,String>()
            properties[PropertyIds.NAME] = 'Test.pdf'
            properties[PropertyIds.OBJECT_TYPE_ID] = 'cmis:document'
            properties[PropertyIds.SECONDARY_OBJECT_TYPE_IDS] = ['P:cm:titled']
            properties['cm:title'] = 'My CMIS 1.1 test with aspects'


The example creates the properties for a document with the "Titled" aspect. So, while in CMIS 1.0 you would have created a comma separated string, with the alfresco-cmis extensions, with CMIS 1.1 you would just set an array of secondary object ids (aspects). So with CMIS 1.1 you do not need the extensions any more, but the API contains everything necessary.