2013-04-10 12:43:02.0|分类: activiti|浏览量: 2398
工作流的整体步骤: (1)创建工作流引擎 (2)获得activiti相关的任务:引擎API是与Activiti交互最常用的方式。主要的出发点是ProcessEngine,由ProcessEngine,可以获取到含有工作流/BPM方法的不同服务。ProcessEngine以及那些服务对象都是线程安全的。
代码: ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RuntimeService runtimeService = processEngine.getRuntimeService(); RepositoryService repositoryService = processEngine.getRepositoryService(); TaskService taskService = processEngine.getTaskService(); ManagementService managementService = processEngine.getManagementService(); IdentityService identityService = processEngine.getIdentityService(); HistoryService historyService = processEngine.getHistoryService(); FormService formService = processEngine.getFormService(); (3)部署流程定义 参照:activiti--部署bpmn/bar文件详解 (4)获得与自己相关的某些任务 (5)声明某个任务: 官方解释:An accountant(账房) now needs to claim(声明) the task. By claiming the task, the specific user will become the assignee(受理人) of the task and the task will disappear(消失) from every task list of the other members of the accountancy group. Claiming a task is programmatically(编程) done as follows: taskService.claim(task.getId(), "fozzie"); (6)完成某个任务 public class TenMinuteTutorial { public static void main(String[] args) { (创建activiti工作引擎) // Create Activiti process engine ProcessEngine processEngine = ProcessEngineConfiguration .createStandaloneProcessEngineConfiguration() .buildProcessEngine(); (2)获得activiti相关服务 // Get Activiti services RepositoryService repositoryService = processEngine.getRepositoryService(); RuntimeService runtimeService = processEngine.getRuntimeService(); (3)部署流程定义 // Deploy the process definition repositoryService.createDeployment() .addClasspathResource("FinancialReportProcess.bpmn20.xml") .deploy(); (4)开启一个流程实例 // Start a process instance String procId = runtimeService.startProcessInstanceByKey("financialReport").getId(); (5)获得与自己相关的某些任务 // Get the first task TaskService taskService = processEngine.getTaskService(); List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("accountancy").list(); for (Task task : tasks) { System.out.println("Following task is available for accountancy group: " + task.getName()); (6)声明某个任务// claim it taskService.claim(task.getId(), "fozzie"); } // Verify Fozzie can now retrieve the task tasks = taskService.createTaskQuery().taskAssignee("fozzie").list(); for (Task task : tasks) { System.out.println("Task for fozzie: " + task.getName()); (7)完成某个任务 // Complete the task taskService.complete(task.getId()); } System.out.println("Number of tasks for fozzie: " + taskService.createTaskQuery().taskAssignee("fozzie").count()); // Retrieve and claim the second task tasks = taskService.createTaskQuery().taskCandidateGroup("management").list(); for (Task task : tasks) { System.out.println("Following task is available for accountancy group: " + task.getName()); taskService.claim(task.getId(), "kermit"); } // Completing the second task ends the process for (Task task : tasks) { taskService.complete(task.getId()); } // verify that the process is actually finished HistoryService historyService = processEngine.getHistoryService(); HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult(); System.out.println("Process instance end time: " + historicProcessInstance.getEndTime()); } } accountant 会计 claim 认领 assignee 分配到任务的人 |