Activiti application of multiple concurrent sub-processes

Source: Internet
Author: User

A number of departments to initiate funding plans, and finally unified to the finance Department for approval, each department initiated funds plan is a sub-process, finance department approval is a number of departments of the plan and approval, after the completion of approval, and then submitted to the senior leadership approval.

The process is as follows:

To solve the above problems, we need to implement the function of multi-sub-process parallel processing. In Activiti5, there is a relatively strong node attribute is multi-instance, it can support multi-instance sub-process, multi-instance task, multi-entity script and so on. The types of nodes that currently support multiple instances are:

    • User Task

    • Script Task

    • Java service Task

    • Web service Task

    • Business Rule Task

    • Email Task

    • Manual Task

    • Receive Task

    • (embedded) subprocess

    • Call activity

Multiple instances also have parallel, serial differentiation. The following explains what is parallel and serial

Parallel representatives, such as the task assigned to 5 people to deal with, these 5 people will receive the task at the same time, and can be processed at the same time, not affected by their own.

Serial represents the work or task that is done by one person, then by another person, until it is complete, and each task relies on the previous task to complete.

The sign-up task can be implemented by the Activiti multi-instance task node (the previous blog has a description of how to develop a design-signing task)

In the definition of Activiti, it is very simple to generate a multi-instance definition, just like this to generate the following tags, you can complete the declaration of multiple instances, as shown below, we want to support the definition of multiple instances of a parallel node

Multi-Instance human tasks

Java code
  1. "${assignee}" id= " SignTask2" name= "financial supervisor" >
  2. Class="Com.hotent.platform.service.bpm.listener.TaskSignCreateListener"
  3. event="Create" />
  4. Class="Com.hotent.platform.service.bpm.listener.TaskAssignListener"
  5. event="Assignment" />
  6. Class="Com.hotent.platform.service.bpm.listener.TaskCompleteListener"
  7. event="complete" />
  8. activiti:elementvariable="Assignee" issequential="false"
  9. activiti:collection="${taskuserassignservice.getsignuser (Execution)}">
  10. ${signcomplete.iscomplete (Execution)}

Multi-real example process

Java code
  1. "${assignee}" id= "SubProcess1"
  2. Name="Departmental Fund planning Process">
  3. "Startuser" id="StartEvent2 "
  4. Name="Start" />
  5. "EndEvent1" Name="End 1" />
  6. "Task3" name= "Assistant fill in">
  7. Class="Com.hotent.platform.service.bpm.listener.TaskCreateListener"
  8. event="Create" />
  9. Class="Com.hotent.platform.service.bpm.listener.TaskAssignListener"
  10. event="Assignment" />
  11. Class="Com.hotent.platform.service.bpm.listener.TaskCompleteListener"
  12. event="complete" />
  13. "Task4" name= "Department Leadership Review">
  14. Class="Com.hotent.platform.service.bpm.listener.TaskCreateListener"
  15. event="Create" />
  16. Class="Com.hotent.platform.service.bpm.listener.TaskAssignListener"
  17. event="Assignment" />
  18. Class="Com.hotent.platform.service.bpm.listener.TaskCompleteListener"
  19. event="complete" />
  20. "StartEvent2" targetref="Task3 "
  21. Id= "sequenceFlow1" name= "" />
  22. "Task3" targetref="Task4" id="SequenceFlow2 "
  23. Name="" />
  24. "Task4" targetref="endEvent1" id="sequenceFlow3 "
  25. Name="" />
  26. "Start"
  27. Class="Com.hotent.platform.service.bpm.listener.StartEventListener" />
  28. "End"
  29. Class="Com.hotent.platform.service.bpm.listener.EndEventListener" />
  30. activiti:elementvariable="Assignee" issequential="false"
  31. activiti:collection="${taskuserassignservice.getmultipleuser (Execution)}" />

So the key configuration properties are:

Java code
    1. activiti:elementvariable="Assignee" issequential="false"
    2. activiti:collection="${taskuserassignservice.getsignuser (Execution)}">
    3. ${signcomplete.iscomplete (Execution)}

When we control the number or number of multiple instances, we get or getmultipleuser (execution) the number of their collections through Taskuserassignservice getsignuser, which determines how many entity tasks or sub-processes are produced.

If the number of instances of the sub-process is achieved, the acquisition is from:

Java code
  1. /**
  2. * Get a collection of execution users for multi-entity sub-processes
  3. * @param execution
  4. * @return
  5. * @throws execption
  6. */
  7. Public List Getmultipleuser (activityexecution execution) throws exception{
  8. String nodeid=execution.getactivity (). GetId ();
  9. Executionentity executionent= (executionentity) execution;
  10. List userids= (list) execution.getvariable (bpmconst.subpro_multi_userids);
  11. If(userids!=null) return UserIDs;
  12. Map <string,flownode> nodemap= Nodecache.getbyactdefid (Executionent.getprocessdefinitionid ());
  13. Flownode Subprocessnode=nodemap.get (nodeId);
  14. Flownode Firstnode=subprocessnode.getsubfirstnode ();
  15. Flownode secodenode=firstnode.getnextflownodes (). Get (0);
  16. List userlist=nodeusermaplocal.get (). Get (Secodenode.getnodeid ());
  17. Logger.debug ("userlist size:" + userlist.size ());
  18. Execution.setvariable (Bpmconst.subpro_multi_userids, userlist);
  19. return userlist;
  20. }

Because the method will be called multiple times, the idea of its implementation is the first time its collection is a list of people from the user's interface selection, after the first time, put in the process variables, and in subsequent fetches, directly from the process variables.

Then, in the listener that created the task, get the performer of the current task from the process variable assignee. One of the details of the above implementation is to resolve how to find the first task node in the sub-process and delegate the corresponding task personnel to the task node.

The effect of the final implementation is as follows:

Activiti application of multiple concurrent sub-processes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.