zoukankan      html  css  js  c++  java
  • activiti 配置节点 连线信息获取

    1.1.1. 前言

    当使用eclipse插件进行流程设计的时候,部署流程之后,我们怎样获取我们定义的全部的节点、连线、关口等配置信息呢?有的人看到这个需求,不免窃喜。这不非常easy嘛,又一次打来bmpn中定义的xml信息,查看不就完了,确实这样的方式是可取的,可是当我们的项目流程在启动的时候,我们想要获取定义的信息的时候,换言之就是 我们能动态的读取里面的信息反馈给系统用户的时候,我们该怎样获取呢?总不能告诉用户你去打开xml文件自己去查看,用户未必能看懂里面的xml定义信息吧。

    这样的方式不是添加了用户操作难度,还要找个人培训用户吧。那所以我们该怎样提供一个接口,让用户须要看的时候,点击一个button。就能一目了然的看到配置的信息呢,这是其一,第二:我们怎样能够获取到一个任务的出线信息。动态的渲染到页面,让用户操作呢?举一个简单的样例,a任务节点有三根出线、出线1 出线2、出线3、当用户查询代办信息的时候,我们怎么把当前a任务节点的3个出线渲染到页面,让用户决定下一个流程的去向。第三:还是上面的样例,a用户选择不同的出线信息就决定了流程的不同运转轨迹,由于activiti 工作流就是靠线上的表达式运转的,那怎么能在用户选择的时把线上配置的表达式获取到呢?还是上面的问题,总不能告诉用户你选择a出线输入a=1表达式。选择2出线输入a=2表达式。这样的方式操作不方便。也是不可取的。所以以下我们将具体的解说怎样获取配置文件的节点信息。

    1.1.2. 流程的定义

    定义一个流程流程的具体定义例如以下:

     

    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: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" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="daling"> <process id="daling" name="name_daling" isExecutable="true" activiti:candidateStarterUsers="a,b,c,d"> <startEvent id="startevent1" name="Start"></startEvent> <userTask id="usertask1" name="usertask1审批" activiti:candidateGroups="1,2"> <documentation>usertask1审批</documentation> </userTask> <userTask id="usertask2" name="usertask2审批" activiti:candidateUsers="b,c"></userTask> <endEvent id="endevent1" name="End"></endEvent> <sequenceFlow id="flow1" name="flow1" sourceRef="startevent1" targetRef="usertask1"> <documentation>flow1连线</documentation> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${a==2}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="flow2" name="flow2" sourceRef="usertask1" targetRef="usertask2"> <documentation>usertask1审批出线</documentation> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${a==1}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="flow3" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_daling"> <bpmndi:BPMNPlane bpmnElement="daling" id="BPMNPlane_daling"> <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"> <omgdc:Bounds height="35.0" width="35.0" x="230.0" y="10.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1"> <omgdc:Bounds height="55.0" width="105.0" x="300.0" y="110.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2"> <omgdc:Bounds height="55.0" width="105.0" x="280.0" y="192.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"> <omgdc:Bounds height="35.0" width="35.0" x="230.0" y="340.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"> <omgdi:waypoint x="247.0" y="45.0"></omgdi:waypoint> <omgdi:waypoint x="352.0" y="110.0"></omgdi:waypoint> <bpmndi:BPMNLabel> <omgdc:Bounds height="14.0" width="100.0" x="247.0" y="45.0"></omgdc:Bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"> <omgdi:waypoint x="352.0" y="165.0"></omgdi:waypoint> <omgdi:waypoint x="332.0" y="192.0"></omgdi:waypoint> <bpmndi:BPMNLabel> <omgdc:Bounds height="14.0" width="100.0" x="352.0" y="165.0"></omgdc:Bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"> <omgdi:waypoint x="332.0" y="247.0"></omgdi:waypoint> <omgdi:waypoint x="247.0" y="340.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>



    流程定义完了就開始部署測试怎样获取节点的信息:

    当一个流程xml部署的时候,看看数据库表的变化后面可能用到。比較熟悉表结构的同志们就忽略继续向下看吧。

    部署的时候ACT_GE_BYTEARRAY表会变化,具体例如以下图所看到的:

     

    ACT_GE_PROPERTY表会变化吧。生成next.dbid

    ACT_RE_PROCDEF会变化,由于定义的部署流程信息。

    好了表的关系大致了解下,看以下我们怎样获取节点配置信息demo吧。

     

    1.1.3. 代码获取

    ProcessEnginesDemo demo = new ProcessEnginesDemo();
    RepositoryService repositoryService2 = demo.getRepositoryService();
    //processDefinitionId 相应表ACT_RE_PROCDEF主键信息
    String processDefinitionId="daling:5:30004";
    //获取bpmnModel对象
    BpmnModel bpmnModel = repositoryService2.getBpmnModel(processDefinitionId);
    //由于我们这里仅仅定义了一个Process 所以获取集合中的第一个就可以
    Process process = bpmnModel.getProcesses().get(0);
    //获取全部的FlowElement信息
    Collection<FlowElement> flowElements = process.getFlowElements();
    for (FlowElement flowElement : flowElements) {
    //假设是任务节点
    if (flowElement instanceof UserTask) {
    UserTask userTask=(UserTask) flowElement;
    //获取入线信息
    List<SequenceFlow> incomingFlows = userTask.getIncomingFlows();
    for (SequenceFlow sequenceFlow : incomingFlows) {
    System.out.println(sequenceFlow.getId() +"-"+sequenceFlow.getConditionExpression()+"--"+sequenceFlow.getDocumentation()+"-"
    +sequenceFlow.getSourceRef()+"--"+sequenceFlow.getTargetRef()+"-");
    }
    }
    }


    程序的输出例如以下所看到的:

    flow1-${a==2}--flow1连线-startevent1--usertask1-

    flow2-${a==1}--usertask1审批出线-usertask1--usertask2

    上面的代码。我们也能看出来主要是获取BpmnModel中的Process对象。Process对象封装了全部的节点、连线、以及关口等信息。所以这个Process对象还是非常重要的,拿到这个对象就能够为所欲为了。

    这个BpmnModel对象能够參考:http://blog.csdn.net/qq_30739519/article/details/51166993这篇文章。

    1.1.4. 问题以及延伸

    上面的代码基本上已经满足我们的需求,可是也存在2个问题:

    第一个问题:获取配置文件里节点的配置信息,上文我们获取到的是指定的任务节点的配置信息,怎么获取全部的节点配置信息呢?非常显然我们能够推断这个FlowElement类型进行转换到相应的类型获取。这个比較简单 FlowElement是一个抽象类。以下有非常多实现类。

    相应推断转换就可以。

    第二个问题:我们怎么能一路究竟获取到全部的配置节点信息。以及配置的路径轨迹的信息呢?这里提供的思路 例如以下:activiti是依据连线运转的。我们能够開始从開始节点查找出线。一直查到结束节点。能够使用递归实现。

    1.1.5. 遗留问题

    可能有些读者对于上面的Process不是非常熟悉,Process是动态部署中非经常常使用的一个对象。所以我们兴许章节会专门出一个章节来解说Process对象中的各个子对象。以及子对象的特性。

  • 相关阅读:
    SpringMVC返回JSON数据时日期格式化问题
    elementUI-tree组件 懒加载
    vue elementUi tree 懒加载使用详情
    Mybatis ResultMap Collection 复合主键
    ElasticSearch-IK分词
    Spring中的InitializingBean接口的使用
    ContextLoadListener & DispatcherServlet 加载顺序以及加载过程
    Spring中查看加载配置文件中 加载类的个数及详情
    DispatcherServlet 被加载顺序
    JetBrainsIDEA-structure结构继承的图标说明
  • 原文地址:https://www.cnblogs.com/llguanli/p/8325293.html
Copyright © 2011-2022 走看看