Flowable边界事件-取消边界事件

取消边界事件

  • 取消边界事件
  • 一、定义
    • 1. 图形标记
    • 2. 配合取消结束事件使用
    • 3. XML标记
  • 二、测试用例
    • 2.1 取消边界事件xml文件
    • 2.2 取消边界事件测试用例
  • 总结


取消边界事件


一、定义

接收到取消命令触发事件

取消边界事情只能在事务子流程中使用,并配合取消结束事件触发

1. 图形标记

Flowable边界事件-取消边界事件_第1张图片

2. 配合取消结束事件使用

Flowable边界事件-取消边界事件_第2张图片

Flowable边界事件-取消边界事件_第3张图片

3. XML标记

错误边界事件的XML

<boundaryEvent id="Event_0lxd35r" attachedToRef="Activity_1vnyjkd">
      <cancelEventDefinition />
    boundaryEvent>

二、测试用例

2.1 取消边界事件xml文件


<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="errorFlag" errorCode="500" />
  <process id="ThransactionSubProcessTest" name="子流程-事务子流程" isExecutable="true">
    <startEvent id="a1bc9933739624c6694151aff2dce872b" />
    <userTask id="aa49686c18f1c48879976ba75a55fcbc6" name="用户提交订单">
      <extensionElements>
        <flowable:formData />
        <flowable:assigneeType>staticflowable:assigneeType>
      extensionElements>
    userTask>
    <sequenceFlow id="ab3c3111802e74e1c829879ce06ef62f1" sourceRef="a1bc9933739624c6694151aff2dce872b" targetRef="aa49686c18f1c48879976ba75a55fcbc6" />
    <transaction id="Activity_1vnyjkd" name="事务子流程">
      <startEvent id="Event_12nf6w8">
        <extensionElements>
          <flowable:formData />
        extensionElements>
      startEvent>
      <sequenceFlow id="Flow_1qdwcnq" sourceRef="Event_12nf6w8" targetRef="Gateway_1swfvxl" />
      <parallelGateway id="Gateway_1swfvxl" />
      <sequenceFlow id="Flow_17rtq7v" sourceRef="Gateway_1swfvxl" targetRef="Activity_1gw2yen" />
      <serviceTask id="Activity_1gw2yen" name="锁定库存" flowable:class="com.dragon.test.bpmn.delegate.TreasuryLockService">
        <extensionElements>
          <flowable:formData />
          <flowable:assigneeType>staticflowable:assigneeType>
        extensionElements>
      serviceTask>
      <userTask id="Activity_0s32nn4" name="用户取消订单">
        <extensionElements>
          <flowable:formData />
          <flowable:assigneeType>staticflowable:assigneeType>
        extensionElements>
      userTask>
      <sequenceFlow id="Flow_0x4x7li" sourceRef="Gateway_1swfvxl" targetRef="Activity_0s32nn4" />
      <userTask id="Activity_0k0ojol" name="用户支付订单">
        <extensionElements>
          <flowable:formData />
          <flowable:assigneeType>staticflowable:assigneeType>
        extensionElements>
      userTask>
      <sequenceFlow id="Flow_107046y" sourceRef="Activity_1gw2yen" targetRef="Activity_0k0ojol" />
      <sequenceFlow id="Flow_1yuazgn" sourceRef="Activity_0k0ojol" targetRef="Activity_0bi67sc" />
      <serviceTask id="Activity_0bi67sc" name="扣减库存" flowable:class="com.dragon.test.bpmn.delegate.TreasuryDeductService">
        <extensionElements>
          <flowable:assigneeType>staticflowable:assigneeType>
          <flowable:formData />
        extensionElements>
      serviceTask>
      <endEvent id="Event_167temk" />
      <sequenceFlow id="Flow_0pkp6lj" sourceRef="Activity_0bi67sc" targetRef="Event_167temk" />
      <sequenceFlow id="Flow_12q7c71" sourceRef="Activity_0s32nn4" targetRef="Event_1mt0jp2" />
      <endEvent id="Event_1mt0jp2">
        <cancelEventDefinition />
      endEvent>
      <boundaryEvent id="Event_1w62z13" attachedToRef="Activity_0bi67sc">
        <errorEventDefinition errorRef="errorFlag" flowable:errorVariableLocalScope="false" flowable:errorVariableTransient="false" />
      boundaryEvent>
      <sequenceFlow id="Flow_03od54n" sourceRef="Event_1w62z13" targetRef="Event_1mt0jp2" />
      <boundaryEvent id="Event_0fblty6" name="30分钟" attachedToRef="Activity_0k0ojol">
        <timerEventDefinition>
          <timeDuration>PT30MtimeDuration>
        timerEventDefinition>
      boundaryEvent>
      <sequenceFlow id="Flow_0hmzy4u" sourceRef="Event_0fblty6" targetRef="Event_1mt0jp2" />
      <boundaryEvent id="Event_0dzq6vl" attachedToRef="Activity_1gw2yen">
        <compensateEventDefinition />
      boundaryEvent>
      <serviceTask id="Activity_15oy2bt" name="释放库存" isForCompensation="true" flowable:class="com.dragon.test.bpmn.delegate.TreasuryReleaseService" />
      <boundaryEvent id="Event_0rv7u1v" attachedToRef="Activity_0k0ojol">
        <compensateEventDefinition />
      boundaryEvent>
      <serviceTask id="Activity_0gw5xlk" name="费用退回" isForCompensation="true" flowable:class="com.dragon.test.bpmn.delegate.RefundPaymentService" />
      <association id="Association_1a1b669" associationDirection="One" sourceRef="Event_0dzq6vl" targetRef="Activity_15oy2bt" />
      <association id="Association_0vig570" associationDirection="One" sourceRef="Event_0rv7u1v" targetRef="Activity_0gw5xlk" />
    transaction>
    <sequenceFlow id="Flow_0ynhbof" sourceRef="aa49686c18f1c48879976ba75a55fcbc6" targetRef="Activity_1vnyjkd" />
    <boundaryEvent id="Event_0lxd35r" attachedToRef="Activity_1vnyjkd">
      <cancelEventDefinition />
    boundaryEvent>
    <sequenceFlow id="Flow_0p83e5j" sourceRef="Event_0lxd35r" targetRef="Activity_0xmvtli" />
    <serviceTask id="Activity_0xmvtli" name="自动取消订单" flowable:class="com.dragon.test.bpmn.delegate.CancelOrderService">
      <extensionElements>
        <flowable:formData />
        <flowable:assigneeType>staticflowable:assigneeType>
      extensionElements>
    serviceTask>
    <endEvent id="Event_0h8me6c" />
    <sequenceFlow id="Flow_1vvt0is" sourceRef="Activity_0xmvtli" targetRef="Event_0h8me6c" />
    <endEvent id="Event_1954lc4" />
    <sequenceFlow id="Flow_0kcxljy" sourceRef="Activity_1vnyjkd" targetRef="Event_1954lc4" />
  process>

