JBPM服务
参考文档:jbpm-4.4\doc\userguide\html_single\index.html
jbpm-4.4\doc\javadocs\index.html
public static ProcessEngine getProcessEngine() { if(singleton == null) synchronized(org/jbpm/api/Configuration) { if(singleton == null) singleton = (new Configuration()).setResource("jbpm.cfg.xml").buildProcessEngine(); } return singleton; } private static ProcessEngine singleton;2:实例化一个新的Configuration对象来构建ProcessEngine。
RepositoryService repositoryService = processEngine.getRepositoryService(); ExecutionService executionService = processEngine.getExecutionService(); TaskService taskService = processEngine.getTaskService(); HistoryService historyService = processEngine.getHistoryService(); ManagementService managementService = processEngine.getManagementService();
NewDeployment newDeployment=repositoryService.createDeployment();NewDeployment可以发布新流程,api文档中提供了多种发布方式:
//从classpath加载流程定义文件(xxx.jpdl.xml) NewDeployment addResourceFromClasspath(java.lang.String resourceName) //通过File对象加载 NewDeployment addResourceFromFile(java.io.File file) //通过输入流加载 NewDeployment addResourceFromInputStream(java.lang.String resourceName, java.io.InputStream inputStream) //通过字符串加载 NewDeployment addResourceFromString(java.lang.String resourceName, java.lang.String string) //通过URL加载 NewDeployment addResourceFromUrl(java.net.URL url) //通过zip文件流加载 NewDeployment addResourcesFromZipInputStream(java.util.zip.ZipInputStream zipInputStream)然后调用发布的方法.deploy();
repositoryService.createDeployment().addResourceFromClasspath("org/jbpm/config/process.jpdl.xml").deploy();流程部署后,会生成{key}-{version}格式的流程定义ID,如果流程定义文件未指明key和
1-2:删除流程。
repositoryService.deleteDeployment(deploymentId);//流程定义没有执行时 repositoryService.deleteDeploymentCascade(deploymentId); //级联删除,包含的流程定义,相关的流程实例和他们的历史信息1-3:查询流程。
List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list();上面是查询所有的流程,当然也可以
List<ProcessDefinition> processDefinitions = repositoryService .createProcessDefinitionQuery() .processDefinitionId("")//参数是流程定义的id .processDefinitionKey("")//参数是流程定义的key .processDefinitionName("")//参数是流程定义的name .processDefinitionNameLike("")//参数是流程定义的name,进行模糊查询 .list();//查询
repositoryService.resumeDeployment(deploymentId) //恢复 repositoryService.suspendDeployment(deploymentId) //挂起*****************************************************************************
ProcessInstance pi1=executionService.startProcessInstanceById("ICL");//根据id ProcessInstance pi2=executionService.startProcessInstanceByKey("ICL-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 pi3 = executionService.startProcessInstanceByKey("ICL", variables);
<state name="wait"> <on event="start"> <event-listener class="org.jbpm.examples.StartExternalWork" /> </on> ... </state>有一个可选的(不太推荐的)的方式,来获得流程执行到达时的状态活动。
ProcessInstance processInstance = executionService.startProcessInstanceById(processDefinitionId); Execution execution = processInstance.findActiveExecutionIn("external work"); String executionId = execution.getId();
//查找指定用户的任务列表 List<Task> taskList = taskService.findPersonalTasks("johndoe"); //查找指定组的任务列表 List<Task> groupTaskList = taskService.findGroupTasks("mygroup");
Object obj=taskService.getVariable(taskId, variableName); Map<String, Object> mp=taskService.getVariables(taskId, variableNames); Set<String> set=taskService.getVariableNames("");
taskService.completeTask(taskId); taskService.completeTask(taskId, variables); taskService.completeTask(taskId, outcome); taskService.completeTask(taskId, outcome, variables);
a)如果一个任务有一个没有name的transition: If a task has one outgoing transition without a name then: taskService.getOutcomes() //returns a collection that includes one null value taskService.completeTask(taskId) //will take that outgoing transition taskService.completeTask(taskId, null) //will take that outgoing transition taskService.completeTask(taskId, "anyvalue") //will result in an exception b)如果一个任务有一个有name的transition: If a task has one outgoing transition with a name then: taskService.getOutcomes() //returns a collection that includes only the name of the transition taskService.completeTask(taskId) //will take the single outgoing transition taskService.completeTask(taskId, null) //will will result in an exception (as there is no transition without a name) taskService.completeTask(taskId, "anyvalue") //will result in an exception taskService.completeTask(taskId, "myName") //will take the transition with the given name c)如果一个任务拥有多个transition,而其中一个没有name,其他都有name: If a task has multiple outgoing transitions. One transition has no a name and the other transition have a name: taskService.getOutcomes() //returns a collection that includes a null value and the names of the other transitions taskService.completeTask(taskId) //will take the transition without a name taskService.completeTask(taskId, null) //will take the transition without a name taskService.completeTask(taskId, "anyvalue")// will result in an exception taskService.completeTask(taskId, "myName") //will take the 'myName' transition d)如果一个任务拥有多个transition,并且都有唯一的name: If a task has multiple outgoing transitions and all of them are uniquely named, then: taskService.getOutcomes() //returns a collection that includes all the names of all the transitions taskService.completeTask(taskId) //will result in an exception, since there is no transition without a name taskService.completeTask(taskId, null) //will result in an exception, since there is no unnamed transition taskService.completeTask(taskId, "anyvalue") //will result in an exception taskService.completeTask(taskId, "myName") //will take the 'myName' transition
<?xml version="1.0" encoding="UTF-8"?> <process name="myprocess" xmlns="http://jbpm.org/4.4/jpdl"> <start name="start1" g="90,129,48,48"> <transition name="to state1" to="state1" g="-56,-22"/> </start> <state name="state1" g="307,127,92,52"> <transition name="to end1" to="end1" g="-50,-22"/> </state> <end name="end1" g="564,128,48,48"/> </process>
List<HistoryTask> task=historyService.createHistoryTaskQuery().taskId("").list(); List<HistoryProcessInstance> hps=historyService.createHistoryProcessInstanceQuery().processDefinitionId("").list(); List<HistoryActivityInstance> hais=historyService.createHistoryActivityInstanceQuery().processDefinitionId("").activityName("").list();
List<Job> joblist=managementService.createJobQuery().processInstanceId("").list();
api到此算是看了个大概,后面该了解流程定义文件jPDL中的东西了,毕竟对一个流程都不清楚,
更谈不上操作流程了。