Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How to Copy AEM node one place to another location?

Keerthana_H_N
Level 2
Level 2

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.

1 Accepted Solution
Kiran_Vedantam
Correct answer by
Community Advisor
Community Advisor
0 Replies
lukaszm
Level 5
Level 5

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]

 

[1] https://www.adobe.io/experience-manager/reference-materials/6-5/javadoc/com/day/cq/commons/jcr/JcrUt...

Dipti_Chauhan
Community Advisor
Community Advisor

Hi @Keerthana_H_N 

 If node already exist in destination path, You want to leave it as is or want to replace it with updated properties.

Thanks

Dipti

Keerthana_H_N
Level 2
Level 2

Hi @Dipti_Chauhan I want to replace the current node with updated properties if the node is already there.

Kiran_Vedantam
Correct answer by
Community Advisor
Community Advisor