问题
I'm working with a local instance of Alfresco CMS and I'm using the Apache Chemistry Java CMIS. Everything works well for browsing and creating objects, however I'm having a hard time adding metadata on documents.
There is an example on their source page code saying that you need to call updateProperties
on the CmisObject
. Unfortunately, this doesn't work, the exception I got stating: Property 'my:property' is not valid for this type or one of the secondary types
Do you know how can I add a custom property? Do I have to enhance the existing aspects collection and if so, how can I do it?
Thanks.
回答1:
Property 'my:property' is not valid for this type or one of the secondary types
my:property seems to be a custom property, and should then be handled with a custom Alfresco aspect.
If you want to use Alfresco aspects, you will need the Alfresco OpenCMIS Extension
The following code fragment allows to use the Alfresco Extension with OpenCMIS:
Map<String, String> parameter = new HashMap<String, String>();
// user credentials
parameter.put(SessionParameter.USER, "admin");
parameter.put(SessionParameter.PASSWORD, "admin");
// connection settings
parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/cmisatom");
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
// set the alfresco object factory
parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
// create session
SessionFactory factory = SessionFactoryImpl.newInstance();
Session session = factory.getRepositories(parameter).get(0).createSession();
The following code allows to create a new document with a custom property filled :
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "doc1");
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,my:docProps");
properties.put("my:property", "My document");
Document doc = session.getRootFolder().createDocument(properties, null, null);
回答2:
Custom properties should be defined in the repository and then you can try to set them in CMIS properties.
来源:https://stackoverflow.com/questions/17217036/how-to-create-custom-property-on-object-using-apache-chemistry