jbpm总结

JBPM核心对象
Configuration
ProcessEngine
1.RepositoryService
流程等资源接口:提供对流程定义的部署,查询,删除和流程图查看等
2.ExecutionService
流程执行服务接口:提供启动流程实例,推进,删除等操作
3.TaskService
人工任务服务接口:提供对任务的创建,提交,查询,保存,删除等操作
4.HistoryService
流程历史服务接口
5.ManagementService
流程管理接口,通常用来管理Jop(异步服务)
6.IdentityService

身份认证服务接口,提供对流程用户,用户组管理


主要问题

1.对部署的理解(RepositoryService)

一开始以为每次运用jbpm后都需要部署一次,但是经过进一步理解,当部署成功后jbpm就会在表中创建一个流程实例,在今后每次都可以运用这个实例不需要再次部署。

部署主要方法

ProcessEngine processEngine=Configuration.getProcessEngine();
RepositoryService repositoryService=processEngine.getRepositoryService();
repositoryService.createDeployment().addResourceFromClasspath("test.jpdl.xml").deploy();

或者

ZipInputStream zis = new ZipInputStream(this.getClass().getResourceAsStream("/leave2.zip"));

String did=repositoryService.createDeployment().addResourcesFromZipInputStream(zis).deploy();

2.创建流程(ExecutionService)

当需要进行流程处理时,可以根据部署的key来创建流程

ProcessEngine processEngine=Configuration.getProcessEngine();
ExecutionService executionService=processEngine.getExecutionService();
ProcessInstance processInstance=executionService.startProcessInstanceByKey("test");
    test问流程实例key

"流程实例ID====="+processInstance.getId()+"流程名称="+processInstance.getName();

3.查看结点(ExecutionService)

查看流程审批当前到达流程结点。

ProcessEngine processEngine=Configuration.getProcessEngine();
ExecutionService exetutionService=processEngine.getExecutionService();
String currecName=exetutionService.createProcessInstanceQuery().processInstanceId("test.10001").uniqueResult().findActiveActivityNames().toString();
   test.10001流程实例ID

4.查看对应人认为(TaskService )
public void getTask(){
ProcessEngine processEngine =  Configuration.getProcessEngine();
TaskService taskService = processEngine.getTaskService();
List<Task> tasks = taskService.findPersonalTasks("张三");
System.out.println("任务数量==" +tasks.size());
/*Task task = tasks.get(0);

System.out.println("任务名词==" +task.getActivityName());
System.out.println("任务人员==" +task.getAssignee() + "任务ID===" + task.getId());*/
for (Task task : tasks) {
System.out.println("任务名称:"+task.getActivityName()+"\t"+"任务人员:"+task.getAssignee()+"\t"+"流程实例ID:"+task.getExecutionId()+"\t"+"任务ID:"+task.getId()+"\t"+task.getProgress());
System.out.println("任务时间:"+task.getCreateTime()+"\t"+task.getDuedate());
}
}

5.完成认为(TaskService )
public void completeTask(){
ProcessEngine processEngine=Configuration.getProcessEngine();
TaskService taskService=processEngine.getTaskService();
taskService.completeTask("130001");
}

6.查看历史(HistoryService )

public void historyTask(){
ProcessEngine processEngine=Configuration.getProcessEngine();
HistoryService historyService=processEngine.getHistoryService();
List<HistoryProcessInstance> historyProcessInstances = historyService.createHistoryProcessInstanceQuery().list();
System.out.println();
for (HistoryProcessInstance ht : historyProcessInstances) {
System.out.println("开始时间:"+ht.getStartTime()+"\t"+"结束时间"+ht.getEndTime()+"\t"+"状态:"+ht.getState()+"\t"+"流程实例ID:"+ht.getProcessInstanceId());

}
}


如果还需要添加用户信息

1.创建
public void createInstance(){
super.startUp();
Map<String,Object> map = new HashMap<String,Object>();
map.put("userId1", "001");
map.put("userName1", "tom");
ProcessInstance processInstance=executionService.startProcessInstanceByKey("test", map);
super.print("流程实例ID", processInstance.getId());
}

2.查看信息
public void getMyVariable(){
super.startUp();
String userId = executionService.getVariable("test.160001", "userId1").toString();
String userName = executionService.getVariable("test.160001", "userName1").toString();
String age=executionService.getVariable("test.160001", "age").toString();
this.print("userId", userId);
this.print("userName", userName);
this.print("age", age);
}

3.不知道变量时候查看信息
public void findMyVariable(){
super.startUp();

Set<String> set =  executionService.getVariableNames("test.160001");

Iterator iter = set.iterator();
while(iter.hasNext()){
System.out.println(iter.next());
}

Map<String,Object> map = executionService.getVariables("test.50001", set);
Iterator it = map.entrySet().iterator();
while(it.hasNext()){
Map.Entry m = (Map.Entry)it.next();
this.print(m.getKey().toString(), m.getValue().toString());
}
}

4.增加信息
public void addVariable(){
super.startUp();
Map<String, Object> map=new HashMap<String,Object>();
map.put("age", 12);
map.put("name", "张三");
executionService.setVariables("test.160001", map);
}

5.修改信息
public void upVariable(){
super.startUp();
executionService.setVariable("test.160001", "age", "21");
}

6.审核人得到当前任务
public void getTask(){
super.startUp();
List<Task> tasks=taskService.findPersonalTasks("李四");
for (Task task : tasks) {
System.out.println("任务名称:"+task.getActivityName()+"\t"+"任务人员:"+task.getAssignee()+"\t"+"流程实例ID:"+task.getExecutionId()+"\t"+"任务ID:"+task.getId()+"\t"+task.getProgress());
String userId = executionService.getVariable(task.getExecutionId(), "userId1").toString();
String userName = executionService.getVariable(task.getExecutionId(), "userName1").toString();
String age=executionService.getVariable(task.getExecutionId(), "age").toString();
String name=executionService.getVariable(task.getExecutionId(), "name").toString();
this.print("userId", userId);
this.print("userName", userName);
this.print("age", age);
this.print("name", name);
}
}
7.审核任务
public void completeTask(){
super.startUp();
taskService.completeTask("160004");
}















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值