0

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.

vosejillarsc
  • 75
  • 1
  • 1
  • 5
  • Create a new *Aspect* which defines+holds the custom property you want to add, then attach that along with the new property? – Gagravarr Jan 11 '23 at 13:18

1 Answers1

1

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

David Dejmal
  • 359
  • 1
  • 8