Trigger Activiti workflow for task sitting in ReceiveTask looping

元气小坏坏 提交于 2019-12-12 03:46:25

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/15640480/trigger-activiti-workflow-for-task-sitting-in-receivetask-looping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!