Skip to main content

Workflows in AEM 03 - Dynamic Participant Step

A participant is a step which enables a user to assign ownership of a task to another user. The workflow will only go further if that user manually acknowledges the step.

A simple use case of this workflow is a review step, i.e. if you have made some changes in an AEM page and then you want someone to review it then you can add it to the participant step and that user will get a notification in his/her inbox. Obviously, the reviewer should have access to the page in question.

Dynamic Participant Step is similar to the Participant Step with the exception that the user is selected at run time. There might be a use case where you want an item to be assigned to a user who has the lowest number of items to review.

The business logic of a Dynamic Participant Step can be written in a class that implements the Participant Chooser interface.

Following is a code example that selects the participant from either "admin" or a user from the "administrators" group based on the condition if the workflow history is empty.

package org.redquark.demo.core.workflows;

import java.util.List;

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.HistoryItem;
import com.adobe.granite.workflow.exec.ParticipantStepChooser;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.Workflow;
import com.adobe.granite.workflow.metadata.MetaDataMap;

/**
 * @author Anirudh Sharma
 */
@Component(service = ParticipantStepChooser.class, property = { "chooser.label=" + "Dynamic Participant Step Example" })
public class DynamicParticipantStepExample implements ParticipantStepChooser {

 private final Logger log = LoggerFactory.getLogger(this.getClass());

 @Override
 public String getParticipant(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
   throws WorkflowException {
  log.info("----------< [{}] >----------", this.getClass().getName());

  String participant = "admin";

  Workflow workflow = workItem.getWorkflow();

  // Getting the workflow history
  List<HistoryItem> workflowHistory = workflowSession.getHistory(workflow);

  if (!workflowHistory.isEmpty()) {
   // Setting the administrators group to the participant
   participant = "administrators";
  } else {
   participant = "admin";
  }

  log.info("----------< Participant: {} >----------", participant);

  return participant;
 }

}

Please note that the property "chooser.label" is important as the value of this property determines by which name our step will be listed.

Configure the workflow

Workflow models
  • Create a model with the name and title
Create workflow model
  • Select the workflow model and edit it
Edit workflow model
  • Delete predefined "Step 1" and add a new participant step by clicking on "+" sign
Add Dynamic Participant Step
  • Edit the component by clicking on the "Spanner" icon and configure the same as below
Configure the dialog
  • Click on the "Sync" button to activate the workflow model.
  • Run the workflow on a page and click on "Next"
Run a workflow on payload
  • Once you complete the workflow, you will see a notification in the "admin" user's inbox. Open it. As soon as you click on "Complete", you will see a dialog opened that will ask for a "Comment" box. This is the manual acknowledgement that a user has to provide in a participant step.

Conclusion

In this post, we looked into creating a custom workflow dynamic participant step and how to configure it. You can find the code to this in my GitHub repository.

I hope you enjoyed this post. Your suggestions and feedback are always welcome. Feel free to befriend me on FacebookTwitter or Linked In or say Hi by email.

Comments

Popular posts from this blog

Day 05: Working with Sling Servlets in AEM

AEM Developer Series Day 00: AEM Developer Series Day 01: Introduction to AEM Day 02: AEM Architecture Day 03: Setting up AEM Development Environment Day 04: Developing First OSGi Bundle Day 05: Working with Sling Servlets in AEM Day 06: Playing with Sling Post Servlet Day 07: Creating your first component in AEM Day 08: Dueling with JavaScript Use API Day 09: Dueling with Java User API Day 10: Getting to know Sling Models Day 11: Client Libraries in Action Day 12: Creating your custom OSGi Configuration Day 13: Schedulers in AEM Day 14: Eventing in AEM Day 15: Custom Workflows in AEM Day 16: Creating JMX Beans in AEM Day 17: Working with QueryBuilder API Day 18: Working with Granite Datasources in AEM Day 19: Replication API in Action Day 20: Working with Users and Groups in AEM A Servlet is a class used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. For such applications, Servlet tec

Day 00: AEM Developer Series

image source:  https://solutionpartners.adobe.com/ Hello everyone! Welcome to this AEM development series. We can all see the revolution of Digital Marketing today. Companies are dying to be a part of it and they have made this a war for the Digital Marketing tools. Adobe is way ahead in this war and has gained a lot of market capture. They are leaders in the Digital Marketing platforms since 2014-15. One of the flagship product in Adobe's Digital Marketing suite is Adobe Experience Manager (AEM) . Since AEM is in huge demand, the people who know how to develop on AEM are also in huge demand. But developing on AEM is not easy as it is made up of various open-source technologies such as Apache Felix (OSGi), Apache Sling, Apache Oak and Adobe's own technologies like Granite, HTL etc. Learning all these technologies in conjunction can sometimes become confusing and frustrating 😫. When I first started learning AEM in 2016, I was dumbfounded to see there is

Day 12: Creating your Custom OSGi configuration

AEM Developer Series Day 00: AEM Developer Series Day 01: Introduction to AEM Day 02: AEM Architecture Day 03: Setting up AEM Development Environment Day 04: Developing First OSGi Bundle Day 05: Working with Sling Servlets in AEM Day 06: Playing with Sling Post Servlet Day 07: Creating your first component in AEM Day 08: Dueling with JavaScript Use API Day 09: Dueling with Java User API Day 10: Getting to know Sling Models Day 11: Client Libraries in Action Day 12: Creating your custom OSGi Configuration Day 13: Schedulers in AEM Day 14: Eventing in AEM Day 15: Custom Workflows in AEM Day 16: Creating JMX Beans in AEM Day 17: Working with QueryBuilder API Day 18: Working with Granite Datasources in AEM Day 19: Replication API in Action Day 20: Working with Users and Groups in AEM We all know that AEM works on Apache Felix  which is an implementation of OSGi . OSGi provides a way to manage bundles and configurations. We saw one example of an OSGi configurati