activiti bpmnModel使用
bpmnModel对象,是activiti动态部署钟很重要的一个对象,如果bpmnModel对象不能深入的理解,那可能如果自己需要开发一套流程设计器,就显得力不从心,之前我们公司自己开发了一套activiti web设计器,如下图所示:
当activiti web设计器设计的时候,存储格式是自定义的json对象,那现在问题来了,我们怎么把我们自己的json格式转化为标准的bpmn需要的xml文件呢?这一点很重要?所以这也是本节课需要重点讲解的地方,大家实际开发可以举一反三。灵活的运用到项目中。
1.1.1. BpmnModel使用
因为平时我们在使用的时候,展示流程图没有使用是默认的流程生成的这种方式,所以这里坐标信息,暂时不演示,主要演示节点等的核心功能。
1.1.1.1. eclipse绘制流程
为了方便演示,这里我们先在eclipse中绘制一个简单的流程。具体的流程图如下:
流程图的xml文件如下:直接用文本打开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://www.activiti.org/test">
<process id="process1" isExecutable="true">
<startEvent id="start1shareniu" name="start1shareniu"></startEvent>
<sequenceFlow id="starttouserTask" name="starttouserTask" sourceRef="start1shareniu" targetRef="userTask1shareniu"></sequenceFlow>
<userTask id="userTask1shareniu" name="userTask1shareniu"></userTask>
<sequenceFlow id="userTasktoend" name="userTasktoend" sourceRef="userTask1shareniu" targetRef="endEventshareniu"></sequenceFlow>
<endEvent id="endEventshareniu" name="endEventshareniu"></endEvent>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_process1">
<bpmndi:BPMNPlane bpmnElement="process1" id="BPMNPlane_process1">
<bpmndi:BPMNShape bpmnElement="start1shareniu" id="BPMNShape_start1shareniu">
<omgdc:Bounds height="35.0" width="35.0" x="70.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="userTask1shareniu" id="BPMNShape_userTask1shareniu">
<omgdc:Bounds height="60.0" width="100.0" x="180.0" y="110.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endEventshareniu" id="BPMNShape_endEventshareniu">
<omgdc:Bounds height="35.0" width="35.0" x="380.0" y="76.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="starttouserTask" id="BPMNEdge_starttouserTask">
<omgdi:waypoint x="87.0" y="150.0"></omgdi:waypoint>
<omgdi:waypoint x="100.0" y="139.0"></omgdi:waypoint>
<omgdi:waypoint x="180.0" y="140.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="87.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="userTasktoend" id="BPMNEdge_userTasktoend">
<omgdi:waypoint x="280.0" y="140.0"></omgdi:waypoint>
<omgdi:waypoint x="324.0" y="129.0"></omgdi:waypoint>
<omgdi:waypoint x="324.0" y="93.0"></omgdi:waypoint>
<omgdi:waypoint x="380.0" y="93.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="414.0" y="126.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
1.1.1.2. 自己生成
下面的代码,就是生成这个bpmnmodel 核心代码,代码如下所示:
//实例化BpmnModel对象
BpmnModel bpmnModel=new BpmnModel();
//开始节点的属性
StartEvent startEvent=new StartEvent();
startEvent.setId("start1shareniu");
startEvent.setName("start1shareniu");
//普通的UserTask节点
UserTask userTask=new UserTask();
userTask.setId("userTask1shareniu");
userTask.setName("userTask1shareniu");
//结束节点属性
EndEvent endEvent=new EndEvent();
endEvent.setId("endEventshareniu");
endEvent.setName("endEventshareniu");
//连线信息
List<SequenceFlow> sequenceFlows=new ArrayList<SequenceFlow>();
List<SequenceFlow> toEnd=new ArrayList<SequenceFlow>();
SequenceFlow s1=new SequenceFlow();
s1.setId("starttouserTask");
s1.setName("starttouserTask");
s1.setSourceRef("start1shareniu");
s1.setTargetRef("userTask1shareniu");
sequenceFlows.add(s1);
SequenceFlow s2=new SequenceFlow();
s2.setId("userTasktoend");
s2.setName("userTasktoend");
s2.setSourceRef("userTask1shareniu");
s2.setTargetRef("endEventshareniu");
toEnd.add(s2);
startEvent.setOutgoingFlows(sequenceFlows);
userTask.setOutgoingFlows(toEnd);
userTask.setIncomingFlows(sequenceFlows);
endEvent.setIncomingFlows(toEnd);
//Process对象
Process process=new Process();
process.setId("process1");
process.addFlowElement(startEvent);
process.addFlowElement(s1);
process.addFlowElement(userTask);
process.addFlowElement(s2);
process.addFlowElement(endEvent);
bpmnModel.addProcess(process);
上面的代码,我们已经写好了bpmnmodel绘制的流程,那我们怎么知道对还是不对呢?下面就开始将我们的bpmnmodel对象转化为标准的xml文件看一下。
1.1.2. BpmnModel转化xml
将上面的对象转化为标准的xml代码如下所示:
//bpmnModel 转换为标准的bpmn xml文件
BpmnXMLConverter bpmnXMLConverter=new BpmnXMLConverter();
byte[] convertToXML = bpmnXMLConverter.convertToXML(bpmnModel);
String bytes=new String(convertToXML);
System.out.println(bytes);
运行程序,看一下程序的输出如下:
<?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://www.activiti.org/test">
<process id="process1" isExecutable="true">
<startEvent id="start1shareniu" name="start1shareniu"></startEvent>
<sequenceFlow id="starttouserTask" name="starttouserTask" sourceRef="start1shareniu" targetRef="userTask1shareniu"></sequenceFlow>
<userTask id="userTask1shareniu" name="userTask1shareniu"></userTask>
<sequenceFlow id="userTasktoend" name="userTasktoend" sourceRef="userTask1shareniu" targetRef="endEventshareniu"></sequenceFlow>
<endEvent id="endEventshareniu" name="endEventshareniu"></endEvent>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_process1">
<bpmndi:BPMNPlane bpmnElement="process1" id="BPMNPlane_process1"></bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
我们看到转化的xml文件,对比eclipse绘制流程的xml,除了坐标没有,其他的都是正确的。那我们怎么验证我们生成的xml是正确的呢?因为转化成功,也不一定可以使用的。接下来看一下bpmnmodel如何验证。
1.1.3. BpmnModel验证
验证的方法代码如下所示:
说明,bpmnmodel正确,大于0,说明自定义的bpmnmodel是错误的,不可以使用的。
验证还是很有必要使用的,因为流程部署的时候,我们最好验证一次,没有问题在部署。
分享牛,分享、我们是快乐的。
分享牛原创(尊重原创 转载对的时候第一行请注明,转载出处来自分享牛http://blog.csdn.net/qq_30739519)
activiti bpmnModel使用的更多相关文章
- 流程开发Activiti 与SpringMVC整合实例
流程(Activiti) 流程是完成一系列有序动作的概述.每一个节点动作的结果将对后面的具体操作步骤产生影响.信息化系统中流程的功能完全等同于纸上办公的层级审批,尤其在oa系统中各类电子流提现较为明显 ...
- activiti当前任务高亮(解决乱码问题)
package com.xinwei; import java.io.File; import java.io.InputStream; import java.util.ArrayList; imp ...
- Spring Boot整合Activiti,查看流程图出现中文乱码问题
最近研究SpringBoot 整合Activiti时,实现流程图高亮追踪是出现中文乱码问题,找了很多方法,现在把我最后的解决方法提供给大家. Spring Boot是微服务快速开发框架,强调的是零配置 ...
- 解决ACTIVITI流程图设置字体不生效的问题
在ACTIVITI 5.15的版本中,有一个设置流程图的字体配置. 配置如下: <bean id="processEngineConfiguration" class=&qu ...
- activiti自定义流程之整合(四):整合自定义表单部署流程定义
综合前几篇博文内容,我想在整合这一部分中应该会有很多模块会跳过不讲,就如自定义表单的表单列表那一块,因为这些模块在整合的过程中都几乎没有什么改动,再多讲也是重复无用功. 正因为如此,在创建了流程模型之 ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(六):启动流程
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
- activiti搭建(四)八项服务介绍
转载请注明源地址:http://www.cnblogs.com/lighten/p/5927949.html 1.前言 之前学习的时候一直在其它文章看到activiti提供了七个接口来操作工作流,但在 ...
- modeler与activiti进行整合
整合Activiti Modeler到业务系统(或BPM平台) http://www.kafeitu.me/activiti/2013/03/10/integrate-activiti-modeler ...
随机推荐
- [LeetCode] Solve the Equation 解方程
Solve a given equation and return the value of x in the form of string "x=#value". The equ ...
- [LeetCode] Predict the Winner 预测赢家
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from eith ...
- org.apache.commons.lang3.tuple.Pair 作为更新参数,XML 中的 Sql 取不到值、报错
项目用的 Mybatis,今天改一个需求,落地实现是批量更新,且只需要根据主键(id)来更新一个字段(name). 于是,没有犹豫,像下面这样设计了数据结构: 既然是批量更新,那外层肯定是 List ...
- .NET CORE 2.0 踩坑记录之ConfigurationManager
在之前.net framework 中使用的ConfigurationManager还是很方便的,不过在.NET CORE 2.0中SDK默认已经不存在ConfigurationManager. 那么 ...
- mongo 服务化与删除
MONGO 服务化 使用超级用户进入cmd到D:\mongodb\bin> 日志文件需要提前创建 mongod --bind_ip 0.0.0.0 --logpath D:\mongodb\d ...
- 用js来实现那些数据结构09(集合01-集合的实现)
说到集合,第一个想到的就是中学学到的那个数学概念:集合.在我们开始集合相关的js实现前,我们有必要来了解一下什么是集合以及集合的数学概念. 好吧,我们一起来复习一下早就被我们遗忘的集合. 集合是由一组 ...
- 51nod 1981 如何愉快地与STL玩耍
Description 驴蛋蛋在愉快地与STL玩耍 突然间小A跳了出来对驴蛋蛋说,看你与STL玩的很开心啊,那我给你一个大小为N的vector,这个vector上每个位置上是一个set, 每次我会在闭 ...
- TCP 通信
一.TCP与UDP的区别 二.ServerSocket与Socket 1 ServerSocket 以上介绍的几个构造方法中,第二个构造方法最常用. 2.Socket import java.io.* ...
- easyui常见问题
EasyUi combobox 下拉列表JS添加首/尾选择项 下拉列表获取数据后,再动态添加一项数据项,如:"<option value=''>全部</option> ...
- vue-cli中配置sass
第一步, npm install node-sass --save-dev npm install sass-loader --save-dev 第二部,打开webpack.base.config.j ...