Activit的心路历程:获取当前节点的下一节点【可能存在多个】的nodeId
上一任务节点
在我的开发任务中,突然给我提出了一个待办任务需要获取当前任务节点下一任务节点的表单信息,刚开始搞得我有点措手不及,后来仔细是靠后,灵感一下,直接操作流程的bpmn信息就可以获取到节点信息嘛,顺着这个思路,我整理出了自己的思路:
(1)将节点大体分为两类,一类是网关节点,另外一类就是用户任务节点,使用List集合,将网关与用户任务进行分类
(2)获取上一节点,我们就需要从bpmn的连线信息入手,这次我们获取的是UserTask节点的出线,固定连线的sourceRef,辨别节点targtaetRef的类型,当是用户任务时,放进 List behildNodeIdlist= new ArrayList<>();,当是GateWay节点时,将sourceRef设为网关的,继续遍历下一节点,就是跳过网关节点,只要用户任务节点
@Test
public void behindNode() {
// String nodeId="UserTask_0mkm9h7";
String nodeId = "UserTask_0mkm9h7";
String processInstanceId="2205001";
//网关集合
List<Gateway> gateways = new ArrayList<>();
//用户任务集合
List<UserTask> userTasks = new ArrayList<>();
//网关节点id
List<String> gatewayNodelIdList = new ArrayList<>();
//用户任务节点id
List<String> usertaskNodelIdList = new ArrayList<>();
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
String processDefinitionId = processInstance.getProcessDefinitionId();
//ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
List<Process> processes = bpmnModel.getProcesses();
Process process = processes.get(0);
Collection<FlowElement> flowElements = process.getFlowElements();
//将网关信息与用户任务进行分类存储(放于JVM堆中)
flowElements.forEach(flowElement -> {
if (flowElement instanceof Gateway) {
gatewayNodelIdList.add(flowElement.getId());
gateways.add((Gateway) flowElement);
}
if (flowElement instanceof UserTask) {
usertaskNodelIdList.add(flowElement.getId());
userTasks.add((UserTask) flowElement);
}
});
//存放下一节点的nodeId(可能存在多个)
List<String> behildNodeIdlist = new ArrayList<>();
//变量所有的UserTask节点
for (UserTask userTask : userTasks) {
//获取UserTask节点的出线
List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
for (SequenceFlow outgoingFlow : outgoingFlows) {
String sourceRef = outgoingFlow.getSourceRef();
String targetRef = outgoingFlow.getTargetRef();
//固定出线的(sourceRef)
if (nodeId.equals(sourceRef)) {
//当前节点的下一节点是网关,跳过
if (gatewayNodelIdList.contains(targetRef)) {
for (Gateway gateway : gateways) {
//获取网关的出线信息
List<SequenceFlow> outgoingFlowsGateWay = gateway.getOutgoingFlows();
for (SequenceFlow sequenceFlow : outgoingFlowsGateWay) {
String sourceRefGateWay = sequenceFlow.getSourceRef();
String targetRefGateWay = sequenceFlow.getTargetRef();
//定sourceRefGateWay
if (targetRef.equals(sourceRefGateWay)) {
behildNodeIdlist.add(targetRefGateWay);
}
}
}
} else {
behildNodeIdlist.add(targetRef);
}
}
}
}
behildNodeIdlist.forEach(System.out::println);
}
我使用的测试流程bpmn如下
<?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="http://activiti.org/bpmn">
<process id="Process_1" name="1023后台设计器测试数据HH" isExecutable="true">
<startEvent id="StartEvent_1b9bgjv" name="start"></startEvent>
<userTask id="UserTask_1wba62u" name="faqi" activiti:assignee="wuniting">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="SequenceFlow_1fnj22n" sourceRef="StartEvent_1b9bgjv" targetRef="UserTask_1wba62u"></sequenceFlow>
<parallelGateway id="ParallelGateway_0g393ev"></parallelGateway>
<userTask id="UserTask_1nt87by" name="tb1" activiti:assignee="wuniting">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<userTask id="UserTask_1xty4gu" name="tb2" activiti:assignee="zhangmiao">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<userTask id="UserTask_0y14rmq" name="sp1" activiti:assignee="wuniting">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<userTask id="UserTask_17jd9y1" name="sp2" activiti:assignee="zhangmiao">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<parallelGateway id="ParallelGateway_1qs7f87"></parallelGateway>
<endEvent id="EndEvent_0fo9mwb" name="交易完成"></endEvent>
<sequenceFlow id="SequenceFlow_1dkxqia" sourceRef="UserTask_1wba62u" targetRef="ParallelGateway_0g393ev"></sequenceFlow>
<sequenceFlow id="SequenceFlow_1pp85s1" sourceRef="ParallelGateway_0g393ev" targetRef="UserTask_1nt87by"></sequenceFlow>
<sequenceFlow id="SequenceFlow_1x051ae" sourceRef="ParallelGateway_0g393ev" targetRef="UserTask_1xty4gu"></sequenceFlow>
<sequenceFlow id="SequenceFlow_05zxco5" sourceRef="UserTask_1nt87by" targetRef="UserTask_0y14rmq"></sequenceFlow>
<sequenceFlow id="SequenceFlow_0bx5wt0" sourceRef="UserTask_1xty4gu" targetRef="UserTask_17jd9y1"></sequenceFlow>
<sequenceFlow id="SequenceFlow_0xgm2pr" sourceRef="UserTask_17jd9y1" targetRef="ParallelGateway_1qs7f87"></sequenceFlow>
<sequenceFlow id="SequenceFlow_1o2rph4" sourceRef="UserTask_0y14rmq" targetRef="ParallelGateway_1qs7f87"></sequenceFlow>
<sequenceFlow id="SequenceFlow_1hyky18" sourceRef="ParallelGateway_1qs7f87" targetRef="UserTask_0mkm9h7"></sequenceFlow>
<userTask id="UserTask_0mkm9h7" name="spe" activiti:assignee="wuniting">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="SequenceFlow_1smv331" sourceRef="UserTask_0mkm9h7" targetRef="EndEvent_0fo9mwb"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_Process_1">
<bpmndi:BPMNPlane bpmnElement="Process_1" id="BPMNPlane_Process_1">
<bpmndi:BPMNShape bpmnElement="StartEvent_1b9bgjv" id="BPMNShape_StartEvent_1b9bgjv">
<omgdc:Bounds height="36.0" width="36.0" x="182.0" y="222.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="UserTask_1wba62u" id="BPMNShape_UserTask_1wba62u">
<omgdc:Bounds height="80.0" width="100.0" x="270.0" y="200.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="ParallelGateway_0g393ev" id="BPMNShape_ParallelGateway_0g393ev">
<omgdc:Bounds height="50.0" width="50.0" x="425.0" y="215.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="UserTask_1nt87by" id="BPMNShape_UserTask_1nt87by">
<omgdc:Bounds height="80.0" width="100.0" x="540.0" y="140.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="UserTask_1xty4gu" id="BPMNShape_UserTask_1xty4gu">
<omgdc:Bounds height="80.0" width="100.0" x="540.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="UserTask_0y14rmq" id="BPMNShape_UserTask_0y14rmq">
<omgdc:Bounds height="80.0" width="100.0" x="710.0" y="140.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="UserTask_17jd9y1" id="BPMNShape_UserTask_17jd9y1">
<omgdc:Bounds height="80.0" width="100.0" x="710.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="ParallelGateway_1qs7f87" id="BPMNShape_ParallelGateway_1qs7f87">
<omgdc:Bounds height="50.0" width="50.0" x="865.0" y="205.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="EndEvent_0fo9mwb" id="BPMNShape_EndEvent_0fo9mwb">
<omgdc:Bounds height="36.0" width="36.0" x="1162.0" y="212.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="UserTask_0mkm9h7" id="BPMNShape_UserTask_0mkm9h7">
<omgdc:Bounds height="80.0" width="100.0" x="990.0" y="190.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_1pp85s1" id="BPMNEdge_SequenceFlow_1pp85s1">
<omgdi:waypoint x="450.0" y="215.0"></omgdi:waypoint>
<omgdi:waypoint x="450.0" y="180.0"></omgdi:waypoint>
<omgdi:waypoint x="540.0" y="180.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_0xgm2pr" id="BPMNEdge_SequenceFlow_0xgm2pr">
<omgdi:waypoint x="810.0" y="300.0"></omgdi:waypoint>
<omgdi:waypoint x="890.0" y="300.0"></omgdi:waypoint>
<omgdi:waypoint x="890.0" y="255.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_1dkxqia" id="BPMNEdge_SequenceFlow_1dkxqia">
<omgdi:waypoint x="370.0" y="240.0"></omgdi:waypoint>
<omgdi:waypoint x="425.0" y="240.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_05zxco5" id="BPMNEdge_SequenceFlow_05zxco5">
<omgdi:waypoint x="640.0" y="180.0"></omgdi:waypoint>
<omgdi:waypoint x="710.0" y="180.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_1x051ae" id="BPMNEdge_SequenceFlow_1x051ae">
<omgdi:waypoint x="450.0" y="265.0"></omgdi:waypoint>
<omgdi:waypoint x="450.0" y="300.0"></omgdi:waypoint>
<omgdi:waypoint x="540.0" y="300.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_1o2rph4" id="BPMNEdge_SequenceFlow_1o2rph4">
<omgdi:waypoint x="810.0" y="180.0"></omgdi:waypoint>
<omgdi:waypoint x="890.0" y="180.0"></omgdi:waypoint>
<omgdi:waypoint x="890.0" y="205.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_0bx5wt0" id="BPMNEdge_SequenceFlow_0bx5wt0">
<omgdi:waypoint x="640.0" y="300.0"></omgdi:waypoint>
<omgdi:waypoint x="710.0" y="300.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_1smv331" id="BPMNEdge_SequenceFlow_1smv331">
<omgdi:waypoint x="1090.0" y="230.0"></omgdi:waypoint>
<omgdi:waypoint x="1162.0" y="230.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_1fnj22n" id="BPMNEdge_SequenceFlow_1fnj22n">
<omgdi:waypoint x="218.0" y="240.0"></omgdi:waypoint>
<omgdi:waypoint x="270.0" y="240.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_1hyky18" id="BPMNEdge_SequenceFlow_1hyky18">
<omgdi:waypoint x="915.0" y="230.0"></omgdi:waypoint>
<omgdi:waypoint x="990.0" y="230.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
Activit的心路历程:获取当前节点的下一节点【可能存在多个】的nodeId的更多相关文章
- javascript 获取dom书的下一个节点。
利用javascript 写一个在页面点击加减按钮实现数字的累加.. 简略的html大概如此.看得懂就好不要在意这些细节啊 <input type="button" valu ...
- Activit的心路历程:获取当前节点的上一节点【可能存在多个】的nodeId
在我的开发任务中,突然给我提出了一个待办任务需要获取当前任务节点上以任务节点的表单信息,刚开始搞得我有点措手不及,后来仔细是靠后,灵感一下,直接操作流程的bpmn信息就可以获取到节点信息嘛,顺着这个思 ...
- 优云老王的心路历程(二):下一站Web体验监控产品
在上一篇文章中,和大家聊到了建立Web应用体验监控体系,经过了概念阶段,也完成了技术选型,就进入了把实质性的产品研发阶段.作为产品经理,时刻不敢忘记我们的产品目标:无限感知你的用户,建立完备的体验监控 ...
- 学习JS的心路历程-参数的传递(下)
今天我们要来探讨JS到底是透过何种参数传递方式呢? 废话不多说,上示例!! 我们先声明原始型别和物件型别来看看两者是否会有不一样的差异: var myStr = 'Hola': var myObj = ...
- Activiti6.0获取下一节点任务的心路历程
在我的开发任务中,我被分配了一个像下一个节点审批人发送短信的任务,这个任务看起来非常的简单,但在开发过程中遇到了许多的坑,在这里进行记录,如果你想要快速知道结果,请看代码版本(3). 首先,就是获取下 ...
- 同门不同类—创新Aurvana Live2/Air简评(附随身视听设备心路历程)
(注,本文把live2/air并成一起写的,同时本人是木耳,请轻拍) 本命年各种坏东西,很是无语,终于坏到耳塞耳机了来了,之前用的拜亚DT235无缘无故就一边不响了,无奈只能扔了. 纠结了好几个月,终 ...
- 【剑指offer】08二叉树的下一个节点,C++实现
原创博文,转载请注明出处! # 题目 父节点指向子节点的指针用实线表示,从子节点指向父节点的指针用虚线表示. # 思路 如果节点有右子节点,则右子节点的最左节点是该节点的下一个节点.例如,寻找b的下一 ...
- 剑指Offer的学习笔记(C#篇)-- 二叉树的下一个节点(好理解版本)
题目描述 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回.注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针. 一 . 理解题意 该题目我们可以借鉴一个非常影响不好的 ...
- 剑指offer笔记面试题8----二叉树的下一个节点
题目:给定一棵二叉树和其中的一个节点,如何找出中序遍历序列的下一个节点?树中的节点除了有两个分别指向左.右子节点的指针,还有一个指向父节点的指针. 测试用例: 普通二叉树(完全二叉树,不完全二叉树). ...
随机推荐
- Redis 中 BitMap 的使用场景
BitMap BitMap 原本的含义是用一个比特位来映射某个元素的状态.由于一个比特位只能表示 0 和 1 两种状态,所以 BitMap 能映射的状态有限,但是使用比特位的优势是能大量的节省内存空间 ...
- C++ 构造函数、拷贝构造函数、赋值运算符
<C++ Primer Plus> 12.1 动态内存和类 12.1.1 复习示例和静态类成员 不能在类声明中初始化静态成员变量,这是因为声明描述了如何分配内存,但并不分配内存 如果在头文 ...
- LCA树上倍增求法
1.LCA LCA就是最近公共祖先(Least common ancestor),x,y的LCA记为z=LCA(x,y),满足z是x,y的公共祖先中深度最大的那一个(即离他们最近的那一个)qwq 2. ...
- 编程代码 | C++/C输出阳历万年历—精美日历制作
前言:本文章向大家介绍如何用C语言代码实现万年历使用实例.应用技巧.基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下. void输出万年历(int年, int月, int日 ...
- centos8平台基于iftop监控网络流量
一,iftop的作用: 基于ip统计外部机器与本机之间的网络流量, 可以方便的查看各客户端是否有非正常的到本机的访问 说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnbl ...
- centos8平台使用journalctl管理systemd-journald日志
一,systemd-journald的作用 1,什么是systemd-journald? systemd-journald 是 systemd 自带的日志系统,是一个收集并存储各类日志数据的系统服务. ...
- <转>二十问全链路压测干货汇总(上)
本文转载自:微信公众号-数列科技<二十问全链路压测干货汇总(上)> 最近几年全链路压测无疑成为了一个热门话题,在各个技术峰会上都可以看到它的身影. 一些大型的互联网公司,比如阿里巴巴.京东 ...
- python的部分GUI模块简介tkinter、pyqt5(Qt Designer)
笔者认为,这两个作为Python3较为常用且简单的GUI模块,是Python开发者所必须学习至少是了解的. 其中tkinter为Python3自带的GUI模块,而pyqt5则需要通过pip insta ...
- 习题解答chapter04
题目: 实验:利用IDE的debug功能给例6.4和例6.6的new语句设置断点,使用单步调试(step into/step over)跟踪子类对象实例化(初始化)的执行顺序,并总结该过程.(教材:J ...
- 安卓日常开发和逆向中常用的shell命令与非shell命令
简述shell 命令与 非shell命令区别 shell命令不用先adb shell进入界面执行 非shell命令必须要 adb shell进入界面执行 基础非shell命令 1.安装app adb ...