May 13, 2020
Estimated Post Reading Time ~

Dynamic Participant Step

In this blog, I will discuss about Dynamic Participant Step:

1. What is the use of Dynamic Participant Step?
2. How can we write Custom Dynamic Participant Step?
3.How can we use Dynamic Participant Step?

Use of Dynamic participant step:

Workflow Dynamic Participant Step is used when the user or a group to perform an activity in that step is selected automatically at run time based on some business logic unlike the user or a group are pre-selected. When we select the dynamic participant step in the workflow, we need to select the respective participant user from the drop down. There are many script/service available out of the box to select from or we can write our own participant chooser service as well which will be discussed further in this post.

Custom Dynamic Participant Step:

For creating the Custom Dynamic Participant Step we have to implement ParticipantStepChooser in our java class which provide us getParticipant method with three parameter Workitem, WorkflowSession and MetaDataMap.

Register this java class as a component and add some properties as enabled, immediate, these property indicates-
That this service will be enabled immediate at the time of deployment of your project.

Now register your class as a service with some configurations-
i.e. add a property named as “chooser.label”. This property defines a name of your process i.e. in workflow participant chooser step, you are able to see this process in your participant chooser drag drop menu with a name define using this property.

Our final code will look like this:

package com.havells.services;

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;

import java.util.List;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(immediate=true)
@Service
@Properties({@org.apache.felix.scr.annotations.Property(name=”service.description”, value={“Sample Implementation of dynamic participant chooser.”}),
@org.apache.felix.scr.annotations.Property(name=”chooser.label”, value={“Workflow Participant Chooser”})
})
public class CustomStepForDynamicParticipant
implements ParticipantStepChooser
{
private static final Logger logger = LoggerFactory.getLogger(CustomStepForDynamicParticipant.class);

public String getParticipant(WorkItem workitem, WorkflowSession wfSession, MetaDataMap metaDataMap)
throws WorkflowException
{
logger.info(“################ Inside the SampleProcessStepChooserImpl GetParticipant ##########################”);
String participant = “admin”;
Workflow workflow = workitem.getWorkflow();
String initiator = workflow.getInitiator();
List<HistoryItem> wfHistory = wfSession.getHistory(workflow);
if (!wfHistory.isEmpty()) {
participant = initiator;
} else {
participant = “admin”;
}
logger.info(“####### Participant : ” + participant + ” ##############”);
return participant;
}
}

Source: 
https://lhotsetechnologies.com/blog/dynamic-participant-step/


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.