How to create custom property on object using Apache Chemistry

☆樱花仙子☆ 提交于 2019-12-13 19:03:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!