vosejillarsc
vosejillarsc

Reputation: 93

Add metadata when creating file in alfresco from java

I want to add to a file custom metadata when i create the file from java.
I can add some propperties i copy from the page i saw the tutorial but i cannot add more.

This is my code:

Map<String, Object> properties2 = new HashMap<String, Object>();
properties2.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
properties2.put(PropertyIds.NAME, file.getOriginalFilename());
properties2.put("propertyName", "propertyValue");

And this is the error i am getting:

Property 'propertyName' is not valid for this type or one of the secondary types!

Thanks.

Upvotes: 0

Views: 176

Answers (1)

David Dejmal
David Dejmal

Reputation: 409

I don't know which function did you use for creation new "file", but properly is use nodeService.createNode(). Or if you want to only add properties nodeService.setProperties(). Parameter properties is type Map<QName,Serializable> not Map<String, Object>. So code then can look like this:

    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    properties.put(ContentModel.PROP_TITLE, "My title");
    properties.put(ContentModel.PROP_DESCRIPTION, "My description");
    properties.put(QName.createQName("http://www.somceCo.cz/org/model/content/1.0", "my_property"), "My value"); 
    nodeService.setProperties(nodeRef,properties);
    

It's good to have all own QName in separate file called Model. Take inspiration here https://github.com/Alfresco/alfresco-data-model/blob/master/src/main/java/org/alfresco/model/ContentModel.java

Upvotes: 1

Related Questions