Copy a Noderef – either Non-Recursive or Recursive

I am replacing the CrossRepositoryCopyService().copy action since we are going from multiple repo’s to one. So I am replacing this service..

// RECURSIVE copy – but specific for multiple repo’s.
serviceRegistry.getCrossRepositoryCopyService() .copy(src, dst,new_name);

 

So I started by re-using the FileFolderService to copy a node from A to B. This works great, but it only copies the node & leaves all children of the source untouched (and more importantly un-copied)  => Non-recursive copy. The FileFolderService() has no recursive copy action available.

// Non-RECURSIVE copy of one node
FileInfo finf = serviceRegistry.getFileFolderService().copy(src, dst, new_name);
return finf.getNodeRef();
There are quite a lot of copy actions available in Alfresco, but this one seems quite elegant. Also the service name alone gives me some hope of giving me what i need.
Enter the CopyService()

 

// RECURSIVE copy

NodeRef copy2 = serviceRegistry.getCopyService().copy(src, dst, ContentModel.ASSOC_CHILDREN, QName.createQName(new_name), true);

and since I am here now – it also has a usefull

// NON-RECURSIVE copy

NodeRef copy = this.copyService.copy(src, dst, ContentModel.ASSOC_CHILDREN, QName.createQName(“newname”));
Big thanks to : http://kickjava.com/

Advertenties

One thought on “Copy a Noderef – either Non-Recursive or Recursive

  1. Another way of doing it, is by just using the copy action already in Alfresco. Calling it in Java looks like this:

    Map params = new HashMap();
    params.put(CopyActionExecuter.PARAM_DEEP_COPY, true);
    params.put(CopyActionExecuter.PARAM_DESTINATION_FOLDER,dst);
    params.put(CopyActionExecuter.PARAM_OVERWRITE_COPY, true);
    Action copyAction = serviceRegistry.getActionService().createAction(CopyActionExecuter.NAME, params);
    serviceRegistry.getActionService().executeAction(copyAction, src);

Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen.

WordPress.com logo

Je reageert onder je WordPress.com account. Log uit / Bijwerken )

Twitter-afbeelding

Je reageert onder je Twitter account. Log uit / Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit / Bijwerken )

Google+ photo

Je reageert onder je Google+ account. Log uit / Bijwerken )

Verbinden met %s