Activiti 流程部署方式 activi 动态部署

  • 目录
    • 概 述
      • 第一种方法:
      • 设计流程引擎:
      • 相关工具如下:
    • 分析:
  • 小结:
  • 参考资料和推荐阅读

LD is tigger forever,CG are not brothers forever, throw the pot and shine forever.
Modesty is not false, solid is not naive, treacherous but not deceitful, stay with good people, and stay away from poor people.
talk is cheap, show others the code and KPI, Keep progress,make a better result.
Survive during the day and develop at night。

目录

概 述

第一种方法:

Activiti的流程 部署方式有很多种方式,我们可以根据activit工作流引擎提供的ap方式进行部署。

设计流程引擎:

流程部署的方式在类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规范文件。适合动态的拓展。自定义。

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);

运行后查表:ACT_GE_BYTEARRAY:

selelct * from ACT_GE_BYTEARRAY;
流程的定义还是第一种方式的流程图,程序如下所示:

Deployment deploy2 =repositoryService2.createDeployment().addClasspathResource(“demo1.bpmn”).deploy();

addClasspathResource中的参数是根据classpath方式加载,如果demo1.bpmn路径在com.daling.ch1.ProcessEnginesDemo包下面则参数参入com/daling/ch1/ProcessEnginesDemo/demo1.bpmn

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 动态部署,请大家指正~

参考资料和推荐阅读

1.链接: 参考资料.

Activiti 流程部署方式 activi 动态部署(高级源码篇)相关推荐

  1. Android逆向之旅---动态方式破解apk前奏篇(Eclipse动态调试smail源码)

    一.前言 今天我们开始apk破解的另外一种方式:动态代码调试破解,之前说的主要采用的是静态方式,步骤也很简单,首先使用apktool来反编译apk,得到smail源码,然后分析smail代码,采用代码 ...

  2. 【SemiDrive源码分析】【X9芯片启动流程】08 - X9平台 lk 目录源码分析 之 目录介绍

    [SemiDrive源码分析][X9芯片启动流程]08 - X9平台 lk 目录源码分析 之 目录介绍 一./rtos/lk/ 目录结构分析 1.1 /rtos/lk_boot/ 目录结构分析 1.2 ...

  3. android浪漫樱花凋零动态壁纸应用源码

    android浪漫樱花凋零动态壁纸应用源码,是从那个安卓教程网拿过来的,本项目是一套基于安卓的樱花动态壁纸项目源码,安装以后桌面没有图标,但是可以在修改壁纸-动态壁纸中找到.我的分辨率是480×854 ...

  4. 简约动态时钟h5源码分享-可做桌面动态壁纸

    简约动态时钟h5源码分享-可做桌面动态壁纸

  5. HTML唯美雷姆时间动态特效网站源码+UI超好看

    正文: HTML唯美雷姆时间动态特效网站源码,一个UI非常好看的时钟网页源码,是动态的,但是由于我没办法放GIF图片,所以大家只能自己去体验了,演示图就是上方那个就是. 程序: wwwu.lanzou ...

  6. Android实现直播的博文和流程(全过程,超详细/附源码)

    为方便大家阅读,源码先行奉上 github源码链接 https://github.com/Recycle1/Live-video-demo csdn源码链接 https://download.csdn ...

  7. 深入浅出Mybatis系列(十)---SQL执行流程分析(源码篇)

    原文地址:http://www.cnblogs.com/dongying/p/4142476.html 最近太忙了,一直没时间继续更新博客,今天忙里偷闲继续我的Mybatis学习之旅.在前九篇中,介绍 ...

  8. Jdk动态代理 底层源码分析

    前言 java动态代理主要有2种,Jdk动态代理.Cglib动态代理,本文主要讲解Jdk动态代理的使用.运行机制.以及源码分析.当spring没有手动开启Cglib动态代理,即:<aop:asp ...

  9. JDK 动态代理之源码解析

    过几天我会分享spring AOP 的相关的代理的源码,为了让大家学好springAOP ,今天先分析jdk 的动态代理 1.首先创建一个接口和一个被代理的对象: package com.nandao ...

最新文章

  1. C# 程序打包成安装项目
  2. 一个简单的blog系统(十一) 增加文章检索功能
  3. Transformer在图像复原领域的降维打击,ETH提出SwinIR:各项任务全面领先
  4. Hadoop2异常分析(一):hdfs移动数据至 hive,为什么原数据没有了?
  5. java从小到大排序函数_利用随机函数产生10个1~100之间的整数,按从小到大的顺序排列输出...
  6. 极验创始人吴渊:恶意流量威胁新趋势,洞察网络黑产3大核心本质
  7. 算法代码中的循环矩阵在哪体现_「Machine Learning 学习小结」| 向量在梯度下降算法当中的应用...
  8. 【kafka】kafka 如何开启 kafka.consumer的监控指标项
  9. 不能错过!简单易懂的哈希表总结
  10. 开放源码的.NET 反编译工具 .NET IL调试工具 学习微软中间语言(MSIL)的绝佳工具 Dotnet IL Editor 推荐...
  11. 爱情四十八课,深情淡如水
  12. VMware下安装CentOS
  13. 阶段1 语言基础+高级_1-3-Java语言高级_08-JDK8新特性_第1节 常用函数接口_3_性能浪费的日志案例...
  14. unity Vuforia物体移动的方向用AR箭头表示出来
  15. [JNI]开发之旅(5)访问c/c++函数
  16. 图网络模型原理详解(Graph Network)
  17. lora网关软件设计_LoRa网关 - 舜为互联
  18. FPGA视频处理系统
  19. 入门3D建模学习教程,让你最快从小白到建模大师!
  20. 错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”

热门文章

  1. 渗透一个最近很火的闲鱼钓鱼网站
  2. matlab ps液化,photoshop液化工具崩溃怎么办 ps液化工具崩溃解决方法
  3. 有服务器端源码和客户端源码,C# 远程控制软件源码(含服务器端和客户端源码)...
  4. 【计算机网络 12,Java视频下载
  5. linux电脑主机国产,“小皮匠”换工作电脑,国产“中国芯”迷你主机能否够用?...
  6. 华为云微认证考试简介
  7. linux将时间转换成毫秒数,linux – 将jiffies转换为毫秒
  8. XCode 苹果开发者账号,无法本地编译项目,问题所在 The app identifier “xxxx“ cannot be registered to your development team
  9. 如何快速查询SCI期刊JCR和ISO缩写?
  10. 用于Brain Runners电子游戏的改进SmallNet脑电解码分类