Skip to content

Commit 37136cd

Browse files
committed
jbpm流程引擎基本流程跑通
1 parent 01e70f4 commit 37136cd

File tree

6 files changed

+758
-210
lines changed

6 files changed

+758
-210
lines changed

.idea/workspace.xml

Lines changed: 658 additions & 192 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@
165165
<artifactId>javax.mail-api</artifactId>
166166
<version>1.4.7</version>
167167
</dependency>
168+
<dependency>
169+
<groupId>junit</groupId>
170+
<artifactId>junit</artifactId>
171+
</dependency>
172+
<dependency>
173+
<groupId>org.springframework</groupId>
174+
<artifactId>spring-test</artifactId>
175+
<version>5.0.4.RELEASE</version>
176+
<scope>compile</scope>
177+
</dependency>
178+
<dependency>
179+
<groupId>org.springframework.boot</groupId>
180+
<artifactId>spring-boot-test</artifactId>
181+
</dependency>
168182

169183
</dependencies>
170184

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.code.repository.study.goodcode;
2+
3+
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.test.context.junit4.SpringRunner;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
@RunWith(SpringRunner.class)
13+
@SpringBootTest
14+
public class uniqueElement {
15+
16+
@Test
17+
public void uniqueElement() {
18+
List<Object> list = new ArrayList<>();
19+
list.add("12");
20+
list.add("12");
21+
int size = list.size();
22+
if (size==0) {
23+
System.out.println("list is null");
24+
}
25+
Object first = list.get(0);
26+
for ( int i=1; i<size; i++ ) {
27+
if ( list.get(i)!=first ) {
28+
System.out.println("list element is not unique");
29+
}
30+
}
31+
System.out.println("===boject is :"+first);
32+
}
33+
}
Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.code.repository;
2-
import org.jbpm.api.Configuration;
3-
import org.jbpm.api.ProcessEngine;
4-
import org.jbpm.api.RepositoryService;
2+
import org.jbpm.api.*;
53
import org.jbpm.api.task.Task;
64
import org.junit.Test;
75
import org.junit.runner.RunWith;
86
import org.springframework.boot.test.context.SpringBootTest;
97
import org.springframework.test.context.junit4.SpringRunner;
108

11-
import java.util.List;
9+
import java.util.*;
1210

1311
@RunWith(SpringRunner.class)
1412
@SpringBootTest
@@ -24,26 +22,35 @@ public void createSchema() { // hbm2ddl.auto=update
2422
new org.hibernate.cfg.Configuration().configure("jbpm.hibernate.cfg.xml").buildSessionFactory();
2523
}
2624

