工作流的分支与聚合:
这是多个分支并行(同时)执行,并且所有的分支Execution都到Join活动聚合后才向后执行;
1.工作流图:test.png
工作流配置文件:test.jpdl.xml:
<?xml version="1.0" encoding="UTF-8"?> <process name="test" xmlns="http://jbpm.org/4.4/jpdl"> <start g="255,8,48,48" name="start1"> <transition g="-51,-13" name="to fork1" to="fork1"/> </start> <end g="260,354,48" name="end1"/> <fork g="258,95,48" name="fork1"> <transition g="-23,-20" name="to 发货" to="发货"/> <transition g="-12,-20" name="to 汇款" to="汇款"/> </fork> <task assignee="商家" g="88,111,92,52" name="发货"> <transition g="-44,-9" name="to 收货" to="收货"/> </task> <task assignee="客户" g="87,193,52" name="收货"> <transition g="-18,-23" name="to join1" to="join1"/> </task> <task assignee="客户" g="385,115,52" name="汇款"> <transition g="-70,-15" name="to 确认收货" to="确认收款"/> </task> <task assignee="商家" g="384,205,52" name="确认收款"> <transition g="-24,-21" name="to join1" to="join1"/> </task> <join g="260,257,48" name="join1"> <transition g="-50,-11" name="to end1" to="end1"/> </join> </process>
JAVA Code:
package cn.edu.zust.itee.joinFork; import java.io.InputStream; import java.util.List; import org.jbpm.api.Configuration; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance; import org.jbpm.api.task.Task; import org.junit.Test; /** * @author 郑勇 * 2013-7-11 13:50 * 分支聚合活动 * 这是多个分支并行(同时)执行,并且所有的分支Execution都到Join活动聚合后才向后执行; */ public class JoinFork { ProcessEngine processEngine= Configuration.getProcessEngine(); @Test public void testJoinForkActivity(){ //部署流程定义 //获得当前包中的文件 InputStream in = this.getClass().getResourceAsStream("test.jpdl.xml"); processEngine.getRepositoryService() .createDeployment() .addResourceFromInputStream("test.jpdl.xml",in) .deploy(); //启动流程实例 ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("test"); System.out.println("processIntenceId="+pi.getId()); System.out.println("当前正在执行的活动:"+pi.findActiveActivityNames()); //完成"发货"和"汇款"任务 List<Task> list = processEngine.getTaskService().createTaskQuery() //查询出该流程实例中分支任务 .processInstanceId(pi.getId()) .list(); for(Task task :list){ //活动按自己的分支执行 processEngine.getTaskService().completeTask(task.getId()); } } }