Activiti 流程部署方式 activi 动态部署(高级源代码篇)
Activiti的流程 部署方式有非常多种方式,我们能够依据activit工作流引擎提供的ap方式进行部署。
当然了实际需求决定你要使用哪一种api操作,后面的总结具体介绍了使用场景。
以下看一下部署方式。
流程部署的方式在类org.activiti.engine.repository.DeploymentBuilder中定义的部署方接口式例如以下
:
DeploymentBuilder addInputStream(String resourceName, InputStream inputStream);
DeploymentBuilder addClasspathResource(String resource);
DeploymentBuilder addString(String resourceName, String text);
DeploymentBuilder addZipInputStream(ZipInputStream zipInputStream);
DeploymentBuilder addBpmnModel(String resourceName, BpmnModel bpmnModel);
能够看出activit工作流引擎一共提供五种方式进行流程对的部署。
addInputStream 依据流进行部署。
addClasspathResource 依据resource部署。
addString依据字符串部署。
addZipInputStream依据zip流进行部署。
addBpmnModel 依据BpmnModel进行部署。
这样的方式使用的场景就是我们自己设计一个流程设计器画布。自己去解析成bpmn规范文件。适合动态的拓展。自己定义。
以下一一解说怎样使用api去进行部署。
1.1.1. addInputStream方式
流程定义例如以下所看到的:
<?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"></userTask>
<userTask id="usertask2" name="usertask2审批" activiti:candidateUsers="b,c"></userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></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: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: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>
程序代码例如以下所看到的:
InputStream inputStream=ProcessEnginesDemo.class.getClassLoader().getResourceAsStream("demo1.bpmn");
Deployment deploy = repositoryService2.createDeployment().addInputStream("addInputStream", inputStream).deploy();
System.out.println(deploy);
程序的执行结果例如以下所看到的:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
1.1.2. addClasspathResource方式
流程的定义还是第一种方式的流程图,程序例如以下所看到的:
Deployment
deploy2 =repositoryService2.createDeployment().addClasspathResource("demo1.bpmn").deploy();
addClasspathResource中的參数是依据classpath方式载入,假设demo1.bpmn路径在com.daling.ch1.ProcessEnginesDemo包以下则參数參入com/daling/ch1/ProcessEnginesDemo/demo1.bpmn
程序的执行例如以下图所看到的:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
1.1.3. addString方式
流程的定义还是第一种方式的流程图,程序例如以下所看到的:
String str=read("D:\\WorkSpace\\activitidemo\\src\\main\\resources/demo1.bpmn");
Deployment deploy2 = repositoryService2.createDeployment().addString("string", str).deploy();
public static String read(String filePath) {
// 读取txt内容为字符串
StringBuffer txtContent = new StringBuffer();
// 每次读取的byte数
byte[] b = new byte[8 * 1024];
InputStream in = null;
try {
// 文件输入流
in = new FileInputStream(filePath);
while (in.read(b) != -1) {
// 字符串拼接
txtContent.append(new String(b));
}
// 关闭流
in.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return txtContent.toString();
}
程序的执行效果例如以下图所看到的:
1.1.4. addZipInputStream方式
流程的定义还是第一种方式的流程图。仅仅只是讲demo1.bpmn打包成zip文件,结构例如以下:
程序操作例如以下所看到的:
InputStream
inputStream=ProcessEnginesDemo.class.getClassLoader().getResourceAsStream("demo1.zip");
ZipInputStream
zipInputStream=new ZipInputStream(inputStream);
Deployment
deploy2 =repositoryService2.createDeployment().addZipInputStream(zipInputStream).deploy();
程序的输出结果例如以下图所看到的:
1.1.5. addBpmnModel方式
这一种方式比較复杂须要自己去手动拼接对象,这里我们就写一个简单的吧。实际开发中假设不够用能够自己扩展依据这个demo详细的实现方式例如以下:
ProcessEnginesDemo demo = new ProcessEnginesDemo();
RepositoryService repositoryService2 = demo.getRepositoryService();
BpmnModel bpmnModel=new BpmnModel();
StartEvent startEvent=new StartEvent();
startEvent.setId("start1shareniu");
startEvent.setName("start1shareniu");
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=new Process();
process.setId("process1");
process.addFlowElement(startEvent);
process.addFlowElement(s1);
process.addFlowElement(userTask);
process.addFlowElement(s2);
process.addFlowElement(endEvent);
bpmnModel.addProcess(process);
repositoryService2.createDeployment().addBpmnModel("bpmnModel", bpmnModel).deploy();
程序的输出截下图所看到的:
总结:
五种方式的总结:
1.假设须要自己开发一套流程设计的话就使用addBpmnModel这样的方法吧。这样的方式更加灵活。缺点就是须要了解每个对象的含义,须要对bpmnMode对象中的各个子对象都有所了解。
2.假设项目中的流程图是固定的可是一些候选组或者人或者名称不是固定的。须要从数据库中查询出来赋值在部署使用addString这样的方法,配合velocity等叶面静态化工具一起使用。
3.假设须要用户自己上传文件部署的话,能够使用addInputStream和addZipInputStream这两种方式。
Activiti 流程部署方式 activi 动态部署(高级源代码篇)的更多相关文章
- Activiti 流程部署方式 activi 动态部署(高级源码篇)
Activiti的流程 部署方式有很多种方式,我们可以根据activit工作流引擎提供的ap方式进行部署. 当然了实际需求决定你要使用哪一种api操作,后面的总结详细介绍了使用场景. 下面看一下部署方 ...
- WAF的部署方式——有直路部署和旁路部署
随着电子商务.网上银行.电子政务的盛行,WEB服务器承载的业务价值越来越高,WEB服务器所面临的安全威胁也随之增大,因此,针对WEB应用层的防御成为必然趋势,WAF(WebApplicationFir ...
- salesforce零基础学习(一百一十七)salesforce部署方式及适用场景
本篇参考:https://architect.salesforce.com/decision-guides/migrate-change https://developer.salesforce.co ...
- ActiveMQ的多种部署方式--ActiveMQ学习之二
单点的ActiveMQ作为企业应用无法满足高可用和集群的需求,所以ActiveMQ提供了master-slave.broker cluster等多种部署方式,但通过分析多种部署方式之后我认为需要将两种 ...
- ThinkPHP 学习笔记 ( 一 ) 项目部署:应用部署方式与模块分组部署方式
/** * ThinkPHP version 3.1.3 */ ThinkPHP ( 官方网站:http://www.thinkphp.cn/ ) 目前最新版本是 3.2.2,它要求 PHP 的版本高 ...
- NBIoT三种部署方式【转】
转自:https://472880.kuaizhan.com/89/34/p441944286fccf2 本文作者:吴老司撩通信 本文来源:EETOP NB-IoT支持在频段内(In-Band).保护 ...
- Activiti流程定义部署方式
1 bpmn png方式部署 ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); /**部署流程定义(从cl ...
- activiti 流程部署的各种方式
流程资源可以是各种类型的文件,在启动流程或流程实例运行过程中会被读取.下面介绍常用的流程资源. 一.流程资源 流程定义文件:扩展名为bpmn20.xml和bpmn; 流程定义的图片:用BPMN2.0规 ...
- Activiti 学习(二)—— Activiti 流程定义和部署
概述 在这一节,我们将创建一个 Activit 工作流,并启动这个流程,主要包含以下几个步骤: 定义流程,按照 BPMN 的规范,使用流程定义工具,用流程符号把整个流程描述出来 部署流程,把画好的流程 ...
随机推荐
- day05 模块以及内置常用模块用法
内置常用模块详解: 1 time 2 datetime 3 random 4 os 5 sys 6 shutil 7 shelve 8 xml 9 configparser 10 hashlib ...
- PYday16&17-设计模式\选课系统习题
1.设计模式:对程序做整体得规划设计,这样做是为了更好的实现功能,使代码的可扩展性更好有27种常见的设计模式.流行的设计模式参考书:GoF设计模式.大话设计模式设计模式是为了更好的实现模块间的解耦,便 ...
- 30、自定义gridview
要想实现自定义gridview效果,有下边几个步骤: 1.定义grivew中的item的xml文件 假如item需要显示一个图片,图片下边显示文字: <?xml version="1. ...
- 03_HibernateSessionFactory源码分析
文章导读: 讲解了一个线程为什么要使用同一个connection, 我们分析了HiberatenSessionFactory的实现机制, 然后根据Hibernate的写法重构了我们的代码. 最后测试可 ...
- [POJ 1008] Maya Calendar C++解题
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 62297 Accepted: 192 ...
- loadrunner参数化数据分配方法
数据分配方法: 在“Select next row“列表中选择一个数据分配方法,以指示在Vuser脚本执行期间如何从参数文件中取得数据.选项包括”Sequential“.“Random”.“Uniqu ...
- SpringMVC对于跨域访问的支持
原文地址:http://docs.spring.io/spring/docs/5.0.0.RC2/spring-framework-reference/web.html#mvc-introductio ...
- hibernate悲观锁,乐观锁
业务逻辑的实现过程中,往往需要保证数据访问的排他性.因此,我们就需要通过一些机制来保证这些数据在某个操作过程中不会被外界修改,这样的机制,在这里,也就是所谓的“锁”,即给我们选定的目标数据上锁,使其无 ...
- 刷题总结——大工程(bzoj3611)
题目: Description 国家有一个大工程,要给一个非常大的交通网络里建一些新的通道. 我们这个国家位置非常特殊,可以看成是一个单位边权的树,城市位于顶点上. 在 2 个国家 a,b 之间建 ...
- 【CTSC2010】产品销售(bzoj1920)
数据结构优化网络流…… 重新定义一下题目的各种条件: 第 $i$ 天能生产 $a_i$ 个物品: 第 $i$ 天有 $b_i$ 个物品的需求: 每存储一天物品(把订单提前一天)需要 $c_i$ 的花费 ...
