Flowable:BpmnModel API

发布时间:2024年01月15日

之前都是使用工具在绘制流程图,但是还是很少去认真的去看这个xml,有时候我们要从xml中分析获取一些结果,这个时候就要对xml及对应的api有足够的认识。

一:重新认识bpmn

在这里插入图片描述

  • definitions:根节点用于定义流程。
    • bpmndi:BPMNDiagram:绘制流程图,主要用于描述控件的id、坐标(x, y)、尺寸(width, height)等,这个节点不用关注。
    • process:定义流程,常用的属性id、name等,里面放bpmn支持的各种FlowElement流元素、流节点FlowNode。org.flowable.bpmn.model.Process
      • startEvent:开始事件,常用的属性id、name、initiatorformKey
      • userTask:用户任务,常用的属性id、name、assigneeformKey
      • parallelGateway:并行网关
      • endEvent:结束事件
      • sequenceFlow:序列流(线),常用的属性 id、sourceReftargetRef
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" 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" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1705288913012" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
  <process id="VacationProcess" isClosed="false" isExecutable="true" name="请假流程" processType="None">
    <startEvent activiti:initiator="starter" id="mainStart" name="StartEvent"/>
    <userTask activiti:assignee="${starter}" activiti:exclusive="true" id="submitApply" name="提交申请"/>
    <userTask activiti:exclusive="true" id="vgm" name="副经理审批"/>
    <parallelGateway gatewayDirection="Unspecified" id="forkParallelGateway" name="ParallelGateway"/>
    <userTask activiti:exclusive="true" id="gm" name="总经理审批"/>
    <userTask activiti:exclusive="true" id="hr" name="人事审批"/>
    <parallelGateway gatewayDirection="Unspecified" id="joinParallelGateway" name="ParallelGateway"/>
    <userTask activiti:exclusive="true" id="notifyResult" name="结果通知"/>
    <endEvent id="mainEnd" name="EndEvent"/>
    
    <sequenceFlow id="_8" sourceRef="mainStart" targetRef="submitApply"/>
    <sequenceFlow id="_9" sourceRef="submitApply" targetRef="vgm"/>
    <sequenceFlow id="_10" sourceRef="vgm" targetRef="forkParallelGateway"/>
    <sequenceFlow id="_11" sourceRef="forkParallelGateway" targetRef="gm"/>
    <sequenceFlow id="_12" sourceRef="forkParallelGateway" targetRef="hr"/>
    <sequenceFlow id="_13" sourceRef="gm" targetRef="joinParallelGateway"/>
    <sequenceFlow id="_14" sourceRef="hr" targetRef="joinParallelGateway"/>
    <sequenceFlow id="_16" sourceRef="joinParallelGateway" targetRef="notifyResult"/>
    <sequenceFlow id="_18" sourceRef="notifyResult" targetRef="mainEnd"/>
  </process>


  <bpmndi:BPMNDiagram documentation="background=#3C3F41;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
    <bpmndi:BPMNPlane bpmnElement="VacationProcess">
      <bpmndi:BPMNShape bpmnElement="mainStart" id="Shape-mainStart">
        <omgdc:Bounds height="32.0" width="32.0" x="5.0" y="120.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="submitApply" id="Shape-submitApply">
        <omgdc:Bounds height="55.0" width="85.0" x="100.0" y="110.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="vgm" id="Shape-vgm">
        <omgdc:Bounds height="55.0" width="85.0" x="275.0" y="110.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="forkParallelGateway" id="Shape-forkParallelGateway">
        <omgdc:Bounds height="32.0" width="32.0" x="425.0" y="120.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="gm" id="Shape-gm">
        <omgdc:Bounds height="55.0" width="85.0" x="570.0" y="60.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="hr" id="Shape-hr">
        <omgdc:Bounds height="55.0" width="85.0" x="575.0" y="180.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="joinParallelGateway" id="Shape-joinParallelGateway">
        <omgdc:Bounds height="32.0" width="32.0" x="775.0" y="130.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="notifyResult" id="Shape-notifyResult">
        <omgdc:Bounds height="55.0" width="85.0" x="875.0" y="120.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="mainEnd" id="Shape-mainEnd">
        <omgdc:Bounds height="32.0" width="32.0" x="1035.0" y="130.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13" sourceElement="_6" targetElement="_3">
        <omgdi:waypoint x="655.0" y="87.5"/>
        <omgdi:waypoint x="775.0" y="146.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12" sourceElement="ParallelGateway" targetElement="_7">
        <omgdi:waypoint x="457.0" y="136.0"/>
        <omgdi:waypoint x="575.0" y="207.5"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_14" id="BPMNEdge__14" sourceElement="_7" targetElement="_3">
        <omgdi:waypoint x="660.0" y="207.5"/>
        <omgdi:waypoint x="775.0" y="146.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_16" id="BPMNEdge__16" sourceElement="_3" targetElement="_15">
        <omgdi:waypoint x="807.0" y="146.0"/>
        <omgdi:waypoint x="875.0" y="147.5"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_18" id="BPMNEdge__18" sourceElement="_15" targetElement="_17">
        <omgdi:waypoint x="960.0" y="147.5"/>
        <omgdi:waypoint x="1035.0" y="146.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_8" id="BPMNEdge__8" sourceElement="_2" targetElement="submitApply">
        <omgdi:waypoint x="37.0" y="136.0"/>
        <omgdi:waypoint x="100.0" y="137.5"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_9" id="BPMNEdge__9" sourceElement="submitApply" targetElement="_4">
        <omgdi:waypoint x="185.0" y="137.5"/>
        <omgdi:waypoint x="275.0" y="137.5"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_11" id="BPMNEdge__11" sourceElement="ParallelGateway" targetElement="_6">
        <omgdi:waypoint x="457.0" y="136.0"/>
        <omgdi:waypoint x="570.0" y="87.5"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10" sourceElement="_4" targetElement="ParallelGateway">
        <omgdi:waypoint x="360.0" y="137.5"/>
        <omgdi:waypoint x="425.0" y="136.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

