In this post, we will see how to implement a workflow using AEM. As the name suggests, a workflow represents a step-by-step process to accomplish a common task. For example, author creates the content. Then, the content goes to an editor for approval. After the approval, the content can be published. As usual, we will see a simple implementation.
(Get the code samples from my GitHub account.)
After executing the workflow, we will log the name of the page into the custom log. I know it’s so simple – but it will give you an idea of how executing a workflow can kick off a method in a bundle.
- Create a WorkflowImpl class in the com.aemcompany.myproject.impl package.
public class WorkflowImpl implements WorkflowProcess{ private Logger log = LoggerFactory.getLogger(this.getClass()); public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException { WorkflowData data = workItem.getWorkflowData(); String payload = (String)data.getPayload(); log.info(payload); } } - Implement WorkflowProcess interface.
- Implement WorkflowProcess interface.
- Use a WorkflowData object to get the workflow data.
- Get the payload from the workflow data.
- Write it to the log.
Now let us create a workflow using the AEM interface.
- Go to the workflow console:
- Select New.
- Enter the name.
- Double-click the newly created workflow.
- Drag and drop a process step
- Select AEM Workflow Process we created.
- Select Handler Advance. Selecting this advances the workflow to the next step automatically, without executing any additional steps.
- Select OK.
Let us execute the workflow.
- On the page we created, go to the Workflow tab.
- Select AEM Company and select Start Workflow.
- Select Step 1 and select Complete.
- Select OK.
- Open the log.
See the name of the page where it’s executed is added to the log. It was a small demo – hope it gave a basic idea of implementing workflow.
See you soon.
Leave a comment