cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco RestFull Api and Metadata

albertogarcía
Champ in-the-making
Champ in-the-making
Hi,

I'm new to the page and to Alfresco.

I'm developing a basic Alfresco Java proyect and need some advice. I have to upload, download and delete files from alfresco (already done with similar code)

Next step, I have to modify the properties of a node. I can access to the properties with the URL, but when I try to change any property I always get the following error:

Expression node is undefined on line 10, column 6 in org/alfresco/cmis/item.put.atomentry.ftl.


This is the code:
         String urlStringPut = "http://192.168.0.33:8070/alfresco/service/api/node/workspace/SpacesStore/689ab69e-39ab-4e50-ac02-866..."
               + authTicket;
         
         PutMethod mPut = new PutMethod(urlStringPut);
         Part[] parts = {
               new StringPart("cm:description", "description")
         };
         mPut.setRequestEntity(new MultipartRequestEntity(parts, mPut
               .getParams()));
         
         int statusCode2 = client.executeMethod(mPut);
                        mPut.releaseConnection();


The conection works well since I can get the xml with the same URL. I can't use Spring since the code is not mine.

Thanks in advance
4 REPLIES 4

marsbard
Champ in-the-making
Champ in-the-making
The error is in this freemarker template which requires a 'node' argument: http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/remote-api/config/alf...

The related javascript calls a getObjectFromUrl() method to get an object containing the node, I'm not sure how it transforms the URL though.

Thing is, the desc.xml lists this script as deprecated: http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/remote-api/config/alf... - perhaps you should try using the more modern CMIS interface instead of the old webscript-based one

There are some examples here: http://ecmarchitect.com/archives/2013/09/15/3554

Thanks a lot marsbard, but I think I can't use CMIS interface since the final version of ALfresco that will be installed will be 3.1.2 (old server)

¿Is there anything I could do with that version?

How can I get the script to return a node?

kaynezhang
World-Class Innovator
World-Class Innovator
You have made several mistakes
1. You want to update properties ,you should not put property values in to mutlipart
2.This webscript  will accept atomentry format ,so you should construct application/atom+xml request.

You can use below code as a example

String urlStringPut = "http://192.168.0.33:8070/alfresco/service/api/node/workspace/SpacesStore/689ab69e-39ab-4e50-ac02-866..."
+ authTicket;

PutMethod put = new PutMethod(urlStringPut );
         String test = FileUtils.readFileToString(new File("E:\\updateNode.xml")); //you can construct xml thro proggram,this is just a test.
         put.setDoAuthentication(true);
         put.setRequestHeader("Content-Type", "application/atom+xml");
         put.setRequestEntity(new StringRequestEntity(test,
               "application/atom+xml", "UTF-8"));

         int status = client.executeMethod(put);
         if (status != HttpStatus.SC_OK) {
            System.err.println("Method failed: " + put.getStatusLine());
         }
         String resultString = put.getResponseBodyAsString();
   

Following is content of updateNode.xml

<entry xmlns="http://www.w3.org/2005/Atom" xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/" xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/" xmlns:alf="http://www.alfresco.org">
   <summary>test modify cm:description property ahhahahah</summary> <!– summary is cm:description property–>
   <title>test modify cm_name property</title> <!– title is cm:name property–>
   <cmisra:object>
      <cmis:properties>
         <cmis:propertyInteger propertyDefinitionId="cmis:contentStreamLength" displayName="Content Stream Length" queryName="cmis:contentStreamLength">
            <cmis:value>98495335</cmis:value>
         </cmis:propertyInteger>
         <alf:setAspects>
            <alf:aspectsToAdd>P:cm:titled</alf:aspectsToAdd>
            <alf:properties>
               <cmis:propertyString propertyDefinitionId="cm:title" queryName="cm:title">
                  <cmis:value>New Title hahahahh</cmis:value>
               </cmis:propertyString>
            </alf:properties>
         </alf:setAspects>
      </cmis:properties>
   </cmisra:object>
</entry>

Thanks kaynezhang

I had found a similar solution by creating the xml inside de java class.

Thanks for the solution.