流程引擎ProcessEngine的构建方式:
ProcessEngine pe = Configuration.getProcessEngine();
ProcessEngine pe = new Configuration().buildProcessEngine();
ProcessEngine pe = new Configuration().setResource("my.jbpm.cfg.xml").buildProcessEngine();
流程引擎的服务接口:
RepositoryService rs = pe.getRepositoryService();
ExecutionService es = pe.getExectionService();
TaskService ts = pe.getTaskService();
HistoryService hs = pe.getHistoryService();
ManagementService ms = pe.getManagementService();
流程资源RepositoryService:包含了管理流程资源的所有方法.
1)部署流程
//通过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)删除流程
//删除流程定义,如果该流程还存在活动的流程实例,将抛出异常
rs.deleteDeployment(deploymentId);
//级联删除所有该流程相关的内容
rs.deleteDeploymentCascade(deploymentId);
3)挂起/恢复流程
//挂起流程后,发起新流程或更新实例数据都会抛出异常
rs.suspendDeployment(deploymentId);
//恢复流程
rs.resumeDeployment(deploymentId);
4)查询流程定义信息
ProcessDefinitionQuery pdq = rs.createProcessDefinitionQuery();
List<ProcessDefinition> pdList = pdq.processDefinitionKey("xxx").list();
5)获取流程定义图片
//前提条件是图片也发布到了数据库中
rs.getResourceAsStream(deploymentId,"xxx.png");
执行服务ExecutionService:主要用于维护流程实例,包含流程实例的查询和流程变量的操作.
1)启动新的流程
//指定KEY,默认最新版本
es.startProcessInstanceByKey("VMIN");
//指定KEY-流程版本
es.startProcessInstanceById("VMIN-2");
//指定流程实例ID
es.startProcessInstanceByKey("VMIN","CGD0008");
//传递流程变量
Map map = new HashMap();
es.startProcessInstanceByKey("VMIN", map);
2)执行等待的流程
es.signalExecutionById(executeId);
任务服务TaskService
1)任务列表访问
//查找指定用户的任务列表
List<Task> list = ts.findPersonalTasks("marker");
//查找指定组的任务列表
List<Task> list = ts.findGroupTasks("hr-group");
2)读取相关数据
ts.getVariable(taskId, variableName);
ts.getVariables(taskId, variableNames);
ts.getVariableNames(taskId);
ts.getVariables(taskId, variables);
3)完成任务
ts.completeTask(taskId);
ts.completeTask(taskId, variables);
ts.completeTask(taskId, outcome);
ts.completeTask(taskId, outcome, variables);
历史服务HistoryService:查询历史流程实例
hs.createHistoryProcessInstanceQuery().processDefinitionId(pdId).orderAsc(HistoryProcessInstanceQuery.PROPERTY_STARTTIME).list();
管理服务ManagementServcie:管理Job
Job job = ms.createJobQuery().processInstanceId(processInstanceId).uniqueResult();
ms.executeJob(job.getId);