Highlighted

PageManager move() Issue

Avatar

Avatar

avinasht6348431

Avatar

avinasht6348431

avinasht6348431

05-02-2019

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

Replies

Highlighted

Avatar

Avatar

Gaurav-Behl

MVP

Total Posts

1.1K

Likes

226

Correct Answer

281

Avatar

Gaurav-Behl

MVP

Total Posts

1.1K

Likes

226

Correct Answer

281
Gaurav-Behl
MVP

06-02-2019

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

Renovator

Highlighted

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K
smacdonald2008

06-02-2019

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

Highlighted

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K
smacdonald2008

06-02-2019

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

Highlighted

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K
smacdonald2008

06-02-2019

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)

Highlighted

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K
smacdonald2008

06-02-2019

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

Highlighted

Avatar

Avatar

bsloki

MVP

Total Posts

1.9K

Likes

172

Correct Answer

544

Avatar

bsloki

MVP

Total Posts

1.9K

Likes

172

Correct Answer

544
bsloki
MVP

06-02-2019

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.

Highlighted

Avatar

Avatar

knitshweta

Avatar

knitshweta

knitshweta

05-08-2020

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