27-
// 一、部署流程定义
25+
// 一、部署流程定义 RepositoryService
2826
@Test
29-
public void deployProcessDefinition() {
30-
ProcessEngine processEngine = Configuration.getProcessEngine();
31-
RepositoryService repositoryService = processEngine.getRepositoryService();
32-
repositoryService.createDeployment().addResourceFromClasspath("jbpm.jpdl.xml").deploy();
27+
public void deploy() {
28+
ProcessEngine processEngine = Configuration.getProcessEngine();// 创建流程引擎
29+
RepositoryService repositoryService = processEngine.getRepositoryService();// 获取流程资源服务接口
30+
repositoryService.createDeployment().addResourceFromClasspath("test.jpdl.xml").deploy();// 部署流程
3331
}
3432

33+
// 生成一个流程实例 ExecutionService
3534
@Test
36-
public void startProcessInstance() {
35+
public void createInstance() {
3736
ProcessEngine processEngine = Configuration.getProcessEngine();
38-
processEngine.getExecutionService().startProcessInstanceByKey("test");
37+
String processKey = "test";
38+
ExecutionService executionService = processEngine.getExecutionService();//执行服务
39+
Map<String, String> map = new HashMap<String, String>(); // 添加变量
40+
map.put("staff","hm员工");
41+
ProcessInstance processInstance = executionService.startProcessInstanceByKey(processKey,map);
42+
String id = processInstance.getId();
43+
System.out.println("流程实例id:"+id);
3944
}
4045

46+
// 查询任务列表 TaskService
4147
@Test
4248
public void findMyTaskList() {
4349
ProcessEngine processEngine = Configuration.getProcessEngine();
4450
// 查询任务
4551
String userId = "员工";
46-
List<Task> list = processEngine.getTaskService().findPersonalTasks(userId);
52+
TaskService taskService = processEngine.getTaskService();
53+
List<Task> list = taskService.findPersonalTasks(userId);
4754

4855
// 显示任务
4956
System.out.println("========= 【"+userId+"】的未办理的任务列表 =========");
@@ -55,13 +62,32 @@ public void findMyTaskList() {
5562
}
5663
}
5764

65+
// 获取流程变量 TaskService
5866
@Test
59-
public void completeTask() {
67+
public void fetchTaskVariable() {
6068
ProcessEngine processEngine = Configuration.getProcessEngine();
61-
String taskId = "20002";
62-
processEngine.getTaskService().completeTask(taskId);
69+
String taskId = "40003";
70+
String instanceId= "test.40001";
71+
TaskService taskService = processEngine.getTaskService();
72+
ExecutionService executionService = processEngine.getExecutionService();
73+
// 取出当前的所有任务
74+
Set<String> activityNames = executionService.createProcessInstanceQuery().processInstanceId(instanceId).uniqueResult().findActiveActivityNames();
75+
String name = (String)activityNames.toArray()[0];
76+
Task task = taskService.createTaskQuery().processInstanceId(instanceId).activityName(name).uniqueResult();
77+
// 根据任务取出变量
78+
Set<String> vars = taskService.getVariableNames(task.getId());
79+
System.out.println(vars.toString());
80+
String staff = (String)taskService.getVariable(taskId,"staff");
81+
System.out.println("staff:"+staff);
6382
}
6483

65-
84+
// 完成当前任务 TaskService
85+
@Test
86+
public void completeTask() {
87+
ProcessEngine processEngine = Configuration.getProcessEngine();
88+
String taskId = "60001";
89+
TaskService taskService = processEngine.getTaskService();
90+
taskService.completeTask(taskId);
91+
}
6692

6793
}

src/test/java/jbpm.hibernate.cfg.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66

77
<hibernate-configuration>
88
<session-factory>
9-
109
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
1110
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jbpm</property>
1211
<property name="hibernate.connection.username">root</property>
1312
<property name="hibernate.connection.password">root</property>
1413
<property name="hibernate.hbm2ddl.auto">update</property>
1514
<property name="hibernate.format_sql">true</property>
16-
1715
<mapping resource="jbpm.repository.hbm.xml" />
1816
<mapping resource="jbpm.execution.hbm.xml" />
1917
<mapping resource="jbpm.history.hbm.xml" />
@@ -22,3 +20,14 @@
2220

2321
</session-factory>
2422
</hibernate-configuration>
23+
24+
<!-- hibernate.hbm2ddl.auto值和作用
25+
create:每次加载hibernate时都会删除上一次的生成的表,然后根据你的model类再重新来生成新表,
26+
哪怕两次没有任何改变也要这样执行,这就是导致数据库表数据丢失的一个重要原因。
27+
create-drop :每次加载hibernate时根据model类生成表,但是sessionFactory一关闭,表就自动删除;
28+
update:最常用的属性,第一次加载hibernate时根据model类会自动建立起表的结构(前提是先建立好数据库),
29+
以后加载hibernate时根据 model类自动更新表结构,即使表结构改变了但表中的行仍然存在不会删除以前的行。
30+
要注意的是当部署到服务器后,表结构是不会被马上建立起来的,是要等 应用第一次运行起来后才会。
31+
validate :每次加载hibernate时,验证创建数据库表结构,只会和数据库中的表进行比较,不会创建新表,但是会插入新值。
32+
33+
-->

0 commit comments

Comments
 (0)