Regarding Moving page in AEM 6.5 | Community
Skip to main content
akshatn
Employee
Oct 3, 2022 5:16 PM UTC
Solved

Regarding Moving page in AEM 6.5

Hello there I am trying to move page to achieve after a certain period of time I had created scheduler for that but  I am not able to move pages also i tried with workspace and session.move method to move the pages but it is not working kindly help!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Oct 4, 2022 7:12 AM UTC

@arunpatidar Done! Still getting java.lang.NullPointerException... is there any other modification needed?


I have a sample example here

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/MovePageServlet.java 

Arun Patidar

7 replies

joerghoh
Employee
Oct 3, 2022 5:38 PM UTC

You should use the PageManager API for this task, see [1].

 

It could look like this:

Page pageToMove = ...
String targetPath = ...
String[] references = ...
PageManager = pageToMove.adaptTo(PageManager.class);
PageManager.move (pageToMove.adaptTo(Resource.class),  targetPath, false, true, references);

You should not use the lowlevel of Sling and JCR for that task, because they cannot handle aspects like the MSM and many other specialities.

Another important aspect I left out is the question if references to this page must be adjusted, too. To help you in that task, please consult [2].

 

 

 

 

[1] https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/index.html?com/day/cq/wcm/api/PageManager.html

[2] https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/wcm/commons/ReferenceSearch.html

Translate
akshatn
akshatnAuthor
Employee
Oct 3, 2022 6:04 PM UTC

@joerghoh Hi there in continuation with the previous query i tried the same this still i am getting the error

This is my crxde Hierarchy

|-Articles
        |-jcr.content
        |-Article-1
        |      |-root
        |      |-container
        |      |-responsivegrid
        |                    |-rtetext
        |                    |-bannerarticle
        |-Article-2
...

This is my QueryBuilder Output

-------------------------------------------

/content/.../Articles/Article-3, (crxde, html, json)
/content/.../Articles/Article-5, (crxde, html, json)
/content/.../Articles/Article-2, (crxde, html, json)
/content/.../Articles/Article-4, (crxde, html, json)
/content/.../Articles/Article-1, (crxde, html, json)

Here is my code

---------------------------------------------

               
                Page pageToMove = hit.getResource().adaptTo(Page.class);
                String pagename= pageToMove.getPath().substring(pageToMove.getPath().lastIndexOf("/"));
                String targetPath = "/content/.../Articles/Archived"+pagename;
                String[] references = {"jcr:content", "jcr:content/root"};
                pageManager = pageToMove.adaptTo(PageManager.class);
                pageManager.move (pageToMove,  targetPath, pagename , false, true, references);
And the output for the same is
---------------------------------------------
2022-10-03 23:27:00.010 ERROR [com.aem.core.schedulers.ArticleArchive] Page to move is ====> /content/.../Articles/Article-5
2022-10-03 23:27:00.010 ERROR [com.aem.core.schedulers.ArticleArchive] Target path is ====> /content/.../Articles/Archived/Article-5 //There is no page like Article-5 i have embed that in code because i had read somewhere that we need to mention the name of file in targetpath
2022-10-03 23:27:00.010 INFO [com.aem.core.schedulers.ArticleArchive] Exception in Schedular====> java.lang.NullPointerException
Please Help!
Translate
arunpatidar
New Participant
Oct 3, 2022 7:35 PM UTC

You must have the path created till/content/.../Articles/Archived and trying to remove page name from target path. e.g.

 String targetPath = "/content/.../Articles/Archived

Translate
Arun Patidar