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 thefollowing sections can be found in the?docs/examples?folder.
本章所讨论的的BPMN2.0可以在docs/examples?目录下找到相应的示例。
See the specific section on?examples?for more information.
更多的可以参考示例?章节。
Defining aprocess
流程定义
To create a new BPMN 2.0 process definition, it's best tohave your Eclipse?properly setup.
为了创建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 fordeployment.
创建一个XML文件(New->Other->XML-XML))并赋一个指定的名称。XML文件名称必须以.bpmn20.xml作为结尾,否则流程引擎将不会部署此文件。
?
The root element of the BPMN 2.0 schema is the?definitions?element. Within this element, multiple processdefinitions can be defined (although we advise to have only one processdefinition in each file, since this simplifies maintenance later in thedevelopment process). An empty process definition looks as follows. Note thatthe minimal definitions element only needs the?xmlns?and?targetNamespacedeclaration.
BPMN2.0定义文件中的根元素是definitions。使用该元素可以在一个定义文件中定义多个流程(尽管如此,我们还是建议一个文件中最好只定义一个流程,因为这样以后维护起来更简单)。一个空的流程定义文件大概如下面所示。注意此时定义元素仅仅需要声明?xmlns?和?targetNamespace。
?
?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 wasgenerated at deploy time by the Activiti engine, and can be retrieved bycalling 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 textin 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属性。引擎本身并不使用该值,它可以显示在与用户交互的界面,这样更人性化一点。
Gettingstarted: 10 minute tutorial
启航:10分钟教程
In this section we will cover a (simple) business processthat we will use to introduce some basic Activiti concepts and the ActivitiAPI.
在本小节中,我们将通过一个(简单)的业务流程用来介绍Activiti的基本概念以及Activiti API。
Use case
用例
The use case is very simple: we have a company, let'scall it BPMCorp. In BPMCorp, a financial report needs to be written every monthfor the company shareholders. This is the responsibility of the accountancydepartment. When the report is finished, one of the members of the uppermanagement needs to approve the document before it is sent to all theshareholders.
这个用例非常简单:假如我们有一家名叫BPM的公司。在BPM公司,每个月财务部门需要将新的财务报表发送给公司的股东。当财务报表编写完毕后,需要经过上级管理部门进行审批,审批通过后才能发送给公司股东。
?
All files and code snippets used through the nextsections 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。
Processdiagram
流程图
The business process as described above, can begraphically visualized using the Activiti Modeler. The end result, in BPMN 2.0notation, looks like this:
上面所说的业务流程可以使用Activiti Modeler建模工具进行绘制。下图就是我们所绘制出的流程图:
There is nothing spectacular here. What we see is a?nonestart event?(circle onthe left), followed by two?usertasks:?'Writemonthly financial report'?and?'Verify monthly financial report', ending in a?noneend event?(circle with thick border on the right).
这里没有什么好解释的。正如我们所看到的一个 none start event(左面那个圆圈),接下来是两个 user task:“Writemonthly financial report”和“Verify monthly financial report”,最后是一个 none end event(右面那个带厚边框的圆)。
XMLrepresentation
XML 表示
The XML version of this business process (FinancialReportProcess.bpmn20.xml) looks as shown below. It's easy to recognize the mainelements of our process (click on the links for going to the detailed sectionof 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结束。?
?
?
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 andverification of the financial report every month.
现在,我们已经为我们的业务流程定义了一个流程定义。通过该流程定义,我们就可以创建一个流程实例。在本示例中,一个流程实例也就是每个月创建并验证财务报表。
?
To be able to create process instances from a givenprocess 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 severalways. One way is through the API as follows:
正如该章节所描述的,部署一个流程可以通过多种方式。下面通过API进行部署就是其中一种:
al
- id: 必须属性。该属性用来映射为Activiti流程定义中可以属性。此属性可以通过ProcessService 的startProcessInstanceByKey?来启动一个新的流程实例。该方法总是使用流程定义的最终版本来启动一个新的流程实例。