1

I want to copy and paste the page even if it has any child pages. If I have copy-pasted the page successfully then rerunning that workflow should overwrite the copied page if the page is already present.

Current approach:

public void copyPage(String productPagesRootPath, ResourceResolver resourceResolver) {
    PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
    Page page = pageManager.getPage(productPagesRootPath);
    Resource parent = resourceResolver.resolve(page + "/target");
    try {
        if (parent.getResourceType().equals(Resource.RESOURCE_TYPE_NON_EXISTING)) {
          pageManager.create(productPagesRootPath, "target", "Template", "Copy_Temp");
        }
        pageManager.copy(page, productPagesRootPath+ "/target/newPage", null, true, false);
    } catch (WCMException e) {
        LOG.error("Error in Copying Page ", e.getMessage(), e);
    }
}

This is running good but whenever I rerun the code it doesn't overwrite but pops an error. If possible I also want to copy the page in the same path. Above code is creating child page /target/newPage.

Summary: I just want to copy-paste with a different name. If a copy is available then just Overwrite that copy using AEM Workflow Java

Please optimize the approach as well. Thanks in advance.

João Dias
  • 16,277
  • 6
  • 33
  • 45
Ronnie
  • 29
  • 3

0 Answers0