Flowable 6.6.0 BPMN用户指南 - 7 BPMN 2.0简介 - 7.3 入门:10分钟教程(11-12)

《Flowable 6.6.0 BPMN用户指南》

1. 入门

2. 配置

3 The Flowable API

4 Flowable 6.6.0 BPMN用户指南 - (4)Spring集成

5 Spring Boot

6 部署

7 BPMN 2.0简介

7.1 BPMN是什么?
7.2 定义流程
7.3 入门:10分钟教程

  • 7.3.1 先决条件
  • 7.3.2 目标
  • 7.3.3 用例
  • 7.3.4 流程图
  • 7.3.5 XML表示
  • 7.3.6 启动流程实例
  • 7.3.7 任务列表
  • 7.3.8 认领任务(Claiming the task)
  • 7.3.9 完成任务
  • 7.3.10 结束流程
  • 7.3.11 代码概述
  • 7.3.12 未来增强

有关Flowable的更多文档,参见:

《Flowable文档大全》


7.3.11 代码概述

Combine all the snippets from previous sections, and you should have something like the following. The code takes into account that you probably will have started a few process instances through the Flowable app UI. It retrieves a list of tasks instead of one task, so it always works:

合并前面几节中的所有代码片段,您应该得到如下内容。代码考虑到您可能已经通过Flowable应用UI(Flowable app UI)启动了几个流程实例。它检索出一个任务列表,而不是一个任务,因此它始终有效:

public class TenMinuteTutorial {
     

  public static void main(String[] args) {
     

    // Create Flowable process engine
    ProcessEngine processEngine = ProcessEngineConfiguration
      .createStandaloneProcessEngineConfiguration()
      .buildProcessEngine();

    // Get Flowable services
    RepositoryService repositoryService = processEngine.getRepositoryService();
    RuntimeService runtimeService = processEngine.getRuntimeService();

    // Deploy the process definition
    repositoryService.createDeployment()
      .addClasspathResource("FinancialReportProcess.bpmn20.xml")
      .deploy();

    // Start a process instance
    String procId = runtimeService.startProcessInstanceByKey("financialReport").getId();

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

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

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

7.3.12 未来增强

It’s easy to see that this business process is too simple to be usable in reality. However, as you are going through the BPMN 2.0 constructs available in Flowable, you will be able to enhance the business process by:

很容易看出,此业务流程过于简单,无法在实际中使用。但是,当您了解Flowable中可用的BPMN 2.0构造时,您将能够通过以下方式增强业务流程:

  • defining gateways so a manager can decide to reject the financial report and recreate the task for the accountant, following a different path than when accepting the report.
  • declaring and using variables to store or reference the report so that it can be visualized in the form.
  • defining a service task at the end of the process to send the report to every shareholder.
  • etc.
  • 定义网关(gateway),以便经理可以决定拒绝财务报告并为会计重新创建任务,使流程遵循与接受报告不同的路径。
  • 声明并使用变量(variable)来存储或引用报表,以便在表单中可视化。
  • 在流程结束时定义服务任务(service task),以将报告发送给每位股东。
  • 等等。

你可能感兴趣的:(Flowable,6.6.0,BPMN用户指南,-(6)部署,(7))