1

How do I launch a rollout process in AEM programmatically?

Thanks.

Diego Nieto
  • 357
  • 1
  • 5
  • 16

2 Answers2

4

Here is a code snippet that can be used for the rollout from the JSP level, same way you can do it in JAVA level.

<%@page import="com.day.cq.wcm.msm.api.RolloutManager"%>

<% Page rolloutthispage = pageManager.getPage("/content/geometrixx/en/toolbar"); //source page
RolloutManager.RolloutParams rolloutparams = new RolloutManager.RolloutParams();
rolloutparams.master = rolloutthispage; 
rolloutparams.isDeep = true;
//rolloutmanager is an OSGI service so using here sling.getService to have a reference
com.day.cq.wcm.msm.api.RolloutManager rolloutManager = sling.getService(com.day.cq.wcm.msm.api.RolloutManager.class);
rolloutManager.rollout(rolloutparams);
%>

To Test this code snippet

I have created a live copy from /content/geometrixx/en/ to /content/geometrixx/in Added/updated some text component data as shown below text rollout

Created a component just used for calling this jsp logic called the JSP logic from some other project page. once the jsp logic got called, The rollout got affected in the /content/geometrixx/in live copy. live copy text updated

Have a look at the below APIs to use more options RolloutManager,Trigger,RolloutParams

Hope it helps

VAr
  • 2,393
  • 1
  • 23
  • 37
  • Thanks dude, also work it out how to do it using the RolloutManager as you explain in your answer, I will put my code and answer too. – Diego Nieto Jan 20 '17 at 15:06
  • I would like to note that `rolloutManager.rollout(ResourceResolver resolver, LiveRelationship relation, boolean reset, boolean autoSave)` does not behave exactly like `rolloutManager(RolloutManager.RolloutParams params)` and the former should be avoided. – Michael Shopsin Feb 08 '18 at 21:36
1

After some research, I found how to launch a rollout programmatically:

In this specific case, I did it inside a workflow:

        @Reference
        private RolloutManager rolloutManager;
        @Reference
        private ResourceResolverFactory resourceResolverFactory;

        private Session session;
        private ResourceResolver resolver;
        private PageManager pageManager;

        public class MyWorkflow implements WorkflowProcess {
            @Override
            public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap dataMap) throws WorkflowException {
               //get the payload page from the workflow data
               WorkflowData workflowData = workItem.getWorkflowData();
               String payload = workflowData.getPayload().toString();

               final Map<String, Object> authInfo = new HashMap<String, Object>();
               authInfo.put(JcrResourceConstants.AUTHENTICATION_INFO_SESSION, workflowSession.getSession());
               resolver = resourceResolverFactory.getResourceResolver(authInfo);

               //Get Instance of PageManager
               pageManager = resolver.adaptTo(PageManager.class);
               final Page targetPage = pageManager.getPage(payload);

               final RolloutParams params = new RolloutParams();
               params.isDeep = false;
               params.master = targetPage;
               params.reset = false;
               params.trigger = RolloutManager.Trigger.ROLLOUT;
               params.delete = false;
               rolloutManager.rollout(params);

            }
        }

This works as expected, rolling out the page to the related live copies

Diego Nieto
  • 357
  • 1
  • 5
  • 16