AEM Page version Workflow
Hi, As part of the requirement we have written a workflow which will automatically create the page version as soon as page content is changed/edited. Now the versions are getting created but the issue is 1)Preview is not working 2) Compare version is not working....but revert to the previous version is working...I have created the launcher on modification of cq:page, and a custom process step with Below is the code :
Please provide any suggestions.. Thanks in advance
package com.aem.bd.core.workflows;
import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.WorkflowProcess;
import com.day.cq.workflow.metadata.MetaDataMap;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.version.VersionManager;
/**
* this workflow is used for creation of page versions automatically.
*/
@8220494(service = WorkflowProcess.class , immediate = true , enabled = true ,
property={
"process.label = Page Version Creation Process Step"
})
public class PageVersionProcessStep implements WorkflowProcess {
private static final Logger log = LoggerFactory.getLogger(PageVersionProcessStep.class);
@9944223
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
String payLoad = workItem.getWorkflowData().getPayload().toString();
VersionManager versionManager = null;
try {
if(payLoad.contains("/jcr:content")){
payLoad = payLoad.split("/jcr:content")[0];
}
payLoad = payLoad+"/jcr:content";
Node node = workflowSession.getSession().getNode(payLoad);
String[] string = {"mix:versionable"};
if(!node.hasProperty("jcr:mixinTypes")) {
node.setProperty("jcr:mixinTypes", "mix:versionable");
}
versionManager = workflowSession.getSession().getWorkspace().getVersionManager();
versionManager.checkpoint(payLoad);
log.debug("payload---------"+payLoad);
workflowSession.getSession().save();
boolean checkedOut = versionManager.isCheckedOut(payLoad);
log.debug("checkedOut---------"+String.valueOf(checkedOut));
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
}
