cancel
Showing results for 
Search instead for 
Did you mean: 

Setting custom properties(single and multiValue)

anujcb
Confirmed Champ
Confirmed Champ
Hi All,

   Newbie to alfresco here. I am trying to set custom properties on a custom type and the custom properties are not being set. Please help

Here is the code I am using….

         String urlString = "http://'+ipaddress+':8080/alfresco/service/api/upload?alf_ticket="
               + authTicket;
         System.out.println("The upload url:::" + urlString);
         HttpClient client = new HttpClient();

         PostMethod mPost = new PostMethod(urlString);
         // File f1 =fileobj;
         Part[] parts = {
               new FilePart("filedata", filename, fileobj, filetype, null),
               new StringPart("filename", filename),
               new StringPart("contenttype", "rs:invoiceDoc" ),
               new StringPart("description", description),
               new StringPart("rs:itemName","Item1,Item2"),
               new StringPart("rs:vendor","sample vendor"),

               // modify this according to where you wanna put your content
               new StringPart("siteid", siteid),
               new StringPart("containerid", "documentLibrary"),
         // new StringPart("uploaddirectory", "/Company Home")
         };
         mPost.setRequestEntity(new MultipartRequestEntity(parts, mPost
               .getParams()));
         int statusCode1 = client.executeMethod(mPost);


The code actually creates the document of the right content type, rs:invoiceDoc. But the property values rs:itemName and rs:vendor (custom properties of rs:invoiceDoc) are not getting set.  What am I missing?

Also, rs:itemName is a multi valued property, is this the right way to set multiple values to a multi valued property?
new StringPart("rs:itemName","Item1,Item2")

13 REPLIES 13

mitpatoliya
Star Collaborator
Star Collaborator
you need to use array-list or array instead of comma separated string for multivalued property.
something like this

ArrayList value=new ArrayList();
value.addAll(Arrays.asList(new String[] { "Item1,Item2}));
new StringPart("rs:itemName",value),

ArrayList is not a valid parameter to StringPart(). Wont compile.  "The constructor stringPart(String, ArrayList<String>) is undefined"

anujcb
Confirmed Champ
Confirmed Champ
Thank you mitpatoliya for the answer. My other issue is that the code is not setting values on the custom properties.

Following is NOT working…what am i doing wrong?

               new StringPart("rs:itemName","Item1,Item2"),
               new StringPart("rs:vendor","sample vendor"),


following is working


               new FilePart("filedata", filename, fileobj, filetype, null),

               new StringPart("filename", filename),

               new StringPart("contenttype", "rs:invoiceDoc" ),

               new StringPart("description", description),

anujcb
Confirmed Champ
Confirmed Champ
Reading up more…my problem seems to be that I am using repository REST API for Upload to set meta data. I should be using repository REST API for updating metadata to update metadata.

What is the repository REST API for updating metadata(couldn't find it in the docs)? Can the properties not be set while uploading content? should that be a separate transaction? Is there an example?

Should I be using CMIS APIs ?


anujcb
Confirmed Champ
Confirmed Champ
Please help

kaynezhang
World-Class Innovator
World-Class Innovator
As far as I know upload webscript api dose not handle custom properties ,it only handle several fixed arguments such as filename,filedata,siteid,containerid,destination..
Which version of alfresco are you using ?

I am using 5.0.c. Does that mean I have to use Alfresco APIs? What about CMIS APi?

kaynezhang
World-Class Innovator
World-Class Innovator
Yes,you can use opencmis api

kaynezhang
World-Class Innovator
World-Class Innovator
You can implement this webscript api your self ,or you can use  opencmis api. I recommend the later one.