Anjali Shyamsundar
Anjali Shyamsundar

Reputation: 555

AEM- Activating page references in node properties along with the page

I am working on AEM 6.2 and have created a custom replication module. I have some properties in my page's child nodes under jcr:content,whose values are the path field to another pages in the same website. when I am activating a page, I need to activate the pages referenced in the properties too. For example, my page path is "/content/project/family/subfamily/TestPage" I need to activate a page path in the node property "pathVal" under "/content/project/family/subfamily/TestPage/abc123/jcr:content". How do I do this?

Upvotes: 0

Views: 1533

Answers (2)

Ameesh Trikha
Ameesh Trikha

Reputation: 1712

If I understand correctly either you have implemented your own workflow process that activates the page or you would have followed the approach of Preprocessor as outlined by Mateusz Chromiński.

In case you have written your own workflow process that invokes Replicator API you could effectively add logic to get referenced paths and call activate on them using Replicator API

Upvotes: 0

Mateusz Chromiński
Mateusz Chromiński

Reputation: 2832

I am not sure what you mean by

custom replication module


Writing a replication Preprocessor (see docs) may be a way to go. The replication process collects all implementations of that interface using the whiteboard pattern and then cycles through them invoking each one of them.

@Component
@Service
public class ReferencedPagePreprocessor implements Preprocessor {

    @Reference
    private Replicator replicator;

    @Reference
    private ResourceResolverFactory resolverFactory;

    public void preprocess(ReplicationAction action, ReplicationOptions options)  {
        // some extra filtering to avoid the calculation if it's not the expected page type

        String resourcePath = action.getPath();
        ResourceResolver resolver = getResolver();
        Resource resource = resolver.resolve(resourcePath);
        String referencedResourcePath = resource.adaptTo(ValueMap.class).get("pathVal", String.class);

        replicator.replicate(resolver.adaptTo(Session.class), ReplicationActionType.ACTIVATE, referencedResourcePath);
    }

    private ResourceResolver getResolver() {
        ...
    }
}

Take also a look into a sample implementation in ACS AEM Commons

Upvotes: 0

Related Questions