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

}
相關文章
相關標籤/搜索