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作为结尾,否则流程引擎将不会部署此文件。


 

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建模工具进行绘制。下图就是我们所绘制出的流程图:


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,Activity是Android系统中的四大组件之一,可以用于显示View。Activity是一个与用记交互的系统模块,几乎所有的Activity都是和用户进行交互的,但是如果这样就能说Activity主要是用来显示View就不太正确了。 在深入了解Activity之前,我们先要知道一下MVC设计模式,在JAVAEE 中MVC设计模式已经很经典了,而且分的也比较清晰了,但是在Android中,好多人对MVC在Android开发中的应用不是很清楚,下面我就先来介绍一下MVC在Android开发中的应用: M(Model 模型):Model是应用程序的主体部分,所有的业务逻辑都应该写在这里,在Android中Model层与JavaEE中的变化不大,如:对数据库的操作,对网络等的操作都放在该层(但不是说它们都放在同一个包中,可以分开放,但它们统称为Model层)。 V(View 视图):是应用程序中负责生成用户界面的部分,也是在整个MVC架构中用户唯一可以看到的一层,接收用户输入,显示处理结果;在Android应用中一般采用XML文件里德界面的描述,使用的时候可以非常方便的引入,当然也可以使用JavaScript+Html等方式作为View。 C(Controller控制层)android的控制层的重任就要落在众多的activity的肩上了,所以在这里就要建议大家不要在activity中写太多的代码,尽量能过activity交割Model业务逻辑层处理。 好了,在介绍过Android应用开发中的MVC架构后,我们就可以很明确的知道,在Android中Activity主要是用来做控制的,它可以选择要显示的View,也可以从View中获取数据然后把数据传给Model层进行处理,最后再来显示出处理结果。 介绍过Activity的主要作用后,那么我们就要详细说一下Activity了。 Activity生命周期图 Activity 的生命周期是被以下的函数控制的。 public class Activity extends ApplicationContext { protected void onCreate(Bundle icicle); protected void onStart(); protected void onRestart(); protected void onResume(); protected void onFreeze(Bundle outIcicle); protected void onPause(); protected void onStop(); protected void onDestroy(); } onCreate(Bundle) 函数是你进行初始化的地方,这个也是执行 setContentView(View)函数的地方,setContentView(View)函数可以传入一个由XML 编制的UI界面,可以使UI和具体实现完全分离。 onPause()函数是处理用户离开当前 Activity 的地方。更重要的是,任何在当前 Activity中的任何改变都要在这个函数中提交。 Activity有四种状态: 活动状态,当Activity处于Stack(栈)顶时,就是手机当前的现实屏幕,这是 Activity就 处于activity或者运行状态。 运行但是失去焦点,当Activity还处于运行状态时,但是屏幕是有另外一个Activity 处于文档处于焦点状态,当前的Activity就处于pause。 停止,当Activity被另一个Activity完全覆盖的时候,就被停止了,其实就是虽然在 运行,但是用户却看不见。 结束,当Activity处于pause或者stop时,系统可以结束 Activity,回收资源,这 是Activity就是处于结束状态了。 处于结束状态的是Activity,如果要使用户可见,只要重启才可以。 Activity的响应时间 当前Activity所在的线程为主线程,它的响应时间为5秒,如果在当前运行的Activity中进行耗时的操作且响应时间起过5秒,那么程序就会报ANR错误。所以,这也是不建议在Activity中写太多复杂代码的原因之一。 当然,有些代码只能写在Activity中,不然就运行不了(它们不是生命周期方法),比如你想要获得android系统或者硬件一的些信息,就必须在Activity中写出来,如果单独写一个工具类获得不了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值