二:API

2.1 xml与BpmnModel互相转换

String bpmnXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
        "<definitions xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\" 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\" xmlns:tns=\"http://www.activiti.org/test\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" expressionLanguage=\"http://www.w3.org/1999/XPath\" id=\"m1705288913012\" name=\"\" targetNamespace=\"http://www.activiti.org/test\" typeLanguage=\"http://www.w3.org/2001/XMLSchema\">\n" +
        "  <process id=\"VacationProcess\" isClosed=\"false\" isExecutable=\"true\" name=\"请假流程\" processType=\"None\">\n" +
        "    <startEvent activiti:initiator=\"starter\" id=\"mainStart\" name=\"StartEvent\"/>\n" +
        "    <userTask activiti:assignee=\"${starter}\" activiti:exclusive=\"true\" id=\"submitApply\" name=\"提交申请\"/>\n" +
        "    <userTask activiti:exclusive=\"true\" id=\"vgm\" name=\"副经理审批\"/>\n" +
        "    <parallelGateway gatewayDirection=\"Unspecified\" id=\"forkParallelGateway\" name=\"ParallelGateway\"/>\n" +
        "    <userTask activiti:exclusive=\"true\" id=\"gm\" name=\"总经理审批\"/>\n" +
        "    <userTask activiti:exclusive=\"true\" id=\"hr\" name=\"人事审批\"/>\n" +
        "    <parallelGateway gatewayDirection=\"Unspecified\" id=\"joinParallelGateway\" name=\"ParallelGateway\"/>\n" +
        "    <userTask activiti:exclusive=\"true\" id=\"notifyResult\" name=\"结果通知\"/>\n" +
        "    <endEvent id=\"mainEnd\" name=\"EndEvent\"/>\n" +
        "    \n" +
        "    <sequenceFlow id=\"_8\" sourceRef=\"mainStart\" targetRef=\"submitApply\"/>\n" +
        "    <sequenceFlow id=\"_9\" sourceRef=\"submitApply\" targetRef=\"vgm\"/>\n" +
        "    <sequenceFlow id=\"_10\" sourceRef=\"vgm\" targetRef=\"forkParallelGateway\"/>\n" +
        "    <sequenceFlow id=\"_11\" sourceRef=\"forkParallelGateway\" targetRef=\"gm\"/>\n" +
        "    <sequenceFlow id=\"_12\" sourceRef=\"forkParallelGateway\" targetRef=\"hr\"/>\n" +
        "    <sequenceFlow id=\"_13\" sourceRef=\"gm\" targetRef=\"joinParallelGateway\"/>\n" +
        "    <sequenceFlow id=\"_14\" sourceRef=\"hr\" targetRef=\"joinParallelGateway\"/>\n" +
        "    <sequenceFlow id=\"_16\" sourceRef=\"joinParallelGateway\" targetRef=\"notifyResult\"/>\n" +
        "    <sequenceFlow id=\"_18\" sourceRef=\"notifyResult\" targetRef=\"mainEnd\"/>\n" +
        "  </process>\n" +
        "  <bpmndi:BPMNDiagram documentation=\"background=#3C3F41;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0\" id=\"Diagram-_1\" name=\"New Diagram\">\n" +
        "    <bpmndi:BPMNPlane bpmnElement=\"VacationProcess\">\n" +
        "      <bpmndi:BPMNShape bpmnElement=\"mainStart\" id=\"Shape-mainStart\">\n" +
        "        <omgdc:Bounds height=\"32.0\" width=\"32.0\" x=\"5.0\" y=\"120.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"32.0\" width=\"32.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNShape>\n" +
        "      <bpmndi:BPMNShape bpmnElement=\"submitApply\" id=\"Shape-submitApply\">\n" +
        "        <omgdc:Bounds height=\"55.0\" width=\"85.0\" x=\"100.0\" y=\"110.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"55.0\" width=\"85.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNShape>\n" +
        "      <bpmndi:BPMNShape bpmnElement=\"vgm\" id=\"Shape-vgm\">\n" +
        "        <omgdc:Bounds height=\"55.0\" width=\"85.0\" x=\"275.0\" y=\"110.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"55.0\" width=\"85.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNShape>\n" +
        "      <bpmndi:BPMNShape bpmnElement=\"forkParallelGateway\" id=\"Shape-forkParallelGateway\">\n" +
        "        <omgdc:Bounds height=\"32.0\" width=\"32.0\" x=\"425.0\" y=\"120.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"32.0\" width=\"32.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNShape>\n" +
        "      <bpmndi:BPMNShape bpmnElement=\"gm\" id=\"Shape-gm\">\n" +
        "        <omgdc:Bounds height=\"55.0\" width=\"85.0\" x=\"570.0\" y=\"60.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"55.0\" width=\"85.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNShape>\n" +
        "      <bpmndi:BPMNShape bpmnElement=\"hr\" id=\"Shape-hr\">\n" +
        "        <omgdc:Bounds height=\"55.0\" width=\"85.0\" x=\"575.0\" y=\"180.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"55.0\" width=\"85.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNShape>\n" +
        "      <bpmndi:BPMNShape bpmnElement=\"joinParallelGateway\" id=\"Shape-joinParallelGateway\">\n" +
        "        <omgdc:Bounds height=\"32.0\" width=\"32.0\" x=\"775.0\" y=\"130.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"32.0\" width=\"32.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNShape>\n" +
        "      <bpmndi:BPMNShape bpmnElement=\"notifyResult\" id=\"Shape-notifyResult\">\n" +
        "        <omgdc:Bounds height=\"55.0\" width=\"85.0\" x=\"875.0\" y=\"120.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"55.0\" width=\"85.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNShape>\n" +
        "      <bpmndi:BPMNShape bpmnElement=\"mainEnd\" id=\"Shape-mainEnd\">\n" +
        "        <omgdc:Bounds height=\"32.0\" width=\"32.0\" x=\"1035.0\" y=\"130.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"32.0\" width=\"32.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNShape>\n" +
        "      <bpmndi:BPMNEdge bpmnElement=\"_13\" id=\"BPMNEdge__13\" sourceElement=\"_6\" targetElement=\"_3\">\n" +
        "        <omgdi:waypoint x=\"655.0\" y=\"87.5\"/>\n" +
        "        <omgdi:waypoint x=\"775.0\" y=\"146.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"0.0\" width=\"0.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNEdge>\n" +
        "      <bpmndi:BPMNEdge bpmnElement=\"_12\" id=\"BPMNEdge__12\" sourceElement=\"ParallelGateway\" targetElement=\"_7\">\n" +
        "        <omgdi:waypoint x=\"457.0\" y=\"136.0\"/>\n" +
        "        <omgdi:waypoint x=\"575.0\" y=\"207.5\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"0.0\" width=\"0.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNEdge>\n" +
        "      <bpmndi:BPMNEdge bpmnElement=\"_14\" id=\"BPMNEdge__14\" sourceElement=\"_7\" targetElement=\"_3\">\n" +
        "        <omgdi:waypoint x=\"660.0\" y=\"207.5\"/>\n" +
        "        <omgdi:waypoint x=\"775.0\" y=\"146.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"0.0\" width=\"0.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNEdge>\n" +
        "      <bpmndi:BPMNEdge bpmnElement=\"_16\" id=\"BPMNEdge__16\" sourceElement=\"_3\" targetElement=\"_15\">\n" +
        "        <omgdi:waypoint x=\"807.0\" y=\"146.0\"/>\n" +
        "        <omgdi:waypoint x=\"875.0\" y=\"147.5\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"0.0\" width=\"0.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNEdge>\n" +
        "      <bpmndi:BPMNEdge bpmnElement=\"_18\" id=\"BPMNEdge__18\" sourceElement=\"_15\" targetElement=\"_17\">\n" +
        "        <omgdi:waypoint x=\"960.0\" y=\"147.5\"/>\n" +
        "        <omgdi:waypoint x=\"1035.0\" y=\"146.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"0.0\" width=\"0.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNEdge>\n" +
        "      <bpmndi:BPMNEdge bpmnElement=\"_8\" id=\"BPMNEdge__8\" sourceElement=\"_2\" targetElement=\"submitApply\">\n" +
        "        <omgdi:waypoint x=\"37.0\" y=\"136.0\"/>\n" +
        "        <omgdi:waypoint x=\"100.0\" y=\"137.5\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"0.0\" width=\"0.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNEdge>\n" +
        "      <bpmndi:BPMNEdge bpmnElement=\"_9\" id=\"BPMNEdge__9\" sourceElement=\"submitApply\" targetElement=\"_4\">\n" +
        "        <omgdi:waypoint x=\"185.0\" y=\"137.5\"/>\n" +
        "        <omgdi:waypoint x=\"275.0\" y=\"137.5\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"0.0\" width=\"0.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNEdge>\n" +
        "      <bpmndi:BPMNEdge bpmnElement=\"_11\" id=\"BPMNEdge__11\" sourceElement=\"ParallelGateway\" targetElement=\"_6\">\n" +
        "        <omgdi:waypoint x=\"457.0\" y=\"136.0\"/>\n" +
        "        <omgdi:waypoint x=\"570.0\" y=\"87.5\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"0.0\" width=\"0.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNEdge>\n" +
        "      <bpmndi:BPMNEdge bpmnElement=\"_10\" id=\"BPMNEdge__10\" sourceElement=\"_4\" targetElement=\"ParallelGateway\">\n" +
        "        <omgdi:waypoint x=\"360.0\" y=\"137.5\"/>\n" +
        "        <omgdi:waypoint x=\"425.0\" y=\"136.0\"/>\n" +
        "        <bpmndi:BPMNLabel>\n" +
        "          <omgdc:Bounds height=\"0.0\" width=\"0.0\" x=\"0.0\" y=\"0.0\"/>\n" +
        "        </bpmndi:BPMNLabel>\n" +
        "      </bpmndi:BPMNEdge>\n" +
        "    </bpmndi:BPMNPlane>\n" +
        "  </bpmndi:BPMNDiagram>\n" +
        "</definitions>\n";
BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
BpmnModel bpmnModel = bpmnXMLConverter.convertToBpmnModel(new StringStreamSource(bpmnXml), false, false);

byte[] bytes = bpmnXMLConverter.convertToXML(bpmnModel);
String xml = StrUtil.utf8Str(bytes);

根据taskId获取BpmnModel。

String taskId = "11";
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());

保存act_ge_model。

BpmnModel bpmnModel = null;
Process process = bpmnModel.getMainProcess();
String modelKey = "model" + new Date().getTime();
Map<String, Object> metaInfo = new HashMap<>();
metaInfo.put("createUser", "zhangsan");
metaInfo.put("description", "拓展用的元数据可以存任意参数");
metaInfo.put("formId", "关联的表单主键id");

Model model = repositoryService.newModel();
model.setName(process.getName());
model.setKey(modelKey);
model.setCategory("Category1");
// 存一个拓展信息的json: 比如描述,创建人,外键id等
model.setMetaInfo(new JSONObject(metaInfo).toString());
model.setVersion(1);
repositoryService.saveModel(model);

// 保存act_ge_bytearray.bytes_
Model model1 = repositoryService.createModelQuery().modelKey(modelKey).singleResult();
byte[] bpmnXmlBytes = StringUtils.getBytes(bpmnXml, StandardCharsets.UTF_8);
// ACT_RE_MODEL.editor_source_value_id = re_re_bytearry.id_
repositoryService.addModelEditorSource(model1.getId(), bpmnXmlBytes);

