JBPM4服务详解

JBPM4服务详解

流程引擎ProcessEngine的构建方式:

[java] view plain copy print ?
  1. ProcessEngine pe = Configuration.getProcessEngine(); 
  2. ProcessEngine pe = new Configuration().buildProcessEngine(); 
  3. ProcessEngine pe = new Configuration().setResource("my.jbpm.cfg.xml").buildProcessEngine(); 
ProcessEngine pe = Configuration.getProcessEngine(); ProcessEngine pe = new Configuration().buildProcessEngine(); ProcessEngine pe = new Configuration().setResource("my.jbpm.cfg.xml").buildProcessEngine();

流程引擎的服务接口:

[java] view plain copy print ?
  1. RepositoryService rs = pe.getRepositoryService(); 
  2. ExecutionService es = pe.getExectionService(); 
  3. TaskService ts = pe.getTaskService(); 
  4. HistoryService hs = pe.getHistoryService(); 
  5. ManagementService ms = pe.getManagementService(); 
RepositoryService rs = pe.getRepositoryService(); ExecutionService es = pe.getExectionService(); TaskService ts = pe.getTaskService(); HistoryService hs = pe.getHistoryService(); ManagementService ms = pe.getManagementService();

流程资源RepositoryService:包含了管理流程资源的所有方法.

1)部署流程

[java] view plain copy print ?
  1. //通过classpath加载 
  2. rs.createDeployment().addResourceFromClasspath(path).deploy(); 
  3. //通过File类加载 
  4. rs.createDeployment().addResourceFromFile(file).deploy(); 
  5. //通过URL加载 
  6. rs.createDeployment().addResourceFromUrl(url).deploy(); 
  7. //通过ZIP文件流加载 
  8. rs.createDeployment().addResourceFromZipInputStream(zip).deploy(); 
  9. //通过字符串加载 
  10. rs.createDeployment().addResourceFromString(resourceName, string).deploy(); 
//通过classpath加载 rs.createDeployment().addResourceFromClasspath(path).deploy(); //通过File类加载 rs.createDeployment().addResourceFromFile(file).deploy(); //通过URL加载 rs.createDeployment().addResourceFromUrl(url).deploy(); //通过ZIP文件流加载 rs.createDeployment().addResourceFromZipInputStream(zip).deploy(); //通过字符串加载 rs.createDeployment().addResourceFromString(resourceName, string).deploy();

2)删除流程

[java] view plain copy print ?
  1. //删除流程定义,如果该流程还存在活动的流程实例,将抛出异常 
  2. rs.deleteDeployment(deploymentId); 
  3. //级联删除所有该流程相关的内容 
  4. rs.deleteDeploymentCascade(deploymentId); 
//删除流程定义,如果该流程还存在活动的流程实例,将抛出异常 rs.deleteDeployment(deploymentId); //级联删除所有该流程相关的内容 rs.deleteDeploymentCascade(deploymentId);

3)挂起/恢复流程

[java] view plain copy print ?
  1. //挂起流程后,发起新流程或更新实例数据都会抛出异常 
  2. rs.suspendDeployment(deploymentId); 
  3. //恢复流程 
  4. rs.resumeDeployment(deploymentId); 
//挂起流程后,发起新流程或更新实例数据都会抛出异常 rs.suspendDeployment(deploymentId); //恢复流程 rs.resumeDeployment(deploymentId);

4)查询流程定义信息

[java] view plain copy print ?
  1. ProcessDefinitionQuery pdq = rs.createProcessDefinitionQuery(); 
  2. List<ProcessDefinition> pdList = pdq.processDefinitionKey("xxx").list(); 
ProcessDefinitionQuery pdq = rs.createProcessDefinitionQuery(); List<ProcessDefinition> pdList = pdq.processDefinitionKey("xxx").list();

5)获取流程定义图片

[java] view plain copy print ?
  1. //前提条件是图片也发布到了数据库中 
  2. rs.getResourceAsStream(deploymentId,"xxx.png"); 
//前提条件是图片也发布到了数据库中 rs.getResourceAsStream(deploymentId,"xxx.png");

执行服务ExecutionService:主要用于维护流程实例,包含流程实例的查询和流程变量的操作.

1)启动新的流程

[java] view plain copy print ?
  1. //指定KEY,默认最新版本 
  2. es.startProcessInstanceByKey("VMIN"); 
  3. //指定KEY-流程版本 
  4. es.startProcessInstanceById("VMIN-2"); 
  5. //指定流程实例ID 
  6. es.startProcessInstanceByKey("VMIN","CGD0008"); 
  7. //传递流程变量 
  8. Map map = new HashMap(); 
  9. es.startProcessInstanceByKey("VMIN", map); 
//指定KEY,默认最新版本 es.startProcessInstanceByKey("VMIN"); //指定KEY-流程版本 es.startProcessInstanceById("VMIN-2"); //指定流程实例ID es.startProcessInstanceByKey("VMIN","CGD0008"); //传递流程变量 Map map = new HashMap(); es.startProcessInstanceByKey("VMIN", map);

2)执行等待的流程

[java] view plain copy print ?
  1. es.signalExecutionById(executeId); 
es.signalExecutionById(executeId);

任务服务TaskService

1)任务列表访问

[java] view plain copy print ?
  1. //查找指定用户的任务列表 
  2. List<Task> list = ts.findPersonalTasks("marker"); 
  3. //查找指定组的任务列表 
  4. List<Task> list = ts.findGroupTasks("hr-group"); 
//查找指定用户的任务列表 List<Task> list = ts.findPersonalTasks("marker"); //查找指定组的任务列表 List<Task> list = ts.findGroupTasks("hr-group");

2)读取相关数据

[java] view plain copy print ?
  1. ts.getVariable(taskId, variableName); 
  2. ts.getVariables(taskId, variableNames); 
  3. ts.getVariableNames(taskId); 
  4. ts.getVariables(taskId, variables); 
ts.getVariable(taskId, variableName); ts.getVariables(taskId, variableNames); ts.getVariableNames(taskId); ts.getVariables(taskId, variables);

3)完成任务

[java] view plain copy print ?
  1. ts.completeTask(taskId); 
  2. ts.completeTask(taskId, variables); 
  3. ts.completeTask(taskId, outcome); 
  4. ts.completeTask(taskId, outcome, variables); 
ts.completeTask(taskId); ts.completeTask(taskId, variables); ts.completeTask(taskId, outcome); ts.completeTask(taskId, outcome, variables);

历史服务HistoryService:查询历史流程实例

[java] view plain copy print ?
  1. hs.createHistoryProcessInstanceQuery().processDefinitionId(pdId).orderAsc(HistoryProcessInstanceQuery.PROPERTY_STARTTIME).list(); 
hs.createHistoryProcessInstanceQuery().processDefinitionId(pdId).orderAsc(HistoryProcessInstanceQuery.PROPERTY_STARTTIME).list();

管理服务ManagementServcie:管理Job

[java] view plain copy print ?
  1. Job job = ms.createJobQuery().processInstanceId(processInstanceId).uniqueResult(); 
  2. ms.executeJob(job.getId); 

你可能感兴趣的:(JBPM4服务详解)