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.
*/
@component(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);
@Override
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);
}
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @ssrikar0811,
I see few issues with general concept:
I would suggest to automatically create version only during publication/approval process instead of doing it for each change - in my opinion having version for each change quickly became not manageable and will not bring any value to anyone (business, content authors or technical team).
Regarding page version creation on workflow level, I will first try to use OOTB CreateVersionProcess workflow process, instead of creating custom one.
If for any reason you have to do implementation on your own, you can try to use PageManager api, like this:
ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);
if (resourceResolver != null) {
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
if (pageManager != null) {
Page page = pageManager.getPage("path/to/page");
if (page != null) {
pageManager.createRevision(page, "Version title", "Version description");
}
}
}
Implementing such a step you should avoid setting properties/mixins like versionable by yourself - this should be done automatically by versioning api
As I understood, versions are getting created but the issue is with preview and comparing versions. can you please check logs and see if you can find any errors?
@ssrikar0811 Compair the node properties of the version which is working and to the one which is not working. I am expecting that some properties are missing in the node
Versions are stored by path '/jcr:system/jcr:versionStorage' in AEM.
Hi @ssrikar0811,
I see few issues with general concept:
I would suggest to automatically create version only during publication/approval process instead of doing it for each change - in my opinion having version for each change quickly became not manageable and will not bring any value to anyone (business, content authors or technical team).
Regarding page version creation on workflow level, I will first try to use OOTB CreateVersionProcess workflow process, instead of creating custom one.
If for any reason you have to do implementation on your own, you can try to use PageManager api, like this:
ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);
if (resourceResolver != null) {
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
if (pageManager != null) {
Page page = pageManager.getPage("path/to/page");
if (page != null) {
pageManager.createRevision(page, "Version title", "Version description");
}
}
}
Implementing such a step you should avoid setting properties/mixins like versionable by yourself - this should be done automatically by versioning api
Views
Likes
Replies