I need to copy an AEM JCR node source to destination. The following code is working but if that node already exists in the destination I'm getting an error:
String sourcePath="/content/dam/assets/content";
String destinationPath="/content/dam/Marketing/content";
Session session = resourceResolver.adaptTo(Session.class);
Workspace workspace = session.getWorkspace();
workspace.copy(sourcePath, destinationPath);
session.logout();
But the problem is that the content node already exists inside the folder "Marketing" so that it's only working on the first time. Once the content node is created I'm not able to copy/update the node but I need to replace each time without deleting the source node.
Solved! Go to Solution.
Views
Replies
Total Likes
Please check this URL:
https://aemvardhan.wordpress.com/2017/02/24/how-to-copy-aem-node-tree-in-jcrcrx/
Also I see the same question here: https://stackoverflow.com/questions/42420255/how-to-copy-aem-node-one-place-to-another-location
Hope this helps.
Thanks,
Kiran Vedantam.
Hi @Keerthana_H_N, I am not sure if I understood your use case correctly, however please check copy method from com.day.cq.commons.jcr.JcrUtil [1]
This worked very well to copy whole node from source location to destination.
Views
Replies
Total Likes
If node already exist in destination path, You want to leave it as is or want to replace it with updated properties.
Thanks
Dipti
Hi @Dipti_Chauhan I want to replace the current node with updated properties if the node is already there.
Please check this URL:
https://aemvardhan.wordpress.com/2017/02/24/how-to-copy-aem-node-tree-in-jcrcrx/
Also I see the same question here: https://stackoverflow.com/questions/42420255/how-to-copy-aem-node-one-place-to-another-location
Hope this helps.
Thanks,
Kiran Vedantam.
Views
Likes
Replies
Views
Like
Replies