I wanted to share the following TaskListener that I've used to handle the following situation:
A task is normally given some set of users as candidate users, but in some cases there is only one user in the candidate set.
In this case I'd like the one candidate user to automatically be the assignee of the task, so they don't have to claim it.
Following is the java code to accomplish this using a TaskListener.
/**
* Listener that automatically assigns a task if there is only one candidate.
*/
public class AutoAssigningTaskListener implements TaskListener
{
@Override
public void notify(DelegateTask t)
{
if(t.getAssignee() == null && t.getCandidates().size() == 1)
{
t.setAssignee(t.getCandidates().stream().filter(id-> id.getUserId() != null).findFirst().map(id -> id.getUserId()).orElse(null));
}
}
}
Feel free to indicate if there is a more preferred way to handle this situation. Otherwise, I hope this is of use to someone.