代码:
package com.activiti.study.ExclusiveGateway;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;
public class ExclusiveGatewayTest {
/**
*加载默认的流程引擎: 加载 activiti.cfg.xml 文件
*/
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
/**
* 部署流程定义
*/
@Test
public void testDeployProcessDefination_inputStream(){
/**从当前包下进行加载*/
InputStream inputStreamBpmn = this.getClass().getResourceAsStream("ExclusiveGateway.bpmn");
InputStream inputStreamPng = this.getClass().getResourceAsStream("ExclusiveGateway.png");
Deployment deployment = processEngine.getRepositoryService()
.createDeployment()
.name("ExclusiveGateway") //设定流程名称
.addInputStream("ExclusiveGateway.bpmn", inputStreamBpmn)
.addInputStream("ExclusiveGateway.png", inputStreamPng)
.deploy();
System.out.println("Id: " + deployment.getId());
System.out.println("Name: " + deployment.getName());
System.out.println("Category: " + deployment.getCategory());
}
/**
* 启动流程
*/
@Test
public void testStartProcessDefination(){
String processDefinationKey = "ExclusiveGateway";
ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceByKey(processDefinationKey);
System.out.println("Id: " + pi.getId());
System.out.println("Key: " + pi.getBusinessKey());
System.out.println("ActivityId: " + pi.getActivityId());
System.out.println("DefinitionId: " + pi.getProcessDefinitionId());
System.out.println("ProcessInstanceId: " + pi.getProcessInstanceId());
}
/**
* 完成任务
*/
@Test
public void testCompleteTask_4000(){
String taskId = "3304";
Map<String,Object> map = new HashMap<String,Object>();
map.put("money", 4000);
processEngine.getTaskService().complete(taskId, map);
System.out.println(taskId + " has Done.");
}
/**
* 完成任务
*/
@Test
public void testCompleteTask_40000(){
String taskId = "2704";
Map<String,Object> map = new HashMap<String,Object>();
map.put("money", 40000);
processEngine.getTaskService().complete(taskId, map);
System.out.println("Done.");
}
/**
* 完成任务
*/
@Test
public void testCompleteTask_400000(){
String taskId = "3004";
Map<String,Object> map = new HashMap<String,Object>();
map.put("money", 400000);
processEngine.getTaskService().complete(taskId, map);
System.out.println(taskId + " has Done.");
}
}
部署逻流程图:
bpmn:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="ExclusiveGateway" name="Fee Reimbursement" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="Dept Manager Audit" activiti:assignee="BB1"></userTask>
<userTask id="usertask2" name="Accounting Audit" activiti:assignee="BB2"></userTask>
<userTask id="usertask3" name="CEO Audit" activiti:assignee="BB3"></userTask>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
<sequenceFlow id="flow2" name="Dept Audit" sourceRef="exclusivegateway1" targetRef="usertask1">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${money>=5000 && money <=100000}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow3" name="Accounting Audit" sourceRef="exclusivegateway1" targetRef="usertask2">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${money<5000}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow4" name="CEO Audit" sourceRef="exclusivegateway1" targetRef="usertask3">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${money>100000}]]></conditionExpression>
</sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow5" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow6" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow7" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
<userTask id="usertask4" name="Apply For a Reimbursement " activiti:assignee="AA"></userTask>
<sequenceFlow id="flow8" sourceRef="startevent1" targetRef="usertask4"></sequenceFlow>
<sequenceFlow id="flow9" sourceRef="usertask4" targetRef="exclusivegateway1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_ExclusiveGateway">
<bpmndi:BPMNPlane bpmnElement="ExclusiveGateway" id="BPMNPlane_ExclusiveGateway">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="518.0" y="10.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="171.0" x="180.0" y="320.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="58.0" width="201.0" x="435.0" y="320.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="201.0" x="730.0" y="320.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
<omgdc:Bounds height="40.0" width="40.0" x="515.0" y="170.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="61.0" width="71.0" x="500.0" y="500.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
<omgdc:Bounds height="61.0" width="191.0" x="440.0" y="90.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="535.0" y="210.0"></omgdi:waypoint>
<omgdi:waypoint x="265.0" y="320.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="13.0" width="100.0" x="381.0" y="259.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="535.0" y="210.0"></omgdi:waypoint>
<omgdi:waypoint x="535.0" y="320.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="13.0" width="100.0" x="506.0" y="249.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="535.0" y="210.0"></omgdi:waypoint>
<omgdi:waypoint x="830.0" y="320.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="13.0" width="100.0" x="610.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="265.0" y="375.0"></omgdi:waypoint>
<omgdi:waypoint x="535.0" y="500.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="535.0" y="378.0"></omgdi:waypoint>
<omgdi:waypoint x="535.0" y="500.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="830.0" y="375.0"></omgdi:waypoint>
<omgdi:waypoint x="535.0" y="500.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
<omgdi:waypoint x="535.0" y="45.0"></omgdi:waypoint>
<omgdi:waypoint x="535.0" y="90.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
<omgdi:waypoint x="535.0" y="151.0"></omgdi:waypoint>
<omgdi:waypoint x="535.0" y="170.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
结果: