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
Views
Replies
Total Likes
You may use this tool or refer its source code for your requirements -
Views
Replies
Total Likes
I am looking into this. I will post back my results.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
I was able to move a page and it returned the page title as per expectations.
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-
/*
*
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)
Views
Replies
Total Likes
We will capture this AEM API code in new article so it is easy to find
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
Properties as cq:lastReplicated, cq:lastReplicatedBy, cq:lastReplicationAction are not being copied while moving pages. Did someone encounter that?
Views
Likes
Replies