2.2 取消边界事件测试用例

 SimplePropertyPreFilter executionFilter = new SimplePropertyPreFilter(Execution.class,
                "id","parentId","businessKey","processInstanceId",
                "rootProcessInstanceId","scope","activityId");
        //部署流程
        ProcessDefinition processDefinition = deployByModelKey("ThransactionSubProcessTest");

        //设置主流程的流程变量
        Map variables1 = new HashMap<>();
        variables1.put("goodsNum", 100);
        variables1.put("orderCost", 1000);
        //发起流程
        ProcessInstance mainProcessInstance = runtimeService.startProcessInstanceById(processDefinition.getId(), variables1);
        //查询执行实例
        List<Execution> executionList1 = runtimeService.createExecutionQuery().processInstanceId(mainProcessInstance.getId()).list();
        log.info("主流程发起后,执行实例数为{},分别为:{}", executionList1.size(), JSON.toJSONString(executionList1, executionFilter));
        //查询主流程的流程变量
        Map mainProcessVariabes1 = runtimeService.getVariables(mainProcessInstance.getProcessInstanceId());
        log.info("主流程的流程变量为:{}", mainProcessVariabes1);
        //查询主流程第一个任务
        Task firstTaskOfMainProcess = taskService.createTaskQuery().processInstanceId(mainProcessInstance.getId()).singleResult();
        log.info("主流程发起后,流程当前所在用户任务为:{}", firstTaskOfMainProcess.getName());
        //完成主流程第一个任务
        log.info("办理用户任务:{},启动事务子流程", firstTaskOfMainProcess.getName());
        taskService.complete(firstTaskOfMainProcess.getId());
        //查询执行实例
        List<Execution> executionList2 = runtimeService.createExecutionQuery().processInstanceId(mainProcessInstance.getId()).list();
        log.info("子流程发起后,执行实例数为{},分别为:{}", executionList2.size(), JSON.toJSONString(executionList2, executionFilter));
        //查询子流程第一个任务
        Task firstTaskOfSubProcess = taskService.createTaskQuery().taskName("用户支付订单").processInstanceId(mainProcessInstance.getId()).includeProcessVariables().singleResult();
        log.info("子流程发起后,流程当前所在用户任务为:{}", firstTaskOfSubProcess.getName());
        //查询子流程的流程变量
        Map subProcessVariabes1 = firstTaskOfSubProcess.getProcessVariables();
        log.info("子流程的流程变量为:{}", subProcessVariabes1);
        log.info("办理用户任务:{}", firstTaskOfSubProcess.getName());
        //完成子流程第一个任务,后续到达服务节点
        taskService.complete(firstTaskOfSubProcess.getId());
        //查询执行实例
        List<Execution> executionList4 = runtimeService.createExecutionQuery().processInstanceId(mainProcessInstance.getId()).list();
        log.info("主流程结束后,执行实例数为{},执行实例信息为:{}", executionList4.size(), JSON.toJSONString(executionList4, executionFilter));

总结

取消边界事件只能在事务子流程中使用,并配合取消结束事件触发。

欢迎加入QQ群学习交流:582010059

你可能感兴趣的:(Flowable组件库,flowable,工作流引擎,bpmnjs)