cancel
Showing results for 
Search instead for 
Did you mean: 

How to getProperties of a Document with OpenCmis

moveax0
Champ in-the-making
Champ in-the-making
Hi

I have some problem to get all the properties of a Document with OpenCmis and Atom Binding

This is our environment

Alfresco Version: Community - 5.1.0

Pom:

<dependency>
   <groupId>org.apache.chemistry.opencmis</groupId>
   <artifactId>chemistry-opencmis-client-api</artifactId>
   <version>0.13.0</version>
</dependency>

<dependency>
   <groupId>org.apache.chemistry.opencmis</groupId>
   <artifactId>chemistry-opencmis-client-impl</artifactId>
   <version>0.13.0</version>
</dependency>

And this is the code:

Map<String, String> properties = new HashMap<String, String>();
properties.put(SessionParameter.USER, user);
properties.put(SessionParameter.PASSWORD, password);
properties.put(SessionParameter.ATOMPUB_URL, "http://{host}:{port}/alfresco/api/-default-/public/cmis/versions/1.1/atom");
properties.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
SessionFactory factory = SessionFactoryImpl.newInstance();
session = factory.getRepositories(properties).get(0).createSession();

String="ObjectId";
ObjectId id = session.createObjectId(idObject);
CmisObject object = session.getObject(id);
Document document = (Document) object;
List<Property<?>> properties = document.getProperties();

If I run the code I obtain this error:
java.lang.ClassCastException: org.apache.chemistry.opencmis.client.runtime.FolderImpl cannot be cast to org.apache.chemistry.opencmis.client.api.Document

After some Google search I have try to add this parameter to the SessionFactory and add alfresco-opencmis-extension dependency to pom:
properties.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

<dependency>
   <groupId>org.alfresco.cmis.client</groupId>
   <artifactId>alfresco-opencmis-extension</artifactId>
   <version>0.3</version>
</dependency>

The exception is changed and It becomes:
java.lang.NoClassDefFoundError: org/apache/chemistry/opencmis/client/api/TransientCmisObject

Do you have any idea Where is the problem?

Is there an how to that explains how to retrieve the Document properties?

Thank in advance
2 REPLIES 2

sepgs2004
Star Contributor
Star Contributor
I am using 5.0.d, so do not know if this helps…
I see a slight difference in my code. It works.
I remember getting the same error. Now I could not say how it is gone. Sorry.

It looks like the combination of these - 1. the URL, 2. the opencmis libraries (versions) and 3. the SessionParameters used on the SessionFactory - matters a lot. They are very sensitive.

Here is the code (that works for me)

Map properties = new HashMap();
properties.put(SessionParameter.USER, user);
properties.put(SessionParameter.PASSWORD, password);
properties.put(SessionParameter.ATOMPUB_URL, "http://{host}:{port}/alfresco/api/-default-/public/cmis/versions/1.1/atom");
properties.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
SessionFactory factory = SessionFactoryImpl.newInstance();
List<Repository> repositories = factory.getRepositories(properties);
Respository cmisRepository = repositories.get(0);

properties.put(SessionParameter.REPOSITORY_ID, cmisRepository.getId());
cmisSession = factory.createSession(properties);
….



I use opencmis libraries
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-client-api</artifactId>
<version>0.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-client-impl</artifactId>
<version>0.13.0</version>
</dependency>

Please post the answer when you figure out the exact issue or any more details…
Gnanasekaran Sakthivel

moveax0
Champ in-the-making
Champ in-the-making
Thank you for the response.

I have solved. It was a Pom configuration problem. Alfresco 5.0d works well with the library that we have used