cancel
Showing results for 
Search instead for 
Did you mean: 

Copy nodes - duplicates

gjovanov
Champ in-the-making
Champ in-the-making
Hi!
We have a very specific situation where we want to copy only children nodes recursively from a given source to a given destination space. The problem is that the source children spaces can already be contained in the destination space. And the when we copy them, for the common spaces we get duplicates in the destination whereas the duplicates occur with the name: "Copy of" + original-name. What we want to achieve is FILE_SYSTEM-copy-like operation as if when a space already exist within the destination should be skipped and it should continue to its children.

e.g. first we copy Designs children spaces:
/Company Home/Templates/Design/01-Offer/…
                                                /02-Testing/…
                                                /03-Design/…

to the destination:
/Company Home/Projects/Kiss/

as a result we get:
/Company Home/Projects/Kiss/01-Offer/
                                          /02-Testing/
                                          /03-Design/

and then we want to copy Developments children spaces:
/Company Home/Templates/Development/01-Offer/…
                                                         /02-Testing/…
                                                         /04-Development/…

also to the same destination:
/Company Home/Projects/Kiss/

and as a result we get:
/Company Home/Projects/Kiss/01-Offer/..
                                          /Copy of 01-Offer/..
                                          /02-Testing/…
                                          /Copy of 02-Testing/…
                                          /03-Design/..
                                          /04-Development/…

Even though we would expect the following result:
/Company Home/Projects/Kiss/01-Offer/..
                                          /02-Testing/…
                                          /03-Design/..
                                          /04-Development/…

we use the CMLCopy command for every child within the source folder:

        CMLCopy copy = new CMLCopy();
        copy.setTo(destinationChildReference);
        copy.setChildren(true);
        copy.setAssociationType(Constants.ASSOC_CONTAINS);
        copy.setWhere(new Predicate(new Reference[] { sourceReference }, STORE, null));
       

        CML cml = new CML();
        cml.setCopy(new CMLCopy[] { copy });

        getRepositoryService().update(cml);


Any suggestions?
1 REPLY 1

openpj
Elite Collaborator
Elite Collaborator
You need to manage all these checks by Web Serivces API.
Whenever you'll try to check if a space exist using a get invocation, if returns an exception then it means that this space doesn't exist otherwise yes.


public boolean checkIfExistOnAlfresco(String yourSpacePath){
   try {
        AuthenticationUtils.startSession(username, password);
        Store store = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
        Reference reference = new Reference(STORE, null, yourSpacePath);
        WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{reference}, STORE, null));
        return true;
   } catch (Exception exception) {
        return false;
   } finally {
       AuthenticationUtils.endSession();
   }
}