A-A+

Flowable6.4 – 排他网关

2019年12月22日 技术, 默认 暂无评论 阅读 1,586 次

一般情况下,通过开始事件、用户任务、网关、结束事件,就可以组成一个简单的顺序流。

在之前的文章中,开始事件、用户任务、结束事件都有过介绍,这次就来着重介绍一下网关中的排他网关。

顾名思义,排他网关只会选择一条顺序流,即当流程到达排他网关这个节点时,会按顺序(XML中定义的前后顺序)选择出口顺序流(sequenceFlow)计算其定义的条件,如果被计算的条件为True,则按照该出口顺序流向下执行。如果所有出口顺序流的条件都为False,则会抛出异常。

在流程设计器内,排他网关位于Gateways内,其英文名称为Exclusive gateway,如下图所示:

下面就以一个简单流程实验一下排他网关的用法,流程图如下:

由排他网关到达用户任务2的Flow condition设置为:

${assigneeUserId != "admin"}

由排他网关到达用户任务3的Flow condition设置为:

${assigneeUserId == "admin"}

启动流程时如下设置:

map.put("assigneeUserId""admin");
runtimeService.startProcessInstanceByKey(modelData.getKey(), "myTestFlow1", map);

整体的流程运行如下:

启动后
通过排他网关后

可以看到,由排他网关到达用户任务3的Flow condition为True,所以流程会自动流转至对应的节点。

如果新加入一个节点,如下图:

由排他网关到达用户任务4的Flow condition设置为:

${assigneeUserId == "admin"}

然后再启动流程,此时流程到达排他网关的流转规则会按照XML中的顺序流转,如下图所示:

实际运行时的结果也是如此:

如果将用户任务3和用户任务4的Flow condition设置为:

${assigneeUserId != "admin"}

此时,再次启动流程,并流转,将输出异常:

org.springframework.web.util.NestedServletException: Request processing failed; 
nested exception is org.flowable.common.engine.api.FlowableException: 
No outgoing sequence flow of the exclusive gateway 'sid-07951B0A-225A-440C-A8C9-60D7C00E962F' could be selected for continuing the process

大概的意思就是:

排他网关没有任何向外路径,流程无法流转。

以上,相继介绍了排他网关的用法、条件生效的顺序、全都不符合条件时所产生的异常。

可以点击”阅读原文“查看流程的XML文件,如有错误欢迎指出和讨论。

