cancel
Showing results for 
Search instead for 
Did you mean: 

set cm:description properties

ccc_chen
Champ in-the-making
Champ in-the-making
Hello!

I try to set the cm:descripion properties by a document/folder by using openCMIS in alfresco.
My test code is:

public class Testing
{
    public static void main(String args[])
    {
        System.out.println(Testing.class.getName() + " started");
        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
        Map<String, String> parameter = new HashMap<String, String>();
       
        parameter.put(SessionParameter.USER, "admin");
        parameter.put(SessionParameter.PASSWORD, "admin");
       
        parameter.put(SessionParameter.BINDING_TYPE,
                BindingType.ATOMPUB.value());
        parameter.put(SessionParameter.ATOMPUB_URL,
                "http://127.0.0.1:8080/alfresco/service/cmis");

        try
        {
            List<Repository> repositories = sessionFactory.getRepositories(parameter);
            Repository repository = repositories.get(0);
            Session session = repository.createSession();
            session.getDefaultContext().setCacheEnabled(false);
           
            System.out.println("Got a connection to repository: " + repository.getName() + ", with id: "
                    + repository.getId());

            Map<String, Object> properties = new HashMap<String, Object>();
            properties.put(PropertyIds.NAME, "doc1");
            properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled");
            properties.put("cm:description", "My document");
            Document doc = session.getRootFolder().createDocument(properties, null, null);
        }
        catch (CmisRuntimeException ex)
        {
            ex.printStackTrace();
        }

        System.out.println(Testing.class.getName() + " ended");
    }
}
but the output is droped by a exception with  "org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException: Bad Request"
in the row "Document doc = session.getRootFolder().createDocument(properties, null, null);"
What is wrong in this case, please help me!   Smiley Sad  :?:
6 REPLIES 6

mrogers
Star Contributor
Star Contributor
Is versionState of null valid?   There's a value of NONE to mean no version state.

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

Is versionState of null valid?

Yes. Its valid. and even I tried to upload the document with version state as MAJOR. But I am getting the same error.

If remove the line,
 properties.put("cm:description", "My document");
document is uploading successfully.

So the problem lies in this line.

Do I need to do any server side modifications to use these tags?

Please provide some suggestions to solve this problem.

Thanks
Naresh

mrogers
Star Contributor
Star Contributor
Sorry don't know too much about CMIS. :mrgreen:   

Just realised cm:description is on the titled aspect,  that could be part of your problem.

I see there is this example of setting titled.
http://code.google.com/a/apache-extras.org/p/alfresco-opencmis-extension/

sumantapakira
Champ in-the-making
Champ in-the-making
Is that issue resolved? I'm facing similar issue.
When I'm executing a POST by using 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>

But when I'm executing through java code then 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);

Can someone please advice!!

jpotts
World-Class Innovator
World-Class Innovator
sumantapakira,

Please follow the example Mark Rogers linked to in his post. The description is part of the titled aspect. You must therefore use the OpenCMIS extension for Alfresco because CMIS 1.0 does not support aspects. The page he referenced has the exact example of setting the description field.

If that doesn't work, respond with the specific version of OpenCMIS you are using, your Alfresco version, which binding you are using, your CMIS URL, and any error message you are seeing.

Jeff

dawit
Champ in-the-making
Champ in-the-making
I am getting the same error (Bad Request) like the folks above.
I am using Alfresco 3.4.a (unfortunately stuck their). OpenCmis (0.8.0) and alfresco-opencmis-extension (0.8)

..
parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8101/alfresco/service/cmis");
parameter.put(SessionParameter.BINDING_TYPE,BindingType.ATOMPUB.value());
parameter.put(SessionParameter.OBJECT_FACTORY_CLASS,"org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");


And the part where I want to add the metadata:

metadata.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled");
metadata.put("cm:description", "DY Description");
//metadata is something like: {cm:description=DY Description, cmis:objectTypeId=cmis:document,P:cm:titled, cmis:name=Some Benefits Guide}
try{
   document = parentFolder.createDocument(metadata, contentStream, null);  //This throws the error
….

} catch (CmisInvalidArgumentException ciae) {
//…IT COMES HERE Saying :
//org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException: Bad Request
}

As the gentlmas stated, if I removed the P:cm:titled and the cm:description, the document loads but I am not sure what I am doing wrong.
Thanks,