JBPM4服务详解
流程引擎ProcessEngine的构建方式:
[java]
view plain
copy
print
?
- ProcessEngine pe = Configuration.getProcessEngine();
- ProcessEngine pe = new Configuration().buildProcessEngine();
- 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
?
- RepositoryService rs = pe.getRepositoryService();
- ExecutionService es = pe.getExectionService();
- TaskService ts = pe.getTaskService();
- HistoryService hs = pe.getHistoryService();
- 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
?
-
- rs.createDeployment().addResourceFromClasspath(path).deploy();
-
- rs.createDeployment().addResourceFromFile(file).deploy();
-
- rs.createDeployment().addResourceFromUrl(url).deploy();
-
- rs.createDeployment().addResourceFromZipInputStream(zip).deploy();
-
- 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
?
-
- rs.deleteDeployment(deploymentId);
-
- rs.deleteDeploymentCascade(deploymentId);
//删除流程定义,如果该流程还存在活动的流程实例,将抛出异常 rs.deleteDeployment(deploymentId); //级联删除所有该流程相关的内容 rs.deleteDeploymentCascade(deploymentId);
3)挂起/恢复流程
[java]
view plain
copy
print
?
-
- rs.suspendDeployment(deploymentId);
-
- rs.resumeDeployment(deploymentId);
//挂起流程后,发起新流程或更新实例数据都会抛出异常 rs.suspendDeployment(deploymentId); //恢复流程 rs.resumeDeployment(deploymentId);
4)查询流程定义信息
[java]
view plain
copy
print
?
- ProcessDefinitionQuery pdq = rs.createProcessDefinitionQuery();
- List<ProcessDefinition> pdList = pdq.processDefinitionKey("xxx").list();
ProcessDefinitionQuery pdq = rs.createProcessDefinitionQuery(); List<ProcessDefinition> pdList = pdq.processDefinitionKey("xxx").list();
5)获取流程定义图片
[java]
view plain
copy
print
?
-
- rs.getResourceAsStream(deploymentId,"xxx.png");
//前提条件是图片也发布到了数据库中 rs.getResourceAsStream(deploymentId,"xxx.png");
执行服务ExecutionService:主要用于维护流程实例,包含流程实例的查询和流程变量的操作.
1)启动新的流程
[java]
view plain
copy
print
?
-
- es.startProcessInstanceByKey("VMIN");
-
- es.startProcessInstanceById("VMIN-2");
-
- es.startProcessInstanceByKey("VMIN","CGD0008");
-
- Map map = new HashMap();
- 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
?
- es.signalExecutionById(executeId);
es.signalExecutionById(executeId);
任务服务TaskService
1)任务列表访问
[java]
view plain
copy
print
?
-
- List<Task> list = ts.findPersonalTasks("marker");
-
- 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
?
- ts.getVariable(taskId, variableName);
- ts.getVariables(taskId, variableNames);
- ts.getVariableNames(taskId);
- 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
?
- ts.completeTask(taskId);
- ts.completeTask(taskId, variables);
- ts.completeTask(taskId, outcome);
- 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
?
- 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
?
- Job job = ms.createJobQuery().processInstanceId(processInstanceId).uniqueResult();
- ms.executeJob(job.getId);