根据modelId获取BpmnModel对象。

String modeId = "2501";
Model model = repositoryService.createModelQuery().modelId(modeId).singleResult();

byte[] bytes = repositoryService.getModelEditorSource(modeId);
String bpmnXml = StringUtils.toEncodedString(bytes, StandardCharsets.UTF_8);
BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
BpmnModel bpmnModel = bpmnXMLConverter.convertToBpmnModel(new StringStreamSource(bpmnXml), false, false);
System.out.println(bpmnModel);

三:BpmnModel

StartEvent extends Event extends FlowNode extends FlowElement extends BaseElement.

UserTask extends Task extends Activity extends FlowNode extends FlowElement extends BaseElement.

public class BpmnModel {
	// 获取流程图中的第一个Process对象
	public Process getMainProcess();
}
public class Process {
	// 获取所有流元素
	public Collection<FlowElement> getFlowElements();
	// 获取所有流元素
	public Map<String, FlowElement> getFlowElementMap();
	// 根据taskDefKey获取元素
	public FlowElement getFlowElement(String flowElementId);
	// 获取初始化元素(开始节点)
	public FlowElement getInitialFlowElement();
	// 获取元素父容器:EventSubProcess、SubProcess、Processs等
	public FlowElementsContainer getFlowElementsContainer(String flowElementId);
}
public abstract class FlowNode extends FlowElement {
	// 入线
	public List<SequenceFlow> getIncomingFlows();
	// 出线
	public List<SequenceFlow> getOutgoingFlows();

}

public abstract class Activity extends FlowNode {
	// 是否多实例
	public boolean hasMultiInstanceLoopCharacteristics();
}

注意:Process下面元素都属于FlowElement的子类(StartEvent、UserTask、Gateway、SubProcess、EndEvent、SequenceFlow等)。

public abstract class FlowElement extends BaseElement {
	public FlowElementsContainer getParentContainer();
}
public class SequenceFlow extends FlowElement {
	// 获取id
	public String getId();
	// 获取源流元素
	public FlowElement getSourceFlowElement();
	// 获取目标流元素
	public FlowElement getTargetFlowElement();
}
public abstract class BaseElement {
	// 获取扩展属性
	public Map<String, List<ExtensionAttribute>> getAttributes();
}
文章来源:https://blog.csdn.net/vbirdbest/article/details/135598469
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。