Reputation: 721
How do I launch a rollout process in AEM programmatically?
Thanks.
Upvotes: 1
Views: 2336
Reputation: 721
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
Upvotes: 1
Reputation: 2601
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
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.
Have a look at the below APIs to use more options RolloutManager,Trigger,RolloutParams
Hope it helps
Upvotes: 4