分享一套j简单的JBPM入门视频
https://pan.baidu.com/s/1sNv5n0Xk3lXn-YSLxum2EQ
提取码:idfq
我是在eclipse当中安装的JBPM
安装好JBPM之后,创建一个java项目 ,整个JBPM运行所需要的包
(所需要的jar包在视频当中有详细区分,并且整合完成的直接复制使用就好)
数据库用的是MySql的我提前安装好了,并且是用的navicat连接的
jbpm.cfg.xml
jbpm.hibernate.cfg.xml
org.hibernate.dialect.MySQL5InnoDBDialect
com.mysql.jdbc.Driver
jdbc:mysql:///jbpm01
root
u04
update
true
true
log4j.properties
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:/mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=info, stdout
配置完成之後,我們用已經安裝好的JBPM插件画出我们要测试用的的流程图
具体修改流程的数值视频当中有解释,这里就不说了
先创建 QuickStartTest 类
package cn.itcast.jbpm.a_quickstart;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.NewDeployment;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
import org.jbpm.api.task.Task;
import org.junit.Test;
public class QuickStartTest {
@Test
//使用hibernate加载配置文件完成建表操作
public void testHibernateCreateTable(){
//能否使用hibernate加载配置文件,创建表
//加载hibernate.properties
org.hibernate.cfg.Configuration configuration= new org.hibernate.cfg.Configuration();
configuration.configure("jbpm.hibernate.cfg.xml");//默认加载jbpm.hibernate.cfg.xml
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session =sessionFactory.openSession();
session.close();
sessionFactory.close();
}
@Test
//使用jbpm方式建表
public void testJbpmCreateTable(){
//使用jbpm提供configuiation
org.jbpm.api.Configuration.getProcessEngine();
}
@Test
//部署流程
public void testDeploy(){
//获取引擎
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
//获得实例管理service
RepositoryService repositoryService = processEngine.getRepositoryService();
//创建一个部署对象
NewDeployment createDeployment = repositoryService.createDeployment();
createDeployment.addResourceFromClasspath("helloworld/helloworld.jpdl.xml");
createDeployment.addResourceFromClasspath("helloworld/helloworld.png");
// 发布
createDeployment.deploy();
}
@Test
//测试启动流程
public void testStartProccess(){
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
//启动流程 获得ExecutionService
ExecutionService executionService = processEngine.getExecutionService();
//启动 (通过看表才能知道id,使用较少)
// executionService.startProcessInstanceById("1");
//设计流程时,流程有name -----默认生成流程key
executionService.startProcessInstanceByKey("helloworld");
}
@Test
//查看个人任务
public void testFindPersonlTask(){
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
//查看任务
TaskService taskService = processEngine.getTaskService();
//查询个人任务
List tasks = taskService.findPersonalTasks("员工");
System.out.println(tasks.size());
for (Task task : tasks) {
System.out.println("任务id : " + task.getId());
System.out.println("任务名称: " + task.getName());
System.out.println("任务的办理人 : " + task.getAssignee());
System.out.println("执行流程实例id :" + task.getExecutionId());
System.out.println("----------------");
}
}
@Test
// 办理任务
public void testCompleteTask(){
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
// 查看任务
TaskService taskService = processEngine.getTaskService();
// 必须通过任务id进行办理
//taskService.completeTask("80002");
taskService.completeTask("90001");
}
}
//使用hibernate加载配置文件完成建表操作
先拿到JBPM的核心引擎(引擎包含很多的服务Service类,这些服务类每个都有明确的分工来处理流程的进度与数据处理)
@Test
//使用hibernate加载配置文件完成建表操作
public void testHibernateCreateTable(){
//能否使用hibernate加载配置文件,创建表
//加载hibernate.properties
org.hibernate.cfg.Configuration configuration= new org.hibernate.cfg.Configuration();
configuration.configure("jbpm.hibernate.cfg.xml");//默认加载jbpm.hibernate.cfg.xml
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session =sessionFactory.openSession();
session.close();
sessionFactory.close();
}
执行方法完成后数据库默认生成18张表
部署我们刚刚画好的请假流程,指定名称部署
@Test
//部署流程
public void testDeploy(){
//获取引擎
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
//获得实例管理service
RepositoryService repositoryService = processEngine.getRepositoryService();
//创建一个部署对象
NewDeployment createDeployment = repositoryService.createDeployment();
createDeployment.addResourceFromClasspath("helloworld/helloworld.jpdl.xml");
createDeployment.addResourceFromClasspath("helloworld/helloworld.png");
// 发布
createDeployment.deploy();
}
部署好请假流程之后,接下来就是要启动我们的请假流程
@Test
//测试启动流程
public void testStartProccess(){
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
//启动流程 获得ExecutionService
ExecutionService executionService = processEngine.getExecutionService();
//启动 (通过看表才能知道id,使用较少)
// executionService.startProcessInstanceById("1");
//设计流程时,流程有name -----默认生成流程key
executionService.startProcessInstanceByKey("helloworld");
}
启动流程后,第一个接受人是员工,此时员工的任务列表中就会有一个处理任务
@Test
//查看个人任务
public void testFindPersonlTask(){
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
//查看任务
TaskService taskService = processEngine.getTaskService();
//查询个人任务
List tasks = taskService.findPersonalTasks("员工");
System.out.println(tasks.size());
for (Task task : tasks) {
System.out.println("任务id : " + task.getId());
System.out.println("任务名称: " + task.getName());
System.out.println("任务的办理人 : " + task.getAssignee());
System.out.println("执行流程实例id :" + task.getExecutionId());
System.out.println("----------------");
}
}
员工办理当前任务,员工办理完任务后当前任务就会流转到了部门经理那,而后以此类推最后总经理处理完成后,请假流程就走完了,从这个这个简单的请假例子当中可以体现出JBPM帮我们做了权限控制业务流转等操作大大的方便了我们的开发。
@Test
// 办理任务
public void testCompleteTask(){
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
// 查看任务
TaskService taskService = processEngine.getTaskService();
// 必须通过任务id进行办理
//taskService.completeTask("80002");
taskService.completeTask("90001");
}