Expand my Community achievements bar.

PageManager move() Issue

Avatar

Level 2

Hi All,

when i try to move pages from one location to another , page gets moved and finally page name changes to 1,2,3....

I need to maintain the same names for the pages.How it can be done?

Using pagemanager api for this.

pmgr.move(page, dest,null, false, true, null, null);

Also need to understand use of "beforeName" and "publishrefs[]" in this move().

kindly help with the info.

-Avinash

9 Replies

Avatar

Level 10

You may use this tool or refer its source code for your requirements -

Renovator

Avatar

Level 10

I am looking into this. I will post back my results.

Avatar

Level 10

I am going to modify this artilce to move the page - but rest of article is very much applicable to working with the AEM Page Manager Java API:

Adobe Experience Manager Help | Creating an Experience Manager 6.3 Page using the Page Manager API

Avatar

Level 10

I was able to move a page and it returned the page title as per expectations.

MovePage.png

The code is similar to the above code - but page service has this Move code:

package com.aem.community.core;

import org.apache.sling.settings.SlingSettingsService;

import org.osgi.service.component.annotations.Activate;

import org.osgi.service.component.annotations.Component;

import org.osgi.service.component.annotations.ConfigurationPolicy;

import org.osgi.service.component.annotations.Reference;

import org.osgi.service.metatype.annotations.Designate;

import java.util.HashMap;

import java.util.Map;

 

import javax.jcr.Node;

import javax.jcr.Session;

 

import org.apache.jackrabbit.commons.JcrUtils;

import org.apache.sling.api.resource.LoginException;

import org.apache.sling.api.resource.ResourceResolver;

import org.apache.sling.api.resource.ResourceResolverFactory;

 

import com.adobe.cq.sightly.WCMUsePojo;

import com.day.cq.commons.jcr.JcrConstants;

import com.day.cq.wcm.api.Page;

import com.day.cq.wcm.api.PageManager;

import org.apache.sling.api.resource.Resource;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

@Component

public class PageServiceImp implements PageService {

    

private final Logger logger = LoggerFactory.getLogger(getClass());

private String user = "";

    

    private Session session;

    

    //Inject a Sling ResourceResolverFactory

    @Reference

    private ResourceResolverFactory resolverFactory;

    

    

    public String MovePage()

    {

    String pagePath = "/content/MovePage64/fr";

    String newPagePath ="/content/MovePage64/en" ;

    String templatePath = "/apps/AEMPage/templates/page-home";

    String pageTitle = "AEM home page";

    Page newPage;

    PageManager pageManager;

    

    

    ResourceResolver resolver = null;

   

   

     String newPageName = "";  

    try {

                 

       

        //Invoke the adaptTo method to create a Session

        resolver = resolverFactory.getAdministrativeResourceResolver(null);

       

       

        Resource res = resolver.getResource(pagePath);   

       

        //Adapts the resource to another type - in this example to a     com.day.cq.wcm.api.page

         Page page = res.adaptTo(Page.class);

    

        

       // session = resolver.adaptTo(Session.class);

                

        //create a page manager instance

        pageManager = resolver.adaptTo(PageManager.class);

        

        //Move a given page and return the new page- 

        /*

         *

Page move(Page page,

   String destination,

   String beforeName,

  boolean shallow,

  boolean resolveConflict,

   String[] adjustRefs)

  throws WCMException

         */

      

//move the page using the API

newPage = pageManager.move(page,newPagePath,null,true,true,null);

       

        if (newPage != null) {

        newPageName= newPage.getPageTitle();

        logger.info("*** PAGE NAME IS "+newPageName);

            }

        else

        {

        logger.info("*** PAGE CANNOT BE MOVED -- ERROR");

        }

        

        return newPageName;

    } catch (Exception e) {

        // TODO Auto-generated catch block

        logger.info("&&&&& BIG ERROR" +e.getMessage());

    }

    

    return ""  ;

}

}

You can look at the parameters of the MOVE method in the Javadocs -- "The Adobe AEM Quickstart and Web Application."  (LOOK AT PAGE MANAGER)

Avatar

Level 10

We will capture this AEM API code in new article so it is easy to find

Avatar

Level 10

Hi Avinash,

move method in pagemanager API should work without any issues.

Are you moving the same page to the same location multiple times? If so, it would create a node with 0,1,2.. etc.

Avatar

Level 2

Properties as cq:lastReplicated, cq:lastReplicatedBy, cq:lastReplicationAction are not being copied while moving pages. Did someone encounter that?

Avatar

Community Advisor

Yes, that is expected. As the moved page is new to the current destination path and that path never existed before. So you'll have to check if the page was published before and republish it post the movement.

 

-Sravan

Avatar

Community Advisor

Hey, you'll have to give the destinationPath as the name you want it to be.
String destination path = page.getParent().getPath + page.getName;
here the page is the one page that you wanted to move.

And "beforeName" is the name of the sibling page, where your moved(wanted to move) page (lets say pageB) should be after. For example, if you want to move the pageB right below to the /content/siteA/pageA, then the beforeName would be pageA.

 

publishedReferences is a String[] of paths of your current pageB which have a component in them that is referring your pageB and were published. So when the references are adjusted after the movement, the published pages are republished with the modified references.

please refer this API doc: https://developer.adobe.com/experience-manager/reference-materials/6-4/javadoc/com/day/cq/wcm/api/Pa... 

Thank you.
-Sravan