MonkeyWrench
MonkeyWrench

Reputation: 1839

Trigger Activiti workflow for task sitting in ReceiveTask looping

I have an Activiti workflow that contains a ReceiveTask where I'm grouping tasks. I have a Listener that triggers on the event start of the ReceiveTask where I check the property of the newly added task to see if others with the same properties are in the ReceiveTask. If yes, then I want to trigger them all to move to the next step.

<receiveTask id="IssuePost" name="Issue Post">
  <extensionElements>
    <activiti:executionListener event="start" delegateExpression="${IssuePost}"></activiti:executionListener>
  </extensionElements>
</receiveTask>

My Java Listener class IssuePost gets called when the task moves to the ReceiveTask just fine. I can get the list of other tasks sitting in that ReceiveTask. I'm having a problem triggering the tasks to move to the next step in the workflow. I get caught in a loop when calling "signal" on the tasks. The IssuePost listener keeps on getting triggered in an infinite loop until Alfresco/Activiti gives up and throws an exception.

List<NodeRef> siblingNodes = searchService.selectNodes( parent, xpath, null, namespacePrefixResolver, false );
if( siblingNodes.size() == batchCount )
{
    for( int i=0; i < siblingNodes.size(); i++ )
    {
        List<WorkflowInstance> workflows = workflowService.getWorkflowsForContent( siblingNodes.get( i ), true );
        // this line causes the loop.
        workflowService.signal( workflows.get(0).getId(), null );

How can I signal the tasks in the ReceiveTask to move to the next step in the workflow without triggering my listener? There's only one flow out of the ReceiveTask to the next step in the workflow.

Upvotes: 0

Views: 3172

Answers (1)

Tahir Malik
Tahir Malik

Reputation: 6643

Looking at the InvitationServiceImpl I see the following useful snippet:

    List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(startTask.getPath().getId());
    if(tasks.size()==1)
    {
        WorkflowTask task = tasks.get(0);
        if(taskTypeMatches(task, taskTypes))
        {
            if(properties != null)
            {
                workflowService.updateTask(task.getId(), properties, null, null);
            }
            workflowService.endTask(task.getId(), transition);
            return;
        }
    }

So you need to have the task itself to update or end or even start.

Or maybe in your case, lookup the next transition which is after start and signal that one instead of null.

Upvotes: 1

Related Questions