JBPM具体流程设计代码基础篇

启动流程引擎:
ProcessEngine processEngine=Configuration.getProcessEngine();//直接从默认的配置文件'jbpm.cfg.xml'里得到流程引擎。
ProcessEngine processEngine =new Configuration() .buildProcessEngine();//创建流程引擎,默认是根据的配置文件同上。
ProcessEngine processEngine =new Configuration() .setResource("my-own-configuration-file.xml") .buildProcessEngine();//指定其他位置的配置文件。

可以根据流程引擎得到下面的服务:
RepositoryService repositoryService = processEngine.getRepositoryService();
ExecutionService executionService = processEngine.getExecutionService();
TaskService taskService = processEngine.getTaskService();
HistoryService historyService = processEngine.getHistoryService();
ManagementService managementService = processEngine.getManagementService();
****************************************************************************************
****************************************************************************************
RepositoryService
包含了用来管理发布资源的所有方法,
例子:
import org.jbpm.api.*;
import junit.framework.TestCase;
import java.util.*;

public class HelloTest extends TestCase {
ProcessEngine processEngine;
public HelloTest()
{
processEngine=Configuration.getProcessEngine();
}
public void testdeploy()
{
RepositoryService repositoryService=processEngine.getRepositoryService();
String deploymentId=repositoryService.createDeployment().addResourceFromClasspath("helloword.jpdl.xml").deploy();
System.out.print("!!!!!!!!!!!!!!"+deploymentId);//1
List<ProcessDefinition> list=repositoryService.createProcessDefinitionQuery().list();
for(ProcessDefinition pd:list){
System.out.println("ID"+pd.getId()); //helloword-1
System.out.println("DeploymentId"+pd.getDeploymentId());//1
System.out.println("Key"+pd.getKey());//helloword
System.out.println("Name"+pd.getName());//helloword
System.out.println("Version"+pd.getVersion());//1
}
repositoryService.deleteDeploymentCascade(deploymentId);//级联删除
}
}
****************************************************************************************
****************************************************************************************
ExecutionService
流程实例
ExecutionService executionService=processEngine.getExecutionService();
创建流程实例方法:
(1)ProcessInstance pi=executionService.startProcessInstanceByKey("helloword");
(2)ProcessInstance pi = executionService.startProcessInstanceById("helloword-1");
携带变量:
Map<String,Object> variables = new HashMap<String,Object>();
variables.put("customer", "John Doe");
variables.put("type", "Accident");
variables.put("amount", new Float(763.74));
ProcessInstance processInstance =executionService.startProcessInstanceByKey("helloword ", variables);
例子:
import junit.framework.TestCase;
import org.jbpm.api.*;
import java.util.*;
public class ProcessInstanceTest extends TestCase {
ProcessEngine processEngine;
public ProcessInstanceTest()
{
processEngine=Configuration.getProcessEngine();
}
protected void setUp()
{
processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("helloword.jpdl.xml").deploy();
}
public void testProcessInstance()
{
ExecutionService executionService=processEngine.getExecutionService();
ProcessInstance pi=executionService.startProcessInstanceByKey("helloword");
System.out.println(pi);
System.out.println(pi.isEnded());//false没结束,等待
pi=executionService.signalExecutionById(pi.getId());//继续执行,使其结束
System.out.println(pi.isEnded());//true结束流程
}
public void testProcessInstanceEnd()
{
ExecutionService executionService=processEngine.getExecutionService();
ProcessInstance pi=executionService.startProcessInstanceByKey("helloword");
executionService.endProcessInstance(pi.getId(), "cancel");//将流程实例终结掉
}
public void testProcessInstanceDelete()
{
ExecutionService executionService=processEngine.getExecutionService();
ProcessInstance pi=executionService.startProcessInstanceByKey("helloword");
executionService.deleteProcessInstanceCascade(pi.getId());//将流程级联删除
}
public void testProcessInstanceList()
{
ExecutionService executionService=processEngine.getExecutionService();
ProcessInstance pi=executionService.startProcessInstanceByKey("helloword");
ProcessInstance pi2=executionService.startProcessInstanceByKey("helloword");
List<ProcessInstance> list=executionService.createProcessInstanceQuery().list();
for(ProcessInstance processInstance:list)
{
System.out.println(processInstance.getId());
}
}
}
****************************************************************************************
****************************************************************************************
TaskService
待办任务
TaskService taskService = processEngine.getTaskService();//流程任务
List<Task> taskList = taskService.findPersonalTasks(userid);//查询该用户的任务列表
携带变量
Map<String,Object> map = new HashMap<String,Object>();
map.put("addall", addall);
map.put("student", stu_id);
taskService.completeTask(taskId, map);

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值