JPDL 全称JBossjBPMProcessDefinitionLanguage,是JBPM的流程定义语言。
JPDL流程定义语言主要掌握以下几种:
1.process (流程)
2.transition (连线、转移)
3.start (开始活动)
4.end、end-error、end-cancel (结束活动)
5.state (状态活动)
6.task (任务活动)
7.decision (判断活动)
8.fork、join (分支/聚合活动
顶级元素 process 定义
name用于显示,通常定义中文
key 用于代码操作,通常定义英文
version 版本号,不指定,相同key流程,version自动+1(如果指定version不要和其它冲突)
在 jbpm4_deployprop 生成 pdId 流程定义id = pdKey + “-” + pdVersion
发布流程保证,key和name 完全相同
代码示例:
process.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<process key="process" name="测试流程" xmlns="http://jbpm.org/4.4/jpdl">
<!-- 根节点 -->
<start g="235,30,48,48" name="start1">
<transition g="-47,-17" name="to 请假" to="请假"/>
</start>
<end g="251,315,48,48" name="end1"/>
<task g="223,128,92,52" name="请假">
<transition g="-47,-17" name="to 审批" to="审批"/>
</task>
<task g="231,211,92,52" name="审批">
<transition g="-47,-17" name="to end1" to="end1"/>
</task>
</process>
ProcessTest.java
package com.my.jbpm.jpdl;
import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.RepositoryService;
import org.junit.Test;
public class ProcessTest {
@Test
// 发布process.jpdl.xml
public void demo(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//获得Service
RepositoryService repositoryService = processEngine.getRepositoryService();
//发布
repositoryService.createDeployment().addResourceFromClasspath("process.jpdl.xml").deploy();
}
}
Transition 节点(流转节点)
一个活动中可以指定一个或多个transition
开始活动只能有一个transition
结束活动没有 transition
其它活动可以有1条或者多条transition
如果只有一个,可以不指定名称,如果有多个,则要分别指定唯一名称
无名称transition
executionService.signalExecutionById(executionId)
有名称transition
executionService.signalExecutionById(executionId, transitionName)
定义transition元素,可以不写name属性,成为默认transition节点
在向后流转时,如果没有transition的name属性,将使用 默认transition节点(没有name属性的transition )
代码示例:
transition.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<process name="transition" xmlns="http://jbpm.org/4.4/jpdl">
<start g="280,9,48,48" name="start1">
<transition g="-53,-17" name="to task1" to="task1"/>
</start>
<end g="290,299,48,48" name="end1"/>
<task g="269,89,92,52" name="task1">
<!-- 没有name的transition成为 默认transition -->
<transition to="task2"/>
<transition g="-53,-17" name="to task3" to="task3"/>
</task>
<task g="157,182,92,52" name="task2">
<transition g="-47,-17" name="to end1" to="end1"/>
</task>
<task g="376,186,92,52" name="task3">
<transition g="-47,-17" name="to end1" to="end1"/>
</task>
</process>
TransitionTest.java
package com.my.jbpm.jpdl;
import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.junit.Test;
public class TransitionTest {
@Test
//发布 启动 transition.jpdl.xml
public void demo1(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//发布流程
processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("transition.jpdl.xml").deploy();
//启动实例
processEngine.getExecutionService().startProcessInstanceByKey("transition");
}
@Test
//完成task1 任务
public void demo2(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//向后流转
//processEngine.getExecutionService().signalExecutionById("transition.10007"); // 没有指定name 使用默认transition
processEngine.getExecutionService().signalExecutionById("transition.10007","to task3");// executionId 在 execution表 ID_
}
}
start和end 节点
start 开始活动
代表流程的开始边界,一个流程有且只能有一个Start活动。开始活动只能指定一个Transition。在流程实例启动后,会自动的使用这个唯一的Transition离开开始活动,到一下个活动
end 结束活动
代表流程的结束边界,可以有多个,也可以没有。如果有多个,则到达任一个结束活动,整个流程就都结束了;如果没有,则到达最后那个没有Transition的活动,流程就结束了
中止流程代码
processEngine.getExecutionService().endProcessInstance(processInstanceId, ProcessInstance.STATE_ENDED);
在任意节点,都能够结束流程
state 节点 (状态节点,当前状态发生改变,向后流转)
State节点,等待含义,当服务器处理一些数据后,实现自动触发流转 executionService.signalExecutionById
代码示例:
state.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<process name="state" xmlns="http://jbpm.org/4.4/jpdl">
<start g="264,13,48,48" name="start1">
<transition g="-71,-17" name="to 用户注册" to="用户注册"/>
</start>
<end g="263,284,48,48" name="end1"/>
<task g="245,92,92,52" name="用户注册">
<transition g="-95,-17" name="to 发送激活邮件" to="发送激活邮件"/>
</task>
<state g="241,182,92,52" name="发送激活邮件">
<transition g="-47,-17" name="to end1" to="end1"/>
</state>
</process>
StateTest.java
package com.my.jbpm.jpdl;
import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.junit.Test;
public class StateTest {
@Test
//发布流程,启动实例
public void demo1(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//发布流程
processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("state.jpdl.xml").deploy();
//启动实例
processEngine.getExecutionService().startProcessInstanceByKey("state");
}
@Test
//用户注册
public void demo2(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//人为办理任务
processEngine.getTaskService().completeTask("40008");
}
@Test
//发送激活邮件
public void demo3(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//通过 state节点
processEngine.getExecutionService().signalExecutionById("state.40007");
}
}
decision 判断节点
使用expression,如:expr=”#{表达式}”
使用Handler,要实现DecisionHandler接口
如果同时配置了expression与Handler,则expression有效,忽略Handler
代码示例:
方式一 : 通过 expr=#{表达式} 控制程序流转 ,在执行到decisition节点前,必须向流程变量中,存放 condition 变量, expr=”#{condition}” 获取流程变量,变量值和 每个transition 节点name属性比较,哪个一致,就流向哪个transition.
decision1.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<process name="decision1" xmlns="http://jbpm.org/4.4/jpdl">
<start g="276,-7,48,48" name="start1">
<transition g="-59,-17" name="to 逛公园" to="逛公园买票"/>
</start>
<end g="283,346,48,48" name="end1"/>
<task g="256,61,92,52" name="逛公园买票">
<transition g="-83,-17" name="to exclusive1" to="exclusive1"/>
</task>
<decision expr="#{condition}" g="274,133,48,48" name="exclusive1">
<transition g="-83,-17" name="to 老年人免票" to="老年人免票"/>
<transition g="-71,-17" name="to 儿童半价" to="儿童半价"/>
<transition g="-71,-17" name="to 普通售票" to="普通售票"/>
</decision>
<task g="81,220,92,52" name="老年人免票">
<transition g="-47,-17" name="to end1" to="end1"/>
</task>
<task g="259,216,89,56" name="儿童半价">
<transition g="-47,-17" name="to end1" to="end1"/>
</task>
<task g="448,217,92,52" name="普通售票">
<transition g="-47,-17" name="to end1" to="end1"/>
</task>
</process>
DecisionTest.java
@Test
//发布流程定义,启动流程实例
public void demo1(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//发布流程
processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("decision1.jpdl.xml").deploy();
//启动实例
processEngine.getExecutionService().startProcessInstanceByKey("decision1");
}
@Test
//逛公园买票
public void demo2(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//完成任务
//设置 condition 变量
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("condition", "to 儿童半价");
processEngine.getTaskService().setVariables("70008", variables);
processEngine.getTaskService().completeTask("70008");
}
方式二 : DecisionHandler 接口实现类,控制判断节点流转
MyDecisionHandler.java
package com.my.jbpm.handler;
import org.jbpm.api.jpdl.DecisionHandler;
import org.jbpm.api.model.OpenExecution;
@SuppressWarnings("serial")
public class MyDecisionHandler implements DecisionHandler{
@Override
public String decide(OpenExecution openExecution) {
// 根据流程变量 age,判断是老年人 、儿童 、正常人
int age = Integer.parseInt((String)openExecution.getVariable("age"));
if(age > 65){
return "to 老年人免票";
}else if(age < 4){
return "to 儿童半价";
}else{
return "to 普通售票";
}
}
}
decision2.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<process name="decision2" xmlns="http://jbpm.org/4.4/jpdl">
<start g="274,4,48,48" name="start1">
<transition g="-59,-17" name="to 逛公园" to="逛公园买票"/>
</start>
<end g="289,436,48,48" name="end1"/>
<task g="256,69,92,52" name="逛公园买票">
<transition g="-83,-17" name="to exclusive1" to="exclusive1"/>
</task>
<decision g="276,147,48,48" name="exclusive1">
<!-- 指定一个handler 类 -->
<handler class="com.my.jbpm.handler.MyDecisionHandler" />
<transition g="-83,-17" name="to 老年人免票" to="老年人免票"/>
<transition g="-71,-17" name="to 儿童半价" to="儿童半价"/>
<transition g="-71,-17" name="to 普通售票" to="普通售票"/>
</decision>
<task g="75,270,92,52" name="老年人免票">
<transition g="-47,-17" name="to end1" to="end1"/>
</task>
<task g="263,271,92,52" name="儿童半价">
<transition g="-47,-17" name="to end1" to="end1"/>
</task>
<task g="461,272,92,52" name="普通售票">
<transition g="-47,-17" name="to end1" to="end1"/>
</task>
</process>
DecisionTest.java
@Test
//发布流程定义,启动流程实例
public void demo3(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//发布流程
processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("decision2.jpdl.xml").deploy();
//启动实例
processEngine.getExecutionService().startProcessInstanceByKey("decision2");
}
@Test
// 完成逛公园 任务
public void demo4(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//完成任务
//设置 age 变量
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("age", "80");
processEngine.getTaskService().setVariables("90008", variables);
processEngine.getTaskService().completeTask("90008");
}
fork、join(分支/聚合活动)
解决流程中并发任务问题 (不强调 任务发生顺序)
fork 必须和 join 同时出现
运行到fork节点后,每个分支,产生一个子流程,每个子流程存放当前任务节点
分支节点,是一个流程的当前任务 变为多个
代码示例:
fork.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<process name="fork" xmlns="http://jbpm.org/4.4/jpdl">
<start g="254,-4,48,48" name="start1">
<transition g="-47,-17" name="to 报销" to="报销"/>
</start>
<end g="268,395,48,48" name="end1"/>
<task g="234,75,92,52" name="报销">
<transition g="-53,-17" name="to fork1" to="fork1"/>
</task>
<fork g="257,142,48,48" name="fork1">
<transition g="-71,-17" name="to 部门经理" to="部门经理"/>
<transition g="-71,-17" name="to 财务总监" to="财务总监"/>
</fork>
<join g="267,308,48,48" name="join1">
<transition g="-47,-17" name="to end1" to="end1"/>
</join>
<task g="69,219,92,52" name="部门经理">
<transition g="-53,-17" name="to join1" to="join1"/>
</task>
<task g="396,220,107,48" name="财务总监">
<transition g="-53,-17" name="to join1" to="join1"/>
</task>
</process>
ForkJoinTest.java
package com.my.jbpm.jpdl;
import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.junit.Test;
public class ForkJoinTest {
@Test
//发布流程定义,启动流程实例
public void demo1(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//发布流程
processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("fork.jpdl.xml").deploy();
//启动实例
processEngine.getExecutionService().startProcessInstanceByKey("fork");
}
@Test
//进行报销 ,完成任务
public void demo2(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//完成任务
processEngine.getTaskService().completeTask("8");
}
@Test
//完成每个分支的任务
public void demo3(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//完成任务
// processEngine.getTaskService().completeTask("10003"); //部门经理审批
processEngine.getTaskService().completeTask("10005"); //财务总监审批
}
}
task 节点(任务节点)
个人任务, 指定个人任务负责人,三种方式
1.通过assignee属性 指定任务负责人
2.通过AssignmentHandler指定负责人
3.通过TaskService 直接更换负责人
个人任务常见操作 :
查询个人任务 taskService.findPersonalTasks(userId);
办理个人任务 taskService.completeTask(taskId)
代码示例:
MyAssignmentHandler.java
package com.my.jbpm.handler;
import org.jbpm.api.model.OpenExecution;
import org.jbpm.api.task.Assignable;
import org.jbpm.api.task.AssignmentHandler;
@SuppressWarnings("serial")
public class MyAssignmentHandler implements AssignmentHandler{
@Override
public void assign(Assignable assignable, OpenExecution openExecution) throws Exception {
// 个人任务
assignable.setAssignee("老李");// 指定个人任务负责人
}
}
personaltask.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<process name="personaltask" xmlns="http://jbpm.org/4.4/jpdl">
<start g="295,6,48,48" name="start1">
<transition g="-95,-17" name="to 员工提出申请" to="员工提出申请"/>
</start>
<end g="292,370,48,48" name="end1"/>
<task assignee="张三" g="270,85,92,52" name="员工提出申请">
<transition g="-95,-17" name="to 部门经理审批" to="部门经理审批"/>
</task>
<task assignee="#{manager}" g="271,176,92,52" name="部门经理审批">
<transition g="-83,-17" name="to 总经理审批" to="总经理审批"/>
</task>
<task g="273,265,92,52" name="总经理审批">
<assignment-handler class="com.my.jbpm.handler.MyAssignmentHandler"/>
<transition g="-47,-17" name="to end1" to="end1"/>
</task>
</process>
PersonalTaskTest.java
package com.my.jbpm.jpdl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.task.Task;
import org.junit.Test;
public class PersonalTaskTest {
@Test
//发布流程定义,启动流程实例
public void demo1(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//发布流程
processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("personaltask.jpdl.xml").deploy();
//启动实例
processEngine.getExecutionService().startProcessInstanceByKey("personaltask");
}
@Test
//查询个人任务,获得任务id
public void demo2(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//查询个人任务
List<Task> tasks = processEngine.getTaskService().findPersonalTasks("张三");
for (Task task : tasks) {
System.out.println(task.getId());
}
}
@Test
// 办理个人任务 (员工请假)
public void demo3(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//办理个人任务
Map<String, Object> map = new HashMap<String, Object>();
map.put("manager", "老王");
processEngine.getTaskService().setVariables("8", map);
processEngine.getTaskService().completeTask("8");
}
@Test
//办理个人任务 (部门经理审批)
public void demo4(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//办理个人任务
processEngine.getTaskService().completeTask("10002");
}
@Test
//改变任务的负责人
public void demo5(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//更换负责人
processEngine.getTaskService().assignTask("20001", "李四");
}
}
组任务,任务节点,指定一组人,组内每个人,都具有任务办理能力
组任务可以使用 三种方式指定
1.通过candidate-users 或者 candidate-groups 属性指定组任务负责人
2.通过 AssignmentHandler 程序为任务节点指定组任务负责人
3.直接对任务添加组用户 processEngine.getTaskService().addTaskParticipatingUser(taskId,userId, Participation.CANDIDATE);
查询组任务 : taskService.findGroupTasks(userId)
拾取任务(将组任务变为个人任务 ) : taskService.takeTask(taskId, userId) ;
改变任务的负责人 :
taskService.assignTask 可以改变任务的负责人
taskService.assignTask(taskId , null) ; 将任务负责人设置为null,重新变为组任务
JBPM系统内部提供三张表,管理用户和用户组
jbpm4_id_group 存放组信息
jbpm4_id_user 存放用户信息
jbpm4_id_memership 存放组和用户关系信息
必须先向系统 存入组和用户信息,才能使用 candidate-groups 属性
代码示例:
MyAssignmentHandler.java
package com.my.jbpm.handler;
import org.jbpm.api.model.OpenExecution;
import org.jbpm.api.task.Assignable;
import org.jbpm.api.task.AssignmentHandler;
@SuppressWarnings("serial")
public class MyAssignmentHandler implements AssignmentHandler{
@Override
public void assign(Assignable assignable, OpenExecution openExecution) throws Exception {
//组任务
assignable.addCandidateUser("小明");
assignable.addCandidateUser("小王");
assignable.addCandidateGroup("boss");// 指定任务负责组
}
}
grouptask.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<process name="grouptask" xmlns="http://jbpm.org/4.4/jpdl">
<start g="322,5,48,48" name="start1">
<transition g="-119,-17" name="to 员工提交请假申请" to="员工提交请假申请"/>
</start>
<end g="343,340,48,48" name="end1"/>
<!-- candidate-users 为任务一次指定多个负责的用户 -->
<task candidate-users="张三,李四,王五" g="290,81,131,53" name="员工提交请假申请">
<transition g="-95,-17" name="to 部门经理审批" to="部门经理审批"/>
</task>
<!-- candidate-groups 为任务指定一个负责组id -->
<!-- manager 是一个组的名字 -->
<task candidate-groups="manager" g="304,171,122,52" name="部门经理审批">
<transition g="-83,-17" name="to 总经理审批" to="总经理审批"/>
</task>
<task g="303,250,135,52" name="总经理审批">
<assignment-handler class="com.my.jbpm.handler.MyAssignmentHandler"/>
<transition g="-47,-17" name="to end1" to="end1"/>
</task>
</process>
GroupTaskTest.java
package com.my.jbpm.jpdl;
import java.util.List;
import org.jbpm.api.Configuration;
import org.jbpm.api.IdentityService;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.task.Participation;
import org.jbpm.api.task.Task;
import org.junit.Test;
public class GroupTaskTest {
@Test
//发布流程定义,启动流程实例
public void demo1(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//发布流程
processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("grouptask.jpdl.xml").deploy();
//启动实例
processEngine.getExecutionService().startProcessInstanceByKey("grouptask");
}
@Test
//查询组任务
public void demo2(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//查询组任务
List<Task> list = processEngine.getTaskService().findGroupTasks("李四");
System.out.println("长度:" + list.size());
for (Task task : list) {
System.out.println(task.getId());
}
}
@Test
//查询个人任务
public void demo3(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//查询个人任务
List<Task> list = processEngine.getTaskService().findPersonalTasks("张三");
System.out.println("长度:" + list.size());
for (Task task : list) {
System.out.println(task.getId());
}
}
@Test
//办理组任务,需要先对任务进行拾取
public void demo4(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//拾取任务
processEngine.getTaskService().takeTask("8", "张三");
}
@Test
//将拾取后 任务,恢复为组任务
public void demo5(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//将拾取的任务,放回到组内
processEngine.getTaskService().assignTask("8", null);
}
@Test
//办理请假任务
public void demo6(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//办理任务
processEngine.getTaskService().completeTask("8");
}
@Test
//要办理 经理审批 (创建组和用户)
public void demo7(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//获得对应Service
IdentityService identityService = processEngine.getIdentityService();
//建立manager组 和 对应用户
identityService.createGroup("manager"); // 创建组
identityService.createUser("1", "张", "老"); // 创建用户
identityService.createUser("2", "王", "老");
identityService.createUser("3", "黎", "老");
identityService.createMembership("1", "manager"); // 建立关系
identityService.createMembership("2", "manager");
}
@Test
//查询组任务 (经理审批)
public void demo8(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//查询组任务
List<Task> list = processEngine.getTaskService().findGroupTasks("1");// 老张
System.out.println("长度:" + list.size());
for (Task task : list) {
System.out.println(task.getId());
}
}
@Test
//拾取任务 (经理审批)
public void demo9(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//拾取任务
processEngine.getTaskService().takeTask("10001", "1");
}
@Test
//办理经理审批任务
public void demo10(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//办理任务
processEngine.getTaskService().completeTask("10001");
}
@Test
//为总经理审批 ,添加一个新的组用户
public void demo11(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//新增组用户
processEngine.getTaskService().addTaskParticipatingUser("30001", "小红", Participation.CANDIDATE);
}
}
swimlanes 泳道使用
泳道可以保证,在同一个流程中,多个任务节点,由同一个用户完成
比如财务报销流程中,在财务报销任务完成后, 确认签字直接成为个人任务,是财务报销任务完成用户。
代码示例:
swimlanes.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<process name="swimlanes" xmlns="http://jbpm.org/4.4/jpdl">
<!-- 定义泳道 -->
<swimlane candidate-users="张三,李四,王五" name="operator"/>
<start g="298,10,48,48" name="start1">
<transition g="-71,-17" name="to 财务报销" to="财务报销"/>
</start>
<end g="313,325,48,48" name="end1"/>
<task g="286,101,92,52" name="财务报销" swimlane="operator">
<transition g="-71,-17" name="to 确认签字" to="确认签字"/>
</task>
<task g="287,215,92,52" name="确认签字" swimlane="operator">
<transition g="-47,-17" name="to end1" to="end1"/>
</task>
</process>
SwimlanesTest.java
package com.my.jbpm.jpdl;
import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.junit.Test;
public class SwimlanesTest {
@Test
//发布流程定义,启动流程实例
public void demo1(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//发布流程
processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("swimlanes.jpdl.xml").deploy();
//启动实例
processEngine.getExecutionService().startProcessInstanceByKey("swimlanes");
}
@Test
//拾取
public void demo2(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//拾取任务
processEngine.getTaskService().takeTask("8", "张三");
}
@Test
//办理财务报销
public void demo3(){
//流程引擎
ProcessEngine processEngine = new Configuration().buildProcessEngine();
//办理任务
processEngine.getTaskService().completeTask("8");
}
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/12051.html