AnsweredAssumed Answered

OpenCMIS - adding aspects with properties

Question asked by bazter on Mar 16, 2014
Latest reply on Sep 29, 2014 by pco
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("cmis:objectTypeId", "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!

Outcomes