JBPM入门(2010-05-24 17:58:20)转载标签: processrepositoryexecutiontasktaskserviceisactive工作流java 分类: 工作圈
jBPM是一种基于J2EE的轻量级工作流管理系统,是JBoss开源项目中的一个组成部分。
JBPM核心类及接口介绍:
ProcessEngieen:central starting point for all process engine API interactions
functions:getExecutionService(),getRepositoryService(),getTaskService()
RepositoryService:Deployments contain a set of named resources. Those resources can represent process definitions,forms,images and so on. The repository contains and manages the process definitions.
functions:deleteDeployment(java.lang.String deploymentId)
ExecutionService:manages runtime process executions.
functions:createProcessInstanceQuery(),deleteProcessInstance(java.lang.String processInstanceId),
findExecutionById(java.lang.String executionId),findProcessInstanceById(java.lang.String processInstanceId),
setVariable(java.lang.String executionId, java.lang.String name, java.lang.Object value),
setVariables(java.lang.String executionId, java.util.Map<java.lang.String,?> variables),
startProcessInstanceById(...),startProcessInstanceByKey(...),getVariableNames(java.lang.String executionId),
getVariables(java.lang.String executionId, java.util.Set<java.lang.String> variableNames)
TaskService:task management
functions:completeTask(java.lang.String taskId),deleteTask(java.lang.String taskId),
findPersonalTasks(java.lang.String userId),getVariableNames(java.lang.String taskId),
getVariables(java.lang.String taskId, java.util.Set<java.lang.String> variableNames)
Execution:The state of an execution is either active or locked.
functions:getExecution(java.lang.String name) ,isActive(java.lang.String activityName),
isEnded() ,isSuspended()
ProcessInstance:extends Execution,a process instance is one execution of a process definition. One process instance can have many concurrent executions.Executions are structured in a tree of which the ProcessInstance is the root.
ProcessDefinition:a graphical process which is deployed in the RepositoryService.
functions:getDeploymentId(),getName(),getKey()
开发中常用功能点介绍:
1.流程发布
org.jbpm.api.ProcessEngine processEngine = Configuration.getProcessEngine();
org.jbpm.api.RepositoryService repositoryService = processEngine.getRepositoryService();
ZipInputStream zis = new ZipInputStream(this.getClass().getResourceAsStream("/xx.zip"));
repositoryService.createDeployment().addResourcesFromZipInputStream(zis).deploy();
//repositoryService.createDeployment().addResourceFromClasspath("org/xx/process.xml).deploy();
2.删除已发布流程
repositoryService.deleteDeployment(processId); // processId流程定义标识
//repositoryService.deleteDeploymentCascade(deploymentId);
3.获取流程实例列表或某个实例
org.jbpm.api.ExecutionService executionService = processEngine.getExecutionService();
executionService.createProcessInstanceQuery().list();
//创建新流程,processDefinitionKey:xml中process标签的key;processInstanceKey:用户给的key,实例标识
executionService.startProcessInstanceByKey(processDefinitionKey, processInstanceKey);
//创建新流程
//processDefinitionKey:xx.xml中process标签的key ;variables:该流程实例要用到的变量;processInstanceKey(用户给定的业务key)
//executionService.startProcessInstanceByKey(processDefinitionKey, variables, processInstanceKey);
org.jbpm.api.ProcessInstance processInstance = executionService.startProcessInstanceByKey("xxx");
//对应于数据库表jbpm4_execution中的KEY_字段
//ProcessInstance processInstance =executionService.createProcessInstanceQuery().processInstanceKey(key).uniqueResult();
4.实现某个任务
Map<String, Object> map = new HashMap<String, Object>();
map.put("condtion1", 1);
map.put("condtion2", "2");
//List<Task> taskList = taskService.findPersonalTasks(name);
//获取指定用户名字的任务
String taskId = taskService.findPersonalTasks(name).get(0).getId();
taskService.setVariables(taskId, map);
//根据任务id获取指定变量值 taskService.getVariable(taskId, variableName);
//taskService.getVariable(taskId, "condtion1");
////让任务向下流转,提交任务
taskService.completeTask(taskId);
5.节点(任务)执行情况判断
task = taskService.getTask(taskId);
org.jbpm.api.Execution execution = executionService.findExecutionById(task.getExecutionId());
boolean b = execution.getProcessInstance().isActive(taskname);
//判断是否是taskname对应的节点需要处理
boolean c = execution.getProcessInstance().isActive(taskname1)
if(b){
...map
taskService.setVariables(taskId, map);
taskService.completeTask(taskId);
}else if(c){
taskService.completeTask(taskId);
}
jbmp装贴
猜你喜欢
转载自a4441135.iteye.com/blog/1249002
今日推荐
周排行