CQ5 Workflow Tutorial Part – III
- Creating custom process Step.
- How to use this custom process Step.
- Explanation of all arguments in Workflow Process Interface execute() method.
- Use of all these arguments.
For creating a custom process step you have to implement WorkflowProcess interface in your java class. It provide a method named as execute() with three parameters, I will explain you all of these parameters.
That your service will be enabled immediately at the time of deployment of your project.
Now register your class as a service with some configurations –
import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowProcess;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate = true, enabled = true, metatype = false)
@Service
@Properties({
@Property(name = “service.description”, value = “Service for Showing custom workflow demo.”),
@Property(name = “service.vendor”, value = “versatileankur@blogspot.in”),
@Property(name = “process.label”, value = “Blog Process”)
})
public class CustomProcess implements WorkflowProcess {
private static final Logger LOGGER = LoggerFactory.getLogger(CustomProcess.class);
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
LOGGER.info(“nnnn==== Custom workflow Creation completed successfully. n thanks for creation”);
}
}
Explanation of method arguments.
workItem
- workItem represent the workItem corresponding to current step, it will be present till this step is running and not present in any other process or participant step. Using this workItem object you are able to access workflow instance or metaDataMap related to only this workItem.
- you can also access workflow metaDataMap using workItem object using workItem.getWorkflow().getMetaDataMap() method it will return metaDataMap related to whole workflow model.
- If you use workItem.getMetaDataMap() then it will return only that metaDataMap object which is related to this step only and not present in any other workflow step.
- You are also able to get payload of this workflow using getWorkflowData() method of workItem.
- You can explore this API from this link- WorkflowData.
workflowSession
- workflowSession represent the session related to whole workflow, using this Object you can deal with all node using history node of workflow instance. You can explore this interface using given link WorkflowSession.
metaDataMap
- this metaDataMap object is related to dialog properties which you select in process dialog. It provides you only those properties which are under process tab i.e. this will provide you information about –
- what process you selected?
- Either you select Handle Advance checkbox or not?
- & also provide you list of arguments.
These there properties comes under three different property names as PROCESS, PROCESS_AUTO_ADVANCE, PROCESS_ARG.
PROCESS_ARG is of type String i.e. what ever you write in Argument text area it will be accessed as a single string & you can provide your custom logic to parse that string.
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
LOGGER.info(“nnnn===== Custom workflow Creation completed successfully. n thanks for creation”);
LOGGER.info(“nnnn===============”+metaDataMap.get(“PROCESS_ARGS”, new String()));
LOGGER.info(“nnnn===============”+metaDataMap);
}
Now go to your geometrixx/en.html page and go to workflow tab-> select blog workflow – > click on start workflow button. Go to crx-quickstart/logs/error.log
github repository link
https://github.com/vietankur009/blog
Happy Coding
Namah Shivay
Recent Comments