Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Custom Live Action does not execute on Rollout page and all sub pages

Avatar

Level 2

Hi,

I've developed a custom live action that executes on Rollout Page but not on Rollout page and all sub pages .

In the code below, VersionNodesLiveAction.execute does not fire on Rollout page and all sub pages, but it does on Rollout Page.

Is there something I'm missing?

package com.test;

import com.day.cq.wcm.api.WCMException;

import com.day.cq.wcm.msm.api.ActionConfig;

import com.day.cq.wcm.msm.api.LiveAction;

import com.day.cq.wcm.msm.api.LiveActionFactory;

import com.day.cq.wcm.msm.api.LiveRelationship;

import com.sonova.support.core.service.component.VersionNodesByPath;

import com.sonova.support.core.utils.SonovaUtils;

import org.apache.felix.scr.annotations.*;

import org.apache.sling.api.resource.Resource;

import org.apache.sling.api.resource.ResourceResolver;

import org.apache.sling.api.resource.ValueMap;

import org.apache.sling.api.wrappers.ValueMapDecorator;

import org.apache.sling.commons.json.JSONException;

import org.apache.sling.commons.json.io.JSONWriter;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import javax.jcr.Node;

import javax.jcr.RepositoryException;

import java.util.Collections;

import java.util.Map;

/**

* Creates actions for each node being rolled out.

*

*/

@Component(metatype = false)

@Service

public class VersionNodesLiveActionFactory implements LiveActionFactory<LiveAction> {

   @Property(value = "versionNodesLiveAction")

   static final String actionname = LiveActionFactory.LIVE_ACTION_NAME;

   private static final Logger log = LoggerFactory.getLogger(VersionNodesLiveActionFactory.class);

   public LiveAction createAction(Resource config) {

   ValueMap configs;

   /* Adapt the config resource to a ValueMap */

   if (config == null || config.adaptTo(ValueMap.class) == null) {

   configs = new ValueMapDecorator(Collections.<String, Object>emptyMap());

   } else {

   log.debug(config.getName());

   log.debug(config.getPath());

  configs = config.adaptTo(ValueMap.class);

   }

   return new VersionNodesLiveAction(actionname, configs);

   }

   public String createsAction() {

   return actionname;

   }

   @Activate

   public void activate(final Map<String, Object> config) throws RepositoryException {

   log.debug("VersionNodesLiveActionFactory: activate");

   }

   @Deactivate

   public void deactivate(final Map<String, String> config) throws RepositoryException {

   log.debug("VersionNodesLiveActionFactory: deactivate");

   }

   /************* LiveAction ****************/

   public static class VersionNodesLiveAction implements LiveAction {

   private static final Logger log = LoggerFactory.getLogger(VersionNodesLiveAction.class);

   private String name;

   private ValueMap configs;

   public VersionNodesLiveAction(String nm, ValueMap config) {

   name = nm;

   configs = config;

   }

   public void execute(Resource source, Resource target,

   LiveRelationship liverel, boolean autoSave, boolean isResetRollout)

   throws WCMException {

   log.debug("VersionNodesLiveAction: execute");

   if (source == null)

   log.debug(source.getName());

   if (source == null || !source.getName().endsWith("jcr:content")) {

   return;

   }

   if (source.adaptTo(Node.class) != null) {

   log.debug(source.getPath());

   VersionNodesByPath vnbp = SonovaUtils.getService(VersionNodesByPath.class);

  vnbp.autoVersion(source.getPath());

   }

  }

   public String getName() {

   return name;

   }

   /************* Deprecated *************/

   @Deprecated

   public void execute(ResourceResolver arg0, LiveRelationship arg1,

   ActionConfig arg2, boolean arg3) throws WCMException {

   log.debug("VersionNodesLiveAction: execute1");

   }

   @Deprecated

   public void execute(ResourceResolver arg0, LiveRelationship arg1,

   ActionConfig arg2, boolean arg3, boolean arg4)

   throws WCMException {

   log.debug("VersionNodesLiveAction: execute2");

   }

   @Deprecated

   public String getParameterName() {

   return null;

   }

   @Deprecated

   public String[] getPropertiesNames() {

   return null;

   }

   @Deprecated

   public int getRank() {

   return 0;

   }

   @Deprecated

   public String getTitle() {

   return null;

   }

   @Deprecated

   public void write(JSONWriter arg0) throws JSONException {

  }

   public void process(final String eventPath, final String type) {

   log.debug("VersionNodesLiveAction: process");

   }

  }

}

1 Accepted Solution

Avatar

Correct answer by
Level 6

Hi Alex,

We checked the AEM document you shared and we tried replicating the same functionality on our end and looks like the iteration not happening on child pages instead it is iterating the components listed within the parent page.

Instead try by invoking custom iteration on child pages to take versions. We understood its not ideal way but this can be alternate option for you.

We tired with existing VersionManager to take versions of pages .

VersionManager vm = session.getWorkspace().getVersionManager();   //Version manager using Session

  

   String parentPage = source.getPath().replace("/jcr:content", "");  //taking source path

  

   PageManager pageManager = resolver.adaptTo(PageManager.class);

   List<String>pageList = new ArrayList();

  

       pageList.add(parentPage);    //iterating Via Source path

    Page rootPage = pageManager.getPage(parentPage);

    Iterator<Page> rootPageIterator = rootPage.listChildren();

    while(rootPageIterator.hasNext())

    {

    Page childPage =    rootPageIterator.next();

    String path = childPage.getPath();

    vm.checkin(path);

    }

Not sure if this helps your need.

View solution in original post

3 Replies

Avatar

Level 10

Please point the community to the doc topic where you got this code to see if it can be reproduced.

Avatar

Correct answer by
Level 6

Hi Alex,

We checked the AEM document you shared and we tried replicating the same functionality on our end and looks like the iteration not happening on child pages instead it is iterating the components listed within the parent page.

Instead try by invoking custom iteration on child pages to take versions. We understood its not ideal way but this can be alternate option for you.

We tired with existing VersionManager to take versions of pages .

VersionManager vm = session.getWorkspace().getVersionManager();   //Version manager using Session

  

   String parentPage = source.getPath().replace("/jcr:content", "");  //taking source path

  

   PageManager pageManager = resolver.adaptTo(PageManager.class);

   List<String>pageList = new ArrayList();

  

       pageList.add(parentPage);    //iterating Via Source path

    Page rootPage = pageManager.getPage(parentPage);

    Iterator<Page> rootPageIterator = rootPage.listChildren();

    while(rootPageIterator.hasNext())

    {

    Page childPage =    rootPageIterator.next();

    String path = childPage.getPath();

    vm.checkin(path);

    }

Not sure if this helps your need.