信号边界事件
- 信号边界事件
- 一、定义
- 1. 图形标记
- 2. 设置信号 选择信号
- 3. XML标记
- 二、测试用例
- 2.1 定时边界事件xml文件
- 2.2 信号边界事件测试用例
- 总结
信号边界事件
一、定义
接收到信号触发事件
1. 图形标记
2. 设置信号 选择信号
3. XML标记
定时边界事件的XML
<signal id="changeContract" name="修改合同" flowable:scope="global" />
<boundaryEvent id="Event_04efcjz" attachedToRef="Activity_1fdbk68">
<signalEventDefinition signalRef="changeContract" />
</boundaryEvent>
二、测试用例
2.1 定时边界事件xml文件
<?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:flowable="http://flowable.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" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://flowable.org/bpmn">
<signal id="changeContract" name="修改合同" flowable:scope="global" />
<process id="SignalBoundaryInterrputingEventProcess" name="边界信号事件" isExecutable="true">
<startEvent id="a9a91088078f04a7ab2e96cd76001227a">
<extensionElements>
<flowable:formData />
</extensionElements>
</startEvent>
<userTask id="a67f45b30d9ee4a4fa51a59f03b557650" name="起草合同">
<extensionElements>
<flowable:formData />
<flowable:assigneeType>static</flowable:assigneeType>
</extensionElements>
</userTask>
<sequenceFlow id="a8568bad6406b4e08bde552e2b97f5cf0" sourceRef="a9a91088078f04a7ab2e96cd76001227a" targetRef="a67f45b30d9ee4a4fa51a59f03b557650" />
<userTask id="Activity_1fdbk68" name="确认合同">
<extensionElements>
<flowable:assigneeType>static</flowable:assigneeType>
<flowable:formData />
</extensionElements>
</userTask>
<sequenceFlow id="Flow_1heyjxs" sourceRef="a67f45b30d9ee4a4fa51a59f03b557650" targetRef="Activity_1fdbk68" />
<userTask id="Activity_0ju7xew" name="签署合同">
<extensionElements>
<flowable:formData />
<flowable:assigneeType>static</flowable:assigneeType>
</extensionElements>
</userTask>
<sequenceFlow id="Flow_0ljet4w" sourceRef="Activity_1fdbk68" targetRef="Activity_0ju7xew" />
<endEvent id="Event_14ronxp" />
<sequenceFlow id="Flow_15mmbl5" sourceRef="Activity_0ju7xew" targetRef="Event_14ronxp" />
<boundaryEvent id="Event_04efcjz" attachedToRef="Activity_1fdbk68">
<signalEventDefinition signalRef="changeContract" />
</boundaryEvent>
<userTask id="Activity_18a64dk" name="修改合同">
<extensionElements>
<flowable:formData />
<flowable:assigneeType>static</flowable:assigneeType>
</extensionElements>
</userTask>
<sequenceFlow id="Flow_1jojj00" sourceRef="Event_04efcjz" targetRef="Activity_18a64dk" />
<sequenceFlow id="Flow_11xl82a" sourceRef="Activity_18a64dk" targetRef="a67f45b30d9ee4a4fa51a59f03b557650" />
</process>
2.2 信号边界事件测试用例
ProcessDefinition processDefinition = this.deployByModelKey("SignalBoundaryInterrputingEventProcess");
//启动两个流程实例
ProcessInstance processInstance1 = runtimeService.startProcessInstanceById(processDefinition.getId());
log.info("第1个流程实例的编号为:{}", processInstance1.getId());
ProcessInstance processInstance2 = runtimeService.startProcessInstanceById(processDefinition.getId());
log.info("第2个流程实例的编号为:{}", processInstance2.getId());
//将实例一进行到确认合同
Task processInstance1Task = taskService.createTaskQuery().processInstanceId(processInstance1.getId()).singleResult();
taskService.complete(processInstance1Task.getId());
processInstance1Task = taskService.createTaskQuery().processInstanceId(processInstance1.getId()).singleResult();
log.info("第1个流程实例当前所在用户任务为:{}", processInstance1Task.getName());
//将实例二进行到确认合同
Task processInstance2Task = taskService.createTaskQuery().processInstanceId(processInstance2.getId()).singleResult();
taskService.complete(processInstance2Task.getId());
processInstance2Task = taskService.createTaskQuery().processInstanceId(processInstance2.getId()).singleResult();
log.info("第2个流程实例当前所在用户任务为:{}", processInstance2Task.getName());
//发送合同变更信号
runtimeService.signalEventReceived("修改合同");
log.info("发送合同变更信号完成");
//根据流程定义查询任务
List<Task> tasks = taskService.createTaskQuery().processDefinitionId(processDefinition.getId()).list();
for (Task task : tasks) {
log.info("编号为{}的流程实例当前所在用户任务为:{}", task.getProcessInstanceId(), task.getName());
}
总结
信号边界事件分全局的和局部的 属性设置为flowable:scope="global"为全局的,默认不写也是全局的;flowable:scope="processInstance"为当前流程实例有效,这个不是bpmn2.0规范,是flowable的规范,但是非常有用
欢迎加入QQ群学习交流:582010059