cancel
Showing results for 
Search instead for 
Did you mean: 

Java Api CMIS - change attribuite 'cm:creator' = 'cmis:createdBy'

dmralfing
Champ in-the-making
Champ in-the-making
I´m implementing a migration with the CMIS Java Api for Alfresco 4.1. The problem is that I have to migrate also the values that indicates the owner of the files, so I have to put values in the attributes cm:creator and cm:modifier - that matches with cmis:createdBy and cmis:lastModifiedBy - .
Does it exist any way to put this values in code?.
Thank you so much
13 REPLIES 13

kaynezhang
World-Class Innovator
World-Class Innovator

You can modity these propertis by java api or customize a java backed webscript .

First you should disable auditable aspect ,this will allow you to change properties of cm:auditable aspect

policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);

// Update properties of cm:auditable aspect
nodeService.setProperty(nodeRef, ContentModel.PROP_CREATOR, "xxxxxx");
nodeService.setProperty(nodeRef, ContentModel.PROP_MODIFIER, "xxxxxx");

// Enable auditable aspect
policyBehaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);

I suggest you customize a java backed webscript . after creating a node using cmis api ,you call your webscript api to modify these properties.

dmralfing
Champ in-the-making
Champ in-the-making

In the behavior the class takes OK the policyBehaviourFilter with the getter. I do this:

   public void beforeUpdateNode(NodeRef arg0)
   {
          policyBehaviourFilter.disableBehaviour(arg0, ContentModel.ASPECT_AUDITABLE);
   }
   public void onUpdateNode(NodeRef nodo)
   {
   //if I uncomment this lines below, it takes the values fine but I don´t want to put this values in the behavior
   //nodeService.setProperty(nodo, ContentModel.PROP_CREATOR, "Barack Obama");
   //nodeService.setProperty(nodo, ContentModel.PROP_MODIFIER, "Michael Jackson");
       }
   }

In the webscript I do this - look that I one of the attributes in the parameters is "cm:modifier" -

  public static String pruebaChangeOwner () throws Exception
     {
        String strParams="{\"prop_cm_name\":\"pruebaREAL\",\"prop_cm_title\":\"JOJO\",\"prop_cm_modifier\":\"danone\",\"prop_mimetype\":\"application/pdf\",\"prop_cm_author\":\"aaaaa\",\"prop_cm_taggable\":\"\"}";
        String result=executePOST (cookieStore, "http://localhost:8080/share/proxy/alfresco/api/node/workspace/SpacesStore/85118fe0-c681-4d61-9f3f-3f...", strParams,"application/json");
        System.out.println(result);
        return result;
     }
     private static String executePOST (CookieStore cookieStore, String url, String parametros, String strContentType) throws Exception 
     {
      try
      {
         DefaultHttpClient client = new DefaultHttpClient();
         client.setCookieStore(cookieStore);
         HttpPost post = new HttpPost(url);
         post.setHeader("Content-Type", strContentType);
         post.setEntity(new StringEntity(parametros,"UTF-8"));
         ResponseHandler<String> responseHandler = new BasicResponseHandler();
         String response = client.execute(post, responseHandler);
         return response;
      }
      catch (ClientProtocolException ex){return ex.getMessage();}
      catch (IOException ex){return ex.getMessage();}
      catch (Exception ex){return ex.getMessage();}
   }//execute
    

It updates all atributes but "cm:modifier" is not updated. This is the result printed in console:

{
   
    "persistedObject": "workspace://SpacesStore/85118fe0-c681-4d61-9f3f-3f4311315499",
    "message": "Successfully persisted form for item [node]workspace/SpacesStore/85118fe0-c681-4d61-9f3f-3f4311315499"
}

I have tried also with cmis and it doesn´t work anyway. So I think that maybe I have to try to pass
the values somehow to the behavior in order to let him write them. But the webscript doesn´t take it!

kaynezhang
World-Class Innovator
World-Class Innovator
You can try to customize your own webscript ,and in your webscript.
First disable auditable aspect

policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);

Then update cm:modifier、cm:createor properties
At last enable auditable aspect
policyBehaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);

dmralfing
Champ in-the-making
Champ in-the-making
Ok, it´s done and work fine, thank you!
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.