JBPM4.4业务流程管理框架详细解读
1. 什么是JBPM4.4业务流程管理框架?
JBPM,全称是Java Business Process Management(业务流程管理),它是覆盖了业务流程管理、工作流、服务协作等领域的一个开源的、灵活的、易扩展的可执行流程语言框架。
相关概念:a: 从一个节点到另一个节点==>流转。b:程序预先设定的行为==>活动。
2. JBPM工作流的特点
2.1 直观描述业务流程
![](/assets/blank.gif)
2.2 使用Hibernate管理数据库
3 ProcessEngine的核心服务
4 怎么用JBMP?
4.1 所需环境与相关资源
4.2 安装说明
第一步:
Help -->Install New Software...
ClickAdd...
In dialogAdd Site dialog, clickArchive...
Navigate toinstall/src/gpd/jbpm-gpd-site.zip and click 'Open'
ClickingOK in theAdd Site dialog will bring you back to the dialog 'Install'
Select thejPDL 4 GPD Update Site that has appeared
ClickNext... and thenFinish
Approve the license
Restart eclipse when that is asked
第二步:
流程定义文件的xsd文件的路径为:JBPM_HOME/src/jpdl-4.4.xsd。
添加到Eclipse中的方法为(jBPM4.4User Guide, 2.11.5. Adding jPDL 4 schema tothe catalog):
ClickWindow -->Preferences
SelectXML -->XML Catalog
Click 'Add...'
The 'Add XML Catalog Entry' dialog opens
Click the button with the map-icon next to location and select 'FileSystem...'
In the dialog that opens, select filejpdl-4.4.xsd in the src directoryof the jBPM installation root.
Click 'Open' and close all the dialogs
第三步:添加jar包
1. JBPM解压目录下有一个重要的jar包:jbpm.jar。
2. JBPM/lib目录下的jar很多,不要添加的jar包:servlet-api.jar、junit.jar(尤其不要添加)。
3. 所使用的数据库对应的驱动的jar包在上面lib目录当中已经有了,所以不需要添加了。
第四步: 添加配置文件
<?xml version="1.0" encoding="UTF-8"?><jbpm-configuration><import resource="jbpm.default.cfg.xml" /><import resource="jbpm.businesscalendar.cfg.xml" /><import resource="jbpm.tx.hibernate.cfg.xml" /><import resource="jbpm.jpdl.cfg.xml" /><import resource="jbpm.bpmn.cfg.xml" /><import resource="jbpm.identity.cfg.xml" /><!-- Job executor is excluded for running the example test cases. --><!-- To enable timers and messages in production use, this should be included. --><!--<import resource="jbpm.jobexecutor.cfg.xml" />--></jbpm-configuration>
jbpm.cfg.xml
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory><!-- 数据库信息 --><property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property><property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property><property name="hibernate.connection.url">jdbc:mysql:///jbpm4test</property><property name="hibernate.connection.username">root</property><property name="hibernate.connection.password">root</property><!-- 其他配置 --><property name="hibernate.hbm2ddl.auto">update</property><!-- 导入映射文件 --><mapping resource="jbpm.repository.hbm.xml" /><mapping resource="jbpm.execution.hbm.xml" /><mapping resource="jbpm.history.hbm.xml" /><mapping resource="jbpm.task.hbm.xml" /><mapping resource="jbpm.identity.hbm.xml" /></session-factory>
</hibernate-configuration>
jbpm.hibernate.cfg.xml
4.3 JBPM工作流的使用
1. 创建jbpm的文件
![](/assets/blank.gif)
2. 绘制工作流程图
![](/assets/blank.gif)
<?xml version="1.0" encoding="UTF-8"?><process name="员工请假流程" xmlns="http://jbpm.org/4.4/jpdl"><start g="77,20,48,48" name="start1"><transition g="-71,-17" name="to 提交申请" to="提交申请"/></start><end g="77,352,48,48" name="end1"/><task assignee="ww" g="55,268,92,52" name="总经理审批"><transition g="-47,-17" name="to end1" to="end1"/></task><task assignee="ls" g="55,184,92,52" name="部门经理审批"><transition g="-26,-8" name="同意" to="总经理审批"/></task><task assignee="#{applyInfo.applier.userName}" g="55,100,92,52" name="提交申请"><transition g="-96,-16" name="to 部门经理审批" to="部门经理审批"/></task>
</process>
保存之后相应的生成png格式的对应的图片。
4.4 JBPM工作流编程实例
4.4.1 JBPM建表
// 建表@Testpublic void createSchema() {new org.hibernate.cfg.Configuration()//.configure("jbpm.hibernate.cfg.xml")//.buildSessionFactory();}
4.4.2 创建ProcessEngine对象
private static ProcessEngine processEngine = new Configuration()//.setResource("jbpm.cfg.xml")//.buildProcessEngine();
private ProcessEngine processEngine = new Configuration().buildProcessEngine();
3. 通过默认的配置文件生成单例的processEngine对象
private ProcessEngine processEngine = Configuration.getProcessEngine();
4.4.3 部署流程定义
<span style="white-space:pre"> </span>// 部署流程定义@Testpublic void deployProcessDefinition(){String reponseStr = processEngine.getRepositoryService()//.createDeployment()//.addResourceFromClasspath("test/test.jpdl.xml")//这里目录需要根据自己的目录确定.addResourceFromClasspath("test/test.png")//.deploy();System.out.println(reponseStr);// 10001}
4.4.4 启动流程实例
// 启动流程实例// jbpm4_execution@Testpublic void testStartProcessInstance() throws Exception {ProcessInstance <strong style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"></strong><pre name="code" class="java" style="display: inline !important;">processInstance
= processEngine.getExecutionService().startProcessInstanceByKey("test");System.out.println("流程实例启动成功:id=" +
processInstance <strong style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"></strong><pre name="code" class="java" style="display: inline !important;">.getId() //
+ ", state=" +
processInstance
.getState() // 状态+ ", processDefinitionId=" +
processInstance
.getProcessDefinitionId()); // 所使用的流程定义的ID} 2. 通过key获取并直接启动实例
// 启动实例@Testpublic void startProcessInstance() {processEngine.getExecutionService().startProcessInstanceByKey("test");}
4.4.5 查看个人的任务列表
// 查询任务列表@Testpublic void findTaskList() {List<Task> taskList = processEngine.getTaskService().findPersonalTasks("员工");System.out.println("个人任务列表");System.out.println(taskList);for(Task task : taskList){System.out.println("id= " + task.getId() + ", name = " + task.getName() + ", assignee = " + task.getAssignee());}}
4.4.6 查询所有的流程定义
// 查询所有@Testpublic void findAll() throws Exception {// 查询List<ProcessDefinition> list = processEngine.getRepositoryService()//.createProcessDefinitionQuery()//// 过滤条件// .processDefinitionKey("")//// .processDefinitionNameLike("%xx%")//// 排序条件// .orderAsc(ProcessDefinitionQuery.PROPERTY_KEY)//// .orderDesc(ProcessDefinitionQuery.PROPERTY_VERSION)//// 执行查询// .uniqueResult();// .count();// .page(firstResult, maxResults)//.list();// 显示for (ProcessDefinition pd : list) {System.out.println("id=" + pd.getId()// 格式为:{key}-{version},用于唯一的标识一个流程定义+ ", name=" + pd.getName()// 流程定义的名称,jpdl.xml中根元素的name属性的值+ ", key=" + pd.getKey()// 流程定义的key,jpdl.xml中根元素的key属性的值,默认是name属性的值+ ", version=" + pd.getVersion()// 自动生成的,同一个名称的第一个为1,以后的自动加1.+ ", deploymentId=" + pd.getDeploymentId()); // 所属的部署对象}}
4.4.7 查询最新版的流程定义
// 查询所有最新版本的流程定义@Testpublic void findAllLatestVersions() throws Exception {// 查询所有,让所有最大的版本都排到最后面List<ProcessDefinition> all = processEngine.getRepositoryService()//.createProcessDefinitionQuery()//.orderAsc(ProcessDefinitionQuery.PROPERTY_VERSION)//.list();// 过滤出所有最新的版本Map<String, ProcessDefinition> map = new HashMap<String, ProcessDefinition>();for (ProcessDefinition pd : all) {map.put(pd.getKey(), pd);}// 显示for (ProcessDefinition pd : map.values()) {System.out.println("id=" + pd.getId()// 格式为:{key}-{version},用于唯一的标识一个流程定义+ ", name=" + pd.getName()// 流程定义的名称,jpdl.xml中根元素的name属性的值+ ", key=" + pd.getKey()// 流程定义的key,jpdl.xml中根元素的key属性的值,默认是name属性的值+ ", version=" + pd.getVersion()// 自动生成的,同一个名称的第一个为1,以后的自动加1.+ ", deploymentId=" + pd.getDeploymentId()); // 所属的部署对象}}
4.4.8 删除流程定义
// 删除@Testpublic void deleteById() throws Exception {String deploymentId = "80001";// // 删除指定的部署对象(流程定义),如果有关联的执行信息,就会报错// processEngine.getRepositoryService().deleteDeployment(deploymentId);// 删除指定的部署对象(流程定义),如果有关联的执行信息,会被同时删除processEngine.getRepositoryService().deleteDeploymentCascade(deploymentId);}
// 删除指定key的所有版本的流程定义@Testpublic void deleteByKey() throws Exception {// 查询出指定key的所有版本的流程定义List<ProcessDefinition> list = processEngine.getRepositoryService()//.createProcessDefinitionQuery()//.processDefinitionKey("helloworld")//.list();// 一一删除for (ProcessDefinition pd : list) {processEngine.getRepositoryService().deleteDeploymentCascade(pd.getDeploymentId());}}
4.4.9 查看流程图
// 查看流程图(xxx.png)@Testpublic void getImageResource() throws Exception {String deploymentId = "50001";String resourceName = "helloworld/helloworld.png";// 获取指定部署对象中的所有资源的名称Set<String> names = processEngine.getRepositoryService().getResourceNames(deploymentId);System.out.println("所有的资源名称:");for (String name : names) {System.out.println("\t" + name);}// 获取指定部署对象中的指下资源的内容InputStream in = processEngine.getRepositoryService().getResourceAsStream(deploymentId, resourceName);// 保存到c盘OutputStream out = new FileOutputStream("c:/process.png");for (int b = -1; (b = in.read()) != -1;) {out.write(b);}in.close();out.close();}
4.4.10 向后执行一步
// 向后执行一步@Testpublic void testSignalExecution() throws Exception {String executionId = "test.130001";processEngine.getExecutionService().signalExecutionById(executionId);// processEngine.getExecutionService().signalExecutionById(executionId, parametersMap); // 离开前先设置一些流程变量// processEngine.getExecutionService().signalExecutionById(executionId, signalName); // 使用指定名称的Transition离开本活动// processEngine.getExecutionService().signalExecutionById(executionId, signalName, parameters) // 离开前先设置一些流程变量,再使用指定名称的Transition离开本活动}
4.4.11 办理任务
// 办理任务@Testpublic void testCompleteTask() throws Exception {String taskId = "130002";processEngine.getTaskService().completeTask(taskId);}
4.4.12 设置流程变量
// 设置流程变量@Testpublic void testSetVariable() throws Exception {String executionId = "test.150001";processEngine.getExecutionService().setVariable(executionId, "请假天数", 15);}
// 获取流程变量@Testpublic void testGetVariable() throws Exception {String executionId = "test.150001";Integer days = (Integer) processEngine.getExecutionService().getVariable(executionId, "请假天数");System.out.println("请假天数 = " + days);}
{ExecutionService executionService = processEngine.getExecutionService();TaskService taskService = processEngine.getTaskService();// ============ 设置变量 ========================executionService.setVariable(executionId, name, value); // 设置一个变量executionService.setVariables(executionId, variablesMap); // 设置多个变量taskService.setVariables(taskId, variables); // 设置多个变量executionService.startProcessInstanceByKey(processDefinitionKey, variablesMap); // 启动流程实例时,先设置一些变量taskService.completeTask(taskId, variablesMap); // 真正办理完任务前先设置一些变量// ============ 获取变量 ========================executionService.getVariable(executionId, variableName); // 获取一个变量executionService.getVariableNames(executionId); // 返回Set<String>,是所有变量的名称集合executionService.getVariables(executionId, variableNames); //获取多个变量,返回Map<String,Object>,表示指定名称的变量信息taskService.getVariable(taskId, variableName);taskService.getVariableNames(taskId);taskService.getVariables(taskId, variableNames);}
4.4.13 流程执行
@Testpublic void testProcess() throws Exception {// 部署流程定义InputStream in = this.getClass().getResourceAsStream("test.jpdl.xml");String deploymentId = processEngine.getRepositoryService()// .createDeployment()//.addResourceFromInputStream("test.jpdl.xml", in)//.deploy();System.out.println("部署流程定义完毕:deploymentId = " + deploymentId);// 启动流程实例ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("test");System.out.println("流程实例启动完毕:processInstanceId = " + pi.getId());// 完成第一步“提交申请”的任务,要使用指定的Transition离开当前活动Task task = processEngine.getTaskService()//.createTaskQuery()// 获取本流程实例中当前情况下仅有的一个任务.processInstanceId(pi.getId())//.uniqueResult();String transitionName1 = "to 部门经理审批";String transitionName2 = "to 总经理审批";processEngine.getTaskService().completeTask(task.getId(), transitionName2); // 使用指定名称的Transition离开本活动}
4.4.14 分配任务
public class AssignmentHandlerImpl implements AssignmentHandler {// 计算此任务的办理人,并分配任务@Overridepublic void assign(Assignable assignable, OpenExecution execution) throws Exception {System.out.println("---> AssignmentHandlerImpl.assign()");// 计算办理人String userId = "李经理--";// 分配个人任务assignable.setAssignee(userId); // 指定个人任务的办理人// // 分配组任务// assignable.addCandidateUser("小A"); // 添加一个候选人(组任务)// assignable.addCandidateUser("小B"); // 添加一个候选人(组任务)// assignable.addCandidateUser("小C"); // 添加一个候选人(组任务)}}
4.4.15 组任务与分配
public class ProcessTest {private static ProcessEngine processEngine = Configuration.getProcessEngine();@Testpublic void testProcess() throws Exception {// 部署流程定义InputStream in = this.getClass().getResourceAsStream("test.jpdl.xml");String deploymentId = processEngine.getRepositoryService()// .createDeployment()//.addResourceFromInputStream("test.jpdl.xml", in)//.deploy();System.out.println("部署流程定义完毕:deploymentId = " + deploymentId);// 启动流程实例Map<String, Object> variables = new HashMap<String, Object>();variables.put("manager", "王经理");variables.put("userIds", "小A,小B,小C,小D");ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("test", variables);System.out.println("流程实例启动完毕:processInstanceId = " + pi.getId());}// 查询组任务列表@Testpublic void testFindMyGroupTaskList() throws Exception {String userId = "王工程师";// String userId = "赵工程师";// 查询// List<Task> list = processEngine.getTaskService().findGroupTasks(userId);// 分页List<Task> list = processEngine.getTaskService()//.createTaskQuery()//.candidate(userId)// 指定候选人,这是查询组任务.page(0, 100)// 分页.list();// 显示System.out.println("====== " + userId + "的个人任务列表 ======");for (Task task : list) {System.out.println("id=" + task.getId()//+ ", name=" + task.getName()//+ ", assignee=" + task.getAssignee()//+ ", createTime=" + task.getCreateTime()//+ ", executionId=" + task.getExecutionId());}}// 拾取任务@Testpublic void testTakeTask() throws Exception {String taskId = "310009";String userId = "王工程师";processEngine.getTaskService().takeTask(taskId, userId);}// 查询个人任务列表@Testpublic void testFindMyPersonalTaskList() throws Exception {String userId = "王工程师";// 查询// List<Task> list = processEngine.getTaskService().findPersonalTasks(userId);// 分页List<Task> list = processEngine.getTaskService()//.createTaskQuery()//.assignee(userId)// 指定办理人条件.page(0, 100)// 分页.list();// 显示System.out.println("====== " + userId + "的个人任务列表 ======");for (Task task : list) {System.out.println("id=" + task.getId()//+ ", name=" + task.getName()//+ ", assignee=" + task.getAssignee()//+ ", createTime=" + task.getCreateTime()//+ ", executionId=" + task.getExecutionId());}}// 直接指定任务的办理人@Testpublic void testAssignTask() throws Exception {String taskId = "310009";// String userId = null; // 退回到组任务列表String userId = "赵工程师";processEngine.getTaskService().assignTask(taskId, userId);}}
如需转载;请注明原文出处谢谢合作!
JBPM4.4业务流程管理框架详细解读相关推荐
- 刚刚,OpenStack 第 19 个版本来了,附28项特性详细解读!
刚刚,OpenStack 第 19 个版本来了,附28项特性详细解读! OpenStack Stein版本引入了新的多云编排功能,以及帮助实现边缘计算用例的增强功能. OpenStack由一系列相互关 ...
- Spring Boot 集成SnakerFlow流程引擎,简介、功能列表、详细解读、扩展点分析
文章目录 简介 功能列表 流程定义 任务参与者 参与者设置 动态添加.删除参与者 组支持 详细解读 Spring Boot集成 表定义 表详细说明: 字段详细说明: 常见操作 常规API 综合查询 模 ...
- NLP突破性成果 BERT 模型详细解读 bert参数微调
https://zhuanlan.zhihu.com/p/46997268 NLP突破性成果 BERT 模型详细解读 章鱼小丸子 不懂算法的产品经理不是好的程序员 关注她 82 人赞了该文章 Goo ...
- VINS-mono详细解读与实现
VINS-mono详细解读 VINS-mono详细解读 前言 Vins-mono是香港科技大学开源的一个VIO算法,https://github.com/HKUST-Aerial-Robotics/V ...
- R回归模型输出结果详细解读:summary、call、residuals、Coefficients、Assessing Model Fit
R回归模型输出结果详细解读:summary.call.residuals.Coefficients.Assessing Model Fit 目录 R回归模型输出结果详细解读:summary.call. ...
- MemCache超详细解读
MemCache是什么 MemCache是一个自由.源码开放.高性能.分布式的分布式内存对象缓存系统,用于动态Web应用以减轻数据库的负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高 ...
- CSS 详细解读定位属性 position 以及参数
Css 详细解读定位属性 position 以及参数 position 定位属性,是CSS中非常重要的属性.除了文档流布局,就是定位布局了.本来我对这个问题没有放在心上,毕竟写了这么多年的css,对p ...
- MemCache详细解读
MemCache是什么 MemCache是一个自由.源码开放.高性能.分布式的分布式内存对象缓存系统,用于动态Web应用以减轻数据库的负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高 ...
- 直播 | 腾讯天衍实验室张子恒:详细解读天衍实验室知识图谱对齐技术
「AI Drive」是由 PaperWeekly 和 biendata 共同发起的学术直播间,旨在帮助更多的青年学者宣传其最新科研成果.我们一直认为,单向地输出知识并不是一个最好的方式,而有效地反馈和 ...
最新文章
- 如何定位并优化慢查询Sql
- magic_quotes_gpc和magic_quotes_runtime的区别和用法详解
- 的it生活_IT圈生活图鉴篇三丨下班后的突变画风
- 为什么静态成员、静态方法中不能用this和super关键字
- DDS发生器的verilog实现(三)
- .NET6之MiniAPI(十二):引入EntityFramewor
- Vue+Element导入导出Excel
- Ubuntu 14.04数据库服务器--mysql的安装和配置
- Python数据挖掘-词频统计-实现
- 人工智能还能登上微博热搜?热搜关键词你得看看!
- CS224N刷题——Assignment1.3_word2vec
- nodejs首个框架开发(先只发个连接,有空再写)
- Python基础(dict类)
- 创建Django项目
- 【无捆绑,可修改主页】系统之家 win7 32位64位极度纯净版系统(每月更新)
- 软件测试的意义究竟是什么?
- 软件测试周刊(第54期):管他乐观还是悲观,都滚蛋,干就完了。
- 渗透测试如何学习? (*╹▽╹*) 信息收集 ~ 其一
- [MSSQL2005]再看CTE
- 量子计算机三种,MIT发现第三种磁性 可造量子计算机?
热门文章
- 大数据框架之Zookeeper详解
- IAR EW8051-8.1编译ZStack时,出现警告Warning[Pe069]: integer conversion resulted in truncation的解决办法
- 缩放图片至固定大小,尺寸不足以0填充
- java修炼之多线程学习心得
- ISO C 与POSIX 的关系
- JAVA中输出分两栏,老司机搞定Java 设置Word分栏
- 可以查看计算机主要自启动项的技术,电脑中怎么查看启动项
- Centos7+Elasticsearch7.4.2+Kibana+IK分词+ElasticHD 安装配置以及集群搭建
- 【前端】零基础带你入门前端< 三 > —— 实现手机通讯录(微信通讯录)等
- 帝国cms缩略图:网站不同地方生成不同的缩略图