错误边界事件
- 错误边界事件
- 一、定义
- 1. 图形标记
- 2. 设置错误 选择错误
- 3. XML标记
- 二、测试用例
- 2.1 错误边界事件xml文件
- 2.2 错误边界事件测试用例
- 总结
错误边界事件
一、定义
接收到错误编码触发事件
1. 图形标记
2. 设置错误 选择错误
自动审批的配置类配置javaDelegate和抛出错误
@Slf4j
public class AutomaticReviewService implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
String healthCodeStatus = (String) execution.getVariable("healthCodeStatus");
if (!"green".equals(healthCodeStatus)) {
String errorCode = "HealthCodeNotGreen";
log.error("健康码异常,抛出BPMN错误,errorCode为:{}", errorCode);
throw new BpmnError(errorCode);
}
}
}
3. XML标记
错误边界事件的XML
<error id="theError" errorCode="HealthCodeNotGreen" />
<boundaryEvent id="Event_05k9xpe" attachedToRef="Activity_0ryoq61">
<errorEventDefinition errorRef="theError" flowable:errorVariableLocalScope="false" flowable:errorVariableTransient="false" />
</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">
<error id="theError" errorCode="HealthCodeNotGreen" />
<process id="ErrorBoundaryEventProcess" name="边界错误事件" isExecutable="true">
<startEvent id="a47952f60eef247ad8a93b4dd2697e697" />
<userTask id="a3b9626571c8542e0a45fc22f94da0ca7" name="提交材料">
<extensionElements>
<flowable:assigneeType>static</flowable:assigneeType>
<flowable:formData />
</extensionElements>
</userTask>
<sequenceFlow id="af7647390384a491d83379d143890cc62" sourceRef="a47952f60eef247ad8a93b4dd2697e697" targetRef="a3b9626571c8542e0a45fc22f94da0ca7" />
<sequenceFlow id="Flow_1tnf8jl" sourceRef="a3b9626571c8542e0a45fc22f94da0ca7" targetRef="Activity_0ryoq61" />
<endEvent id="Event_0rcxgdh" />
<sequenceFlow id="Flow_1c7i87w" sourceRef="Activity_0ryoq61" targetRef="Activity_0eqb1jn" />
<boundaryEvent id="Event_05k9xpe" attachedToRef="Activity_0ryoq61">
<errorEventDefinition errorRef="theError" flowable:errorVariableLocalScope="false" flowable:errorVariableTransient="false" />
</boundaryEvent>
<userTask id="Activity_1bji7w3" name="人工复审">
<extensionElements>
<flowable:formData />
<flowable:assigneeType>static</flowable:assigneeType>
</extensionElements>
</userTask>
<sequenceFlow id="Flow_101iy5v" sourceRef="Event_05k9xpe" targetRef="Activity_1bji7w3" />
<userTask id="Activity_0eqb1jn" name="结果登记">
<extensionElements>
<flowable:formData />
<flowable:assigneeType>static</flowable:assigneeType>
</extensionElements>
</userTask>
<sequenceFlow id="Flow_05cqugg" sourceRef="Activity_1bji7w3" targetRef="Activity_0eqb1jn" />
<sequenceFlow id="Flow_0bj9c6y" sourceRef="Activity_0eqb1jn" targetRef="Event_0rcxgdh" />
<serviceTask id="Activity_0ryoq61" name="自动审核" flowable:class="com.dragon.test.bpmn.delegate.AutomaticReviewService">
<extensionElements>
<flowable:formData />
<flowable:assigneeType>static</flowable:assigneeType>
</extensionElements>
</serviceTask>
</process>
2.2 错误边界事件测试用例
ProcessDefinition processDefinition = this.deployByModelKey("ErrorBoundaryEventProcess");
Map<String, Object> params = new HashMap<>();
params.put("healthCodeStatus", "red");
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId(), params);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
taskService.complete(task.getId());
task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
log.info("当前任务为:{}", task.getName());
总结
错误边界事件就没有什么中断与不中断,就只有中断
欢迎加入QQ群学习交流:582010059