3

I have a repository, and through the alfresco website, I can set the name, title, and description when I create a folder in a repository.

However, if I try to create the same via opencmis java, I get the error "Property 'cmis:title' is not valid for this type or one of the secondary types!"

Here is my code:

Map<String, String> newFolderProps = new HashMap<String, String>();
newFolderProps.put(PropertyIds.NAME, "this is my new folder");
newFolderProps.put("cmis:description", "this is my description");  //this doesn't work.
newFolderProps.put("cmis:title", "this is my title"); //this doesn't work.

//I also tried this too:

newFolderProps.put(PropertyIds.DESCRIPTION, "this is my description");  //this doesn't work either.
newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");  //this works!
Folder newFolderObject=rootfolder.createFolder(newFolderProps);

I also tried "cm:description" but that doesn't work either.

How do I set the title and description when creating a new folder in Alfresco?

Jeff Potts
  • 10,468
  • 17
  • 40
user2624246
  • 31
  • 1
  • 2
  • This code is based on the GettingStarted.java sample code at http://chemistry.apache.org/java/developing/guide.html#getting-started-with-opencmis – user2624246 Jul 26 '13 at 20:57

2 Answers2

3

Those two particular properties are defined in an aspect called cm:titled. Aspects are not natively supported by CMIS. In order to work with aspects and properties defined in aspects you must use the Alfresco OpenCMIS Extension.

I've created a gist that is a working class you can compile and run that will create a folder (if it doesn't exist), set the description and title, and then create a document within that folder and set the description and title on it.

The key bits are where you establish a session using the Alfresco object factory:

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

And then when you specify the type, you must also specify the aspect:

properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder, P:cm:titled");

The rest of the properties work as you had them, but pay attention to the property names which are cm:description and cm:title:

properties.put(PropertyIds.NAME, folderName);
properties.put("cm:description", TEST_DESCRIPTION);
properties.put("cm:title", TEST_TITLE);
Jeff Potts
  • 10,468
  • 17
  • 40
  • If you are using a version of Alfresco that supports CMIS 1.1, you do not use the Alfresco object factory, but instead use CMIS's native support for aspects, called secondary object types. See the other answer for an example. – Jeff Potts Jun 09 '17 at 19:17
2

You no longer need to use custom Alfresco classes to set secondary attributes. Using Apache Chemistry CMIS 1.1.0 Client;

Map<String, Object> props = new HashMap<>();
props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
props.put(PropertyIds.NAME, "my-doc.txt");
List<String> secondary = new ArrayList<>();
secondary.add("P:cm:titled");
props.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondary);
props.put("cm:title", "My Very Fancy Document");
props.put("cm:description", "This document was generated by me!");

No further code changes are required. If you are using an older Alfresco this will probably not work but most current installs will work out of the box.

John Bryant
  • 327
  • 3
  • 11