cancel
Showing results for 
Search instead for 
Did you mean: 

Document property update CMIS

sumantapakira
Champ in-the-making
Champ in-the-making
Hi All,

I'm trying to update property of a document in Alfresco repository using CMIS. For that I've written below code but I'm getting error Property 'cm:description' is not valid for this type!
Folder newFolder = root.createFolder(folderProperties);
String name = "testdata5.text";
Map<String, Object> contentProperties = new HashMap<String, Object>();
contentProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
contentProperties.put(PropertyIds.NAME, name);
contentProperties.put("cm:description", "Test");
byte[] content = "This is a test".getBytes();
InputStream stream = new ByteArrayInputStream(content);
ContentStream contentStream = new ContentStreamImpl(name, new BigInteger(content), "text/plain", stream);
Document document = newFolder.createDocument(contentProperties, contentStream, null);

But when I'm executing a POST by using culr then it is correctly setting Description
curl -X POST -uadmin:admin "http://localhost:8080/alfresco/s/cmis/p/testfolder5/children" -H "Content-Type: application/atom+xml" -d @C:\Books\CMIS\test.atom.xml, then it is setting description correctly. test.atom.xml looks below -
<?xml version="1.0" encoding="utf-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:cmisra="http://docs.oasisopen.org/ns/cmis/restatom/200908/"
xmlns:cmis="http://docs.oasisopen.org/ns/cmis/core/200908/"><title>sample.doc</title><summary>A sample Doc</summary>
<content type="application/text"></content><cmisraSmiley Surprisedbject><cmisSmiley Tongueroperties><cmisSmiley TongueropertyId propertyDefinitionId="cmisSmiley SurprisedbjectTypeId"><cmis:value>cmis:document</cmis:value></cmisSmiley TongueropertyId></cmisSmiley Tongueroperties></cmisraSmiley Surprisedbject></entry>

Can someone please advice!!
11 REPLIES 11

jpotts
World-Class Innovator
World-Class Innovator
The cm:description property is part of the cm:titled aspect. In order to use OpenCMIS with content models that leverage aspects, you must use the OpenCMIS Alfresco Extension available at Google Code. The home page for that project shows an example of how to set the cm:description property.

Jeff

sumantapakira
Champ in-the-making
Champ in-the-making
Thanks Jeff,

As per the instruction, I've included alfresco-opencmis-extension-0.4.jar in classpath and modified code as below -
Folder newFolder = root.createFolder(folderProperties);
Map<String, Object> contentProperties = new HashMap<String, Object>();
contentProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled");
contentProperties.put(PropertyIds.NAME, name);
contentProperties.put("cm:description", "Test");
ContentStream contentStream = new ContentStreamImpl(name, new BigInteger(content), "text/plain", stream);
Document document =  newFolder.createDocument(contentProperties, contentStream, null);

But still I get error : Type 'cmis:document,P:cm:description' is unknown!

Could you please advice what is wrong here?

jpotts
World-Class Innovator
World-Class Innovator
Your code runs fine for me against Alfresco 4.2.c. It is strange that the code you pasted has the correct objectTypeId ("cmis:document,P:cm:titled") but the error message you are getting has the property, not the type ("Type 'cmis:document,P:cm:description' is unknown!").

Can you have the correct string for the objectTypeId property and that you are not accidentally overwriting that property somewhere in the code before you call createDocument?

Jeff

jpotts
World-Class Innovator
World-Class Innovator
Also, I note in your curl example that you are using the deprecated, web script-based CMIS URL (/alfresco/s/cmis) instead of the OpenCMIS-based URL (/alfresco/cmisatom). If you are running Alfresco 4 or higher, please switch your URL unless you have a good reason for using the old URL.

Jeff

sumantapakira
Champ in-the-making
Champ in-the-making
Hi Jeff,

In my code I'm using OpenCMIS based URL and I'm using 4.2.c
In my code I'm not overwriting property. First I'm creating folder and then document. Below is the code -

Folder root = session.getRootFolder();
        Map<String, Object> folderProperties = new HashMap<String, Object>();
        String foldername="testfolder";
        folderProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
        folderProperties.put(PropertyIds.NAME, foldername);
Folder  newFolder = root.createFolder(folderProperties);
        Map<String, Object> contentProperties = new HashMap<String, Object>();
        contentProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled");
        contentProperties.put(PropertyIds.NAME, "TestName");
        contentProperties.put("cm:description", "Test");
         byte[] content = " Testdata".getBytes();
        InputStream stream = new ByteArrayInputStream(content);
        ContentStream contentStream = new ContentStreamImpl(name, new BigInteger(content), "text/plain", stream);

       Document document =  newFolder.createDocument(contentProperties, contentStream, VersioningState.MINOR);
Error:
org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException: Type 'cmis:document,P:cm:titled' is unknown!
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:432)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.read(AbstractAtomPubService.java:554)

narithota
Champ in-the-making
Champ in-the-making
Hi sumantapakira,

How do you getting the session object?

I think the problem with session object, Provide your code to get the Session Object.

Hi narithota,

Below code I've written to create session -

private static final String CMIS_ENDPOINT_TEST_SERVER = "http://localhost:8080/alfresco/cmisatom";
  private Session session;
  public String  getCmisClientSession(){
       String repoName=null;
       try{
       SessionFactory factory = SessionFactoryImpl.newInstance();
        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put(SessionParameter.USER, "admin");
        parameters.put(SessionParameter.PASSWORD, "admin");
        // connection settings
        parameters.put(SessionParameter.ATOMPUB_URL,
                CMIS_ENDPOINT_TEST_SERVER );
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB
                .value());
         session =  factory.getRepositories(parameters).get(0).createSession();
    }

Please advice

jpotts
World-Class Innovator
World-Class Innovator
You are missing:

// Set the alfresco object factory
parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");


Which needs to be called before you instantiate the session.

Jeff

sumantapakira
Champ in-the-making
Champ in-the-making
Thanks Jeff,
So this is specific to Alfresco session but if I want to create session for other content management system like Documentum then this will not work I guess. Please let me know your thoughts. I want to make it as vendor repository independent.