Surya Chandra
Surya Chandra

Reputation: 1591

AEM / CQ5 - livecopy - how to get the list of live copy pages (if any), for a given page path(which is blueprint in this case)

I would like to get the list of live copy pages for any given blue print page. So, if I have given a page path, I should be able to list out all its live copies(if any). Can this be achieved with any API?

Upvotes: 2

Views: 2662

Answers (2)

Md Rahman
Md Rahman

Reputation: 1820

Need to do the following steps

  • Add dependency to pom.xml

    <dependency>
         <groupId>com.day.cq.wcm</groupId>
         <artifactId>cq-msm-api</artifactId>
         <version>5.7.2</version>
         <scope>provided</scope>
    </dependency>       
    
  • Add two references

    @Reference
    private ResourceResolverFactory resolverFactory;
    
    @Reference
    LiveRelationshipManager liveRelManager;
    
  • Add the code where you need liveCopy list.

     List<LiveCopy> liveCopyList = new ArrayList();
        try {
            ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
            String givenPageOrBlueprint = "/content/we-retail/ca/en/experience/climbing-in-the-massif-du-mont-blanc";
            Resource res = resourceResolver.getResource(givenPageOrBlueprint);
            RangeIterator rangeIterator = liveRelManager.getLiveRelationships(res,"",null);
            while (rangeIterator.hasNext())
            {
                LiveRelationship liveCopy =(LiveRelationship) rangeIterator.next();
                liveCopyList.add(liveCopy.getLiveCopy());
    
            }
    
        } catch (Exception e) {
            e.printStackTrace();
        }
    

Upvotes: 0

Imran Saeed
Imran Saeed

Reputation: 3444

Live copies of a resource (page) can be obtained by the official API

You just need to use LiveRelationshipManager.getLiveRelationships in order to get the live relationships.

Depending on the version of AEM you are using and the complexity of your BluePrint setup and depth of LiveCopy inheritance (and cancellations) this API could have performance impacts.

  • For pre AEM 6.0 SP3, it will be pretty slow and is not entirely optimised.
  • AEM 6.1 SP1 and all the way to latest version this API is optimised for performance.

In effect, it should return the same data which is visible via CQ Blueprint manager screen.

Upvotes: 4

Related Questions