附件,流程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:xsd="http://www.w3.org/2001/XMLSchema" 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" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
  <process id="ExclusiveGatewayFlowTest" name="测试排他网关" isExecutable="true">
    <startEvent id="StartEvent" name="开始"></startEvent>
    <userTask id="UserTask1" name="处理"></userTask>
    <sequenceFlow id="sid-20EF43C5-7147-4275-9EB8-7E86639DCE0A" sourceRef="StartEvent" targetRef="UserTask1"></sequenceFlow>
    <exclusiveGateway id="sid-07951B0A-225A-440C-A8C9-60D7C00E962F"></exclusiveGateway>
    <sequenceFlow id="sid-43D498C5-E475-4C0B-8EF7-5144EADA2C14" sourceRef="UserTask1" targetRef="sid-07951B0A-225A-440C-A8C9-60D7C00E962F"></sequenceFlow>
    <userTask id="UserTask3" name="用户任务3"></userTask>
    <userTask id="UserTask2" name="用户任务2"></userTask>
    <endEvent id="EndEvent1" name="结束1"></endEvent>
    <sequenceFlow id="sid-03A9DF99-5757-4881-A490-0A4586751EA5" sourceRef="UserTask2" targetRef="EndEvent1"></sequenceFlow>
    <endEvent id="EndEvent2" name="结束2"></endEvent>
    <sequenceFlow id="sid-676620AA-77A8-4F19-8506-13D8C3EFF0C5" sourceRef="sid-07951B0A-225A-440C-A8C9-60D7C00E962F" targetRef="UserTask2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${assigneeUserId != "admin"}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="UserTask4" name="用户任务4"></userTask>
    <sequenceFlow id="sid-E588F005-EA80-4F0A-8C2C-0B1B7F614912" sourceRef="UserTask3" targetRef="EndEvent2"></sequenceFlow>
    <endEvent id="sid-05A5A92E-290B-423B-97C9-9EEB2112BF2D"></endEvent>
    <sequenceFlow id="sid-99C7170B-304F-4A86-8428-5BE5DDBE8073" sourceRef="UserTask4" targetRef="sid-05A5A92E-290B-423B-97C9-9EEB2112BF2D"></sequenceFlow>
    <sequenceFlow id="sid-EDA1F094-3B70-42E5-8E94-49A01480EF90" sourceRef="sid-07951B0A-225A-440C-A8C9-60D7C00E962F" targetRef="UserTask3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${assigneeUserId == "admin"}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-61511D8E-0C8E-4F03-BA4B-17531892C95D" sourceRef="sid-07951B0A-225A-440C-A8C9-60D7C00E962F" targetRef="UserTask4">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${assigneeUserId == "admin"}]]></conditionExpression>
    </sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_ExclusiveGatewayFlowTest">
    <bpmndi:BPMNPlane bpmnElement="ExclusiveGatewayFlowTest" id="BPMNPlane_ExclusiveGatewayFlowTest">
      <bpmndi:BPMNShape bpmnElement="StartEvent" id="BPMNShape_StartEvent">
        <omgdc:Bounds height="30.0" width="30.0" x="120.0" y="114.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="UserTask1" id="BPMNShape_UserTask1">
        <omgdc:Bounds height="80.0" width="100.0" x="195.0" y="89.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-07951B0A-225A-440C-A8C9-60D7C00E962F" id="BPMNShape_sid-07951B0A-225A-440C-A8C9-60D7C00E962F">
        <omgdc:Bounds height="40.0" width="40.0" x="330.0" y="109.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="UserTask3" id="BPMNShape_UserTask3">
        <omgdc:Bounds height="80.0" width="100.0" x="405.0" y="285.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="UserTask2" id="BPMNShape_UserTask2">
        <omgdc:Bounds height="80.0" width="100.0" x="405.0" y="30.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="EndEvent1" id="BPMNShape_EndEvent1">
        <omgdc:Bounds height="28.0" width="28.0" x="550.0" y="56.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="EndEvent2" id="BPMNShape_EndEvent2">
        <omgdc:Bounds height="28.0" width="28.0" x="550.0" y="311.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="UserTask4" id="BPMNShape_UserTask4">
        <omgdc:Bounds height="80.0" width="100.0" x="405.0" y="135.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-05A5A92E-290B-423B-97C9-9EEB2112BF2D" id="BPMNShape_sid-05A5A92E-290B-423B-97C9-9EEB2112BF2D">
        <omgdc:Bounds height="28.0" width="28.0" x="550.0" y="161.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-03A9DF99-5757-4881-A490-0A4586751EA5" id="BPMNEdge_sid-03A9DF99-5757-4881-A490-0A4586751EA5">
        <omgdi:waypoint x="504.9499999999792" y="70.0"></omgdi:waypoint>
        <omgdi:waypoint x="550.0" y="70.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-E588F005-EA80-4F0A-8C2C-0B1B7F614912" id="BPMNEdge_sid-E588F005-EA80-4F0A-8C2C-0B1B7F614912">
        <omgdi:waypoint x="504.95000000000005" y="325.0"></omgdi:waypoint>
        <omgdi:waypoint x="550.0" y="325.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-676620AA-77A8-4F19-8506-13D8C3EFF0C5" id="BPMNEdge_sid-676620AA-77A8-4F19-8506-13D8C3EFF0C5">
        <omgdi:waypoint x="350.5" y="109.5"></omgdi:waypoint>
        <omgdi:waypoint x="350.5" y="70.0"></omgdi:waypoint>
        <omgdi:waypoint x="405.0" y="70.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-61511D8E-0C8E-4F03-BA4B-17531892C95D" id="BPMNEdge_sid-61511D8E-0C8E-4F03-BA4B-17531892C95D">
        <omgdi:waypoint x="350.5" y="148.42922149122805"></omgdi:waypoint>
        <omgdi:waypoint x="350.5" y="175.0"></omgdi:waypoint>
        <omgdi:waypoint x="405.0" y="175.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-99C7170B-304F-4A86-8428-5BE5DDBE8073" id="BPMNEdge_sid-99C7170B-304F-4A86-8428-5BE5DDBE8073">
        <omgdi:waypoint x="504.94999999999595" y="175.0"></omgdi:waypoint>
        <omgdi:waypoint x="550.0" y="175.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-20EF43C5-7147-4275-9EB8-7E86639DCE0A" id="BPMNEdge_sid-20EF43C5-7147-4275-9EB8-7E86639DCE0A">
        <omgdi:waypoint x="149.9499984899576" y="129.0"></omgdi:waypoint>
        <omgdi:waypoint x="194.9999999999917" y="129.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-EDA1F094-3B70-42E5-8E94-49A01480EF90" id="BPMNEdge_sid-EDA1F094-3B70-42E5-8E94-49A01480EF90">
        <omgdi:waypoint x="350.5" y="148.44515593047032"></omgdi:waypoint>
        <omgdi:waypoint x="350.5" y="325.0"></omgdi:waypoint>
        <omgdi:waypoint x="405.0" y="325.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-43D498C5-E475-4C0B-8EF7-5144EADA2C14" id="BPMNEdge_sid-43D498C5-E475-4C0B-8EF7-5144EADA2C14">
        <omgdi:waypoint x="294.95000000000005" y="129.2367298578199"></omgdi:waypoint>
        <omgdi:waypoint x="330.4047619047619" y="129.40476190476193"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
觉的不错?可以关注我的公众号↑↑↑

给我留言

Copyright © 字痕随行 保留所有权利.   Theme  Ality 京ICP备14039894号

用户登录

分享到: