Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

How to break inheritance during live copy creation for each page programmatically?

Avatar

Level 2
 
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @bkkothari2255, you can try to reuse below code, this is not a full solution but it shows how msm api can be used programmatically - the result will be canceled inheritance (suspend) for given page resource.

In general LiveRelationshipManager allows you to full manage relationships (including, cancel inheritance, detach etc) - here you can find link to java docs - [1]

import com.day.cq.wcm.msm.api.LiveRelationshipManager;
import com.day.cq.wcm.msm.api.LiveRelationship;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Reference;

// place for your class definition

@Reference
private LiveRelationshipManager liveRelationshipManager;

// place for other code

public void cancelPageInheritance(Resource pageResource, ResourceResolver resourceResolver) {
    if (liveRelationshipManager.hasLiveRelationship(pageResource)) {
        LiveRelationship liveRelationship = liveRelationshipManager.getLiveRelationship(pageResource, true);
        if (liveRelationship != null) {
            liveRelationshipManager.cancelRelationship(resourceResolver, liveRelationship, false, true);
        }
    }
}

[1] - https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/wcm/msm/ap...

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @bkkothari2255, you can try to reuse below code, this is not a full solution but it shows how msm api can be used programmatically - the result will be canceled inheritance (suspend) for given page resource.

In general LiveRelationshipManager allows you to full manage relationships (including, cancel inheritance, detach etc) - here you can find link to java docs - [1]

import com.day.cq.wcm.msm.api.LiveRelationshipManager;
import com.day.cq.wcm.msm.api.LiveRelationship;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Reference;

// place for your class definition

@Reference
private LiveRelationshipManager liveRelationshipManager;

// place for other code

public void cancelPageInheritance(Resource pageResource, ResourceResolver resourceResolver) {
    if (liveRelationshipManager.hasLiveRelationship(pageResource)) {
        LiveRelationship liveRelationship = liveRelationshipManager.getLiveRelationship(pageResource, true);
        if (liveRelationship != null) {
            liveRelationshipManager.cancelRelationship(resourceResolver, liveRelationship, false, true);
        }
    }
}

[1] - https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/wcm/msm/ap...