扩展activiti工做流的整个生命流程(代码)

本人博客开始迁移,博客整个架构本身搭建及编码 http://www.cookqq.com/listBlog.action java

工做流的总体步骤:编程

(1)建立工做流引擎安全

(2)得到activiti相关的任务:引擎API是与Activiti交互最经常使用的方式。主要的出发点是ProcessEngine,由ProcessEngine,能够获取到含有工做流/BPM方法的不一样服务。ProcessEngine以及那些服务对象都是线程安全的架构

代码:app

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文件详解 ide

(4)得到与本身相关的某些任务ui

(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: spa

taskService.claim(task.getId(), "fozzie");

(6)完成某个任务.net

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());
  }

}
相关文章
相关标签/搜索