Best Practices for Creating Custom Workflow Processes in Adobe Experience Manager (AEM)

Problem statement:

What is the recommended way to create a custom workflow process in AEM?

Requirement:

This article discusses the recommended approach to creating custom workflow processes in Adobe Experience Manager (AEM) for implementing business logic. The author outlines the steps for creating a custom workflow process, including creating a component service with WorkflowProcessclass and providing a process. label, and override the execute method. The article includes a code example to illustrate the process.

Create the custom Workflow Process to do some business logic

Introduction:

WorkflowProcess is the interface to be used for automatic workflow steps implemented in Java. Classes implementing this interface define Java based processes that can be attached to a WorkflowNode and executed by the workflow engine.

Create Component Service with WorkflowProcessclass and implement WorkflowProcess class

Provide process.label for all the custom workflow process

Override execute method

package com.mysite.core.workflows;

import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;

/**
 * This process tracks back the properties which are changed in the generated
 * deck and updates its respective properties in all the assets.
 */
@Component(service = WorkflowProcess.class, property = { "process.label=Dynamic Deck Dynamo Write Back Process" })
public class CustomWorkflowProcess implements WorkflowProcess {
	private static final Logger LOGGER = LoggerFactory.getLogger(CustomWorkflowProcess.class);

	@Override
	public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
			throws WorkflowException {
		ResourceResolver resourceResolver;
		resourceResolver = workflowSession.adaptTo(ResourceResolver.class);
	}
}

References:

https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/adobe/acs/commons/indesign/dynamicdeckdynamo/workflow/processes/impl/DynamicDeckBackTrackProcess.java

2 thoughts on “Best Practices for Creating Custom Workflow Processes in Adobe Experience Manager (AEM)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s