cancel
Showing results for 
Search instead for 
Did you mean: 

How to copy a set of nodes into another destination node

sergio
Champ in-the-making
Champ in-the-making
Hi all.

The usual question for today about WS….

I want to copy at once a set of nodes (instead of a single node) into a destination node. I tried the following code


Reference ref = new Reference();
ref.setStore(STORE);
ref.setPath("/app:company_home/cm:Committenti/cm:Test/*");


The folder named "Test" under the folder named "Committenti" under the root of the company home contains three files (nodes) I want to copy at once under the company home itself, as the following code shows:

ParentReference destinationFolder = new ParentReference();
destinationFolder.setStore(STORE);
destinationFolder.setPath("/app:company_home");
destinationFolder.setAssociationType(Constants.ASSOC_CONTAINS);
destinationFolder.setChildName("pippo");

Predicate pred = new Predicate();
pred.setStore(STORE);
pred.setNodes(new Reference[]{ref});
     
CMLCopy copy = new CMLCopy();
copy.setTo(destinationFolder);
copy.setWhere(pred);
     
CML cml = new CML();
cml.setCopy(new CMLCopy[]{copy});
     
UpdateResult[] result = repositoryService.update(cml); 


Unfortunately the Reference class can contain only one node but in this case I have to manipulate three nodes.

My question is: what is the best solution to copy more than one node at once into a destination node?

Many thanks to all.

Best regards,

Sergio
5 REPLIES 5

jtorres
Champ in-the-making
Champ in-the-making
Simply look the signature of CML:


CML(CMLCreate[] create, CMLAddAspect[] addAspect, CMLRemoveAspect[] removeAspect, CMLUpdate[] update, CMLWriteContent[] writeContent, CMLDelete[] delete, CMLMove[] move, CMLCopy[] copy, CMLAddChild[] addChild, CMLRemoveChild[] removeChild, CMLCreateAssociation[] createAssociation, CMLRemoveAssociation[] removeAssociation)

As you can see CML receives an array of CMLCopy[]. You can pass as many items as you can and when you do the update(cml) operation all of them will be copied.

sergio
Champ in-the-making
Champ in-the-making
Hi jtorres.

Many thanks for your useful suggestions.

All the best,

Sergio

raju_myadam
Champ in-the-making
Champ in-the-making
Sergio,
Are you able to resolve copying entire folder or multiple folders to another location?

I also have similar requirement. Could you please pass on your inputs for the same.

Thanks in advance.

Regards,
Raju

mabayona
Champ on-the-rise
Champ on-the-rise
This can very easily achieved using Javascript. Have a look at:

http://wiki.alfresco.com/wiki/JavaScript_API_Cookbook
http://wiki.alfresco.com/wiki/JavaScript_API

moveI() or copy() functions

raju_myadam
Champ in-the-making
Champ in-the-making
Thank you.

In our case we are using webservice API for communicating remotely with Alfresco repository. We have built a custom interface and implementation. The implementation will use the alfresco's web service API.
So planning to copy the files and folders through web service.