Expand my Community achievements bar.

SOLVED

Trying to move a Page from one place to another through backend(java)

Avatar

Employee

Hi,

I am trying to change the path of my "demomovement" page to archive-articles. But somewhere its crashing. Can anyone please help me out here?

 

 

@Override public void run() {

String rs="/content/enablementCapstone/us-capstone/en/article/demomovement";
Page page = resourceResolver.getResource(rs).adaptTo(Page.class);
PageManager pm = resourceResolver.adaptTo(PageManager.class);
String TargetPage="/content/enablementCapstone/us-capstone/en/archive-articles";
try{
pm.move(page, TargetPage, null, false, true, null);
}
catch(Exception e){
LOG.info("ErrorInMovement");
}
LOG.info("\n ====> RUN METHOD !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!S");
}
 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

what is the error on logs?

Try having the shallow field as true to move the page content, as in "pm.move(page, TargetPage, null, true, true, null);" and also, make sure you have the write permissions.

are you running this on scheduler? check your cron expression timing etc.., to perform the action immediately.

 

Also, instead of passing null for references, you can have the references of the resource, check this – here is the way to find our resources' references acs-aem-commons/PagesReferenceProvider.java at master · Adobe-Consulting-Services/acs-aem-commons · ... 

 

Thank you.


View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

what is the error on logs?

Try having the shallow field as true to move the page content, as in "pm.move(page, TargetPage, null, true, true, null);" and also, make sure you have the write permissions.

are you running this on scheduler? check your cron expression timing etc.., to perform the action immediately.

 

Also, instead of passing null for references, you can have the references of the resource, check this – here is the way to find our resources' references acs-aem-commons/PagesReferenceProvider.java at master · Adobe-Consulting-Services/acs-aem-commons · ... 

 

Thank you.