Activiti User Guide -- Activit 用户指南 Part06

 

Chapter 7. BPMN

第七章 BPMN

Table of Contents

What is BPMN?

Examples

Defining a process

Getting started: 10 minute tutorial

Use case

Process diagram

XML representation

Starting a process instance

Task lists

Claiming the task

Completing the task

Ending the process

Future enhancements

BPMN 2.0 constructs

Custom extensions

Events

Start events

None start event

End events

None end event

Sequence flow

Conditional sequence flow

Gateways

Exclusive gateway

Parallel Gateway

User task

Script Task

Java Service Task

Email task

Manual Task

Java receive task

Boundary events

Timer Boundary Event

SubProcess

Call activity (subprocess)

What is BPMN?

什么是BPMN

See our FAQ entry on BPMN 2.0

请参考: FAQ entry on BPMN 2.0

Examples

示例

Examples for the BPMN 2.0 constructs described in the following sections can be found in the docs/examples folder.

本章所讨论的的BPMN2.0可以在docs/examples 目录下找到相应的示例。

See the specific section on examples for more information.

更多的可以参考示例 章节。

Defining a process

流程定义

To create a new BPMN 2.0 process definition, it's best to have your Eclipse properly set up.

为了创建BPMN2.0的流程定义文件,最好你的Eclipse中已经设置好相应的属性。

 

Create a new XML file (New->Other->XML-XML) and give it a name. Make sure that the file ends with .bpmn20.xml, since otherwise the engine won't pick up this file for deployment.

创建一个XML文件(New->Other->XML-XML))并赋一个指定的名称。XML文件名称必须以.bpmn20.xml作为结尾,否则流程引擎将不会部署此文件。


Activiti User Guide -- Activit 用户指南 Part06

 

The root element of the BPMN 2.0 schema is the definitions element. Within this element, multiple process definitions can be defined (although we advise to have only one process definition in each file, since this simplifies maintenance later in the development process). An empty process definition looks as follows. Note that the minimal definitions element only needs the xmlns and targetNamespacedeclaration.

BPMN2.0定义文件中的根元素是definitions。使用该元素可以在一个定义文件中定义多个流程(尽管如此,我们还是建议一个文件中最好只定义一个流程,因为这样以后维护起来更简单)。一个空的流程定义文件大概如下面所示。注意此时定义元素仅仅需要声明 xmlns  targetNamespace

 

<definitions 
  xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:activiti="http://activiti.org/bpmn-extensions"
  targetNamespace="http://www.activiti.org/bpmn2.0">

  <process id="myProcess" name="My First Process">

  </process>

</definitions>

 The process element has two attributes:

流程元素有两个属性:

  • id: this attribute is required and maps to the key property of an Activiti ProcessDefinition object. This id can then be used to start a new process instance of the process definition, through the startProcessInstanceByKey method on the ProcessService. This method will always take the latest deployed version of the process definition.

ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess");

Important to note here is that this is not the same as calling the startProcessInstanceById method. This method expects the String id that was generated at deploy time by the Activiti engine, and can be retrieved by calling the processDefinition.getId() method. The format of the generated id is 'key:version', and the length is constrained to 64 characters. If you get an ActivitiException stating that the generated id is too long, limit the text in the key field of the process.

  • id: 必须属性。该属性用来映射为Activiti流程定义中可以属性。此属性可以通过ProcessService startProcessInstanceByKey 来启动一个新的流程实例。该方法总是使用流程定义的最终版本来启动一个新的流程实例。

ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess");

这里需要注意的是与startProcessInstanceById 方法的区别。startProcessInstanceById 方法传入的参数是id字符串,该id是在Activiti引擎部署一个流程定义自动生成的,该id的值可以通过调用 processDefinition.getId() 方法获取。 Id格式为 'key:version' 长度为64位。如果你在部署时得到一个id长度太长的ActivitiException异常,那么最好修改key字段的长度。

  • name: this attribute is optional and maps to the name property of a ProcessDefinition. The engine itself doesn't use this property, so it can for example be used for displaying a more human-friendly name in a user interface.
  • name: 可选属性。用例映射流程定义中name属性。引擎本身并不使用该值,它可以显示在与用户交互的界面,这样更人性化一点。

Getting started: 10 minute tutorial

启航:10分钟教程

In this section we will cover a (simple) business process that we will use to introduce some basic Activiti concepts and the Activiti API.

在本小节中,我们将通过一个(简单)的业务流程用来介绍Activiti的基本概念以及Activiti API

Use case

用例

The use case is very simple: we have a company, let's call it BPMCorp. In BPMCorp, a financial report needs to be written every month for the company shareholders. This is the responsibility of the accountancy department. When the report is finished, one of the members of the upper management needs to approve the document before it is sent to all the shareholders.

这个用例非常简单:假如我们有一家名叫BPM的公司。在BPM公司,每个月财务部门需要将新的财务报表发送给公司的股东。当财务报表编写完毕后,需要经过上级管理部门进行审批,审批通过后才能发送给公司股东。

 

All files and code snippets used through the next sections can be found in the examples shipped with the Activiti distribution. Look for the package org.activiti.examples.bpmn.usertask.

接下来我们所使用的所有的文件以及代码都在Activiti发行包的examples目录中可以找到。具体可以参看 org.activiti.examples.bpmn.usertask package

Process diagram

流程图

The business process as described above, can be graphically visualized using the Activiti Modeler. The end result, in BPMN 2.0 notation, looks like this:

上面所说的业务流程可以使用Activiti Modeler建模工具进行绘制。下图就是我们所绘制出的流程图:


Activiti User Guide -- Activit 用户指南 Part06

There is nothing spectacular here. What we see is a none start event (circle on the left), followed by two user tasks: 'Write monthly financial report' and 'Verify monthly financial report', ending in a none end event (circle with thick border on the right).

这里没有什么好解释的。正如我们所看到的一个 none start event(左面那个圆圈),接下来是两个 user task:“Write monthly financial report”和“Verify monthly financial report”,最后是一个 none end event(右面那个带厚边框的圆)

XML representation

XML 表示

The XML version of this business process (FinancialReportProcess.bpmn20.xml) looks as shown below. It's easy to recognize the main elements of our process (click on the links for going to the detailed section of that BPMN 2.0 construct):

(FinancialReportProcess.bpmn20.xml)业务流程的XML表示如下面所示。我们可以清晰的辨识出主要的元素(点击链接查看BPMN2.0具体元素章节):

  • The (none) start event learns us where to start with the process
  • (none) start event表示流程从哪里开始
  • The user tasks declarations are the representation of the human tasks of our process. Note that the first task is assigned to theaccountancy group, while the second task is assigned to the management group. See the section on user task assignment for more information on how users and groups can be assigned to user tasks.
  • user task 则表示流程中需要人工进行处理的任务。需要注意的是第一个任务分配给accountancy 小组,而第二个任务则是分配给management 小组。 请参考人员任务分配章节来了解如何将人员和小组分配给user task.
  • The process ends when the none end event is reached.
  • 流程则是以none end event结束。
 

 

<process id="financialReport" name="Monthly financial report reminder process">
  
  <startEvent id="theStart" />
    
  <sequenceFlow id='flow1' sourceRef='theStart' targetRef='writeReportTask' />
    
  <userTask id="writeReportTask" name="Write monthly financial report" >
    <documentation>
      Write monthly financial report for publication to shareholders.
    </documentation>
    <potentialOwner>
      <resourceAssignmentExpression>
        <formalExpression>accountancy</formalExpression>
      </resourceAssignmentExpression>
    </potentialOwner>
  </userTask>
    
  <sequenceFlow id='flow2' sourceRef='writeReportTask' targetRef='verifyReportTask' />
      
  <userTask id="verifyReportTask" name="Verify monthly financial report" >
    <documentation>
      Verify monthly financial report composed by the accountancy department.
      This financial report is going to be sent to all the company shareholders.  
    </documentation>
    <potentialOwner>
      <resourceAssignmentExpression>
        <formalExpression>management</formalExpression>
      </resourceAssignmentExpression>
    </potentialOwner>
  </userTask>
    
  <sequenceFlow id='flow3' sourceRef='verifyReportTask' targetRef='theEnd' />
      
  <endEvent id="theEnd" />
      
</process>
 

Starting a process instance

启动流程实例

We now have defined the process definition of our business process. From such a process definition, we can create at runtime process instances. In this case, one process instance would match with the creation and verification of the financial report every month.

现在,我们已经为我们的业务流程定义了一个流程定义。通过该流程定义,我们就可以创建一个流程实例。在本示例中,一个流程实例也就是每个月创建并验证财务报表。

 

To be able to create process instances from a given process definition, we must first deploy this process definition. Deploying a process definition means two things:

为了能够从一个给定的流程定义中创建流程实例,我们必须首先部署该流程定义。部署流程定义也就意味着需要做下面两件事:

  • The process definition will be stored in the persistent datastore that is configured for your Activiti engine. So by deploying our business process, we make sure that the engine will find the process definition after an engine reboot.
  • 流程定义必须存放在我们为Activiti所配置的持久化数据库存储中。因此部署我们的业务流程,也就是可以让Activiti引擎重启后依然可以找到我们所部署的流程定义。
  • The BPMN 2.0 process file will be parsed to an in-memory object model that can be manipulated through the Activiti API.
  • BPMN2.0流程文件将被解析成一个可以通过Activiti API进行管理的内存对象。

More information on deployment can be found in the dedicated deployment section.

更多关于如何进行部署的内容可以在 dedicated deployment section小节中找到。

 

As described in that section, deployment can happen in several ways. One way is through the API as follows:

正如该章节所描述的,部署一个流程可以通过多种方式。下面通过API进行部署就是其中一种:

Deployment deployment = repositoryService.createDeployment()
  .addClasspathResource("org/activiti/examples/bpmn/usertask/FinancialReportProcess.bpmn20.xml")
  .deploy();
 

al

你可能感兴趣的:(eclipse,xml,配置管理,UP)