启动流程引擎:
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);

2815

被折叠的 条评论
为什么被折叠?



