Now we can start a new process instance using the id we defined in the process definition (see first line of the XML). Note
that this id in Activiti terminology is called the key.
现在我们就可以使用id来创建一个新的流程实例了(id值在XML定义的第一行中)。注意此处的id在Activiti属于中称之为key。
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("financialReport");
This will create a runtime execution that will go first
through the start event. After the start event, it follows all the outgoing
sequence flow (only one in this case) and the first task ('write monthly
financial report') is reached. The Activiti engine will now store a task in the
persistent datastore. At this point, the user or group assignments attached to
the task are resolved and also stored in the datastore.
这将创建一个流程执行,该执行将首先调用start event。之后将经由所有外出顺序流(这里只有一个)并到达第一个任务(“write monthly financial report”)。Activiti引擎将把一个任务信息存储到持久化数据库中。这里分配给任务的人员或小组也会被解析,并也存储到数据库中。
After the task is created, the startProcessInstanceByKey will return since the user task activity is a so-called 'wait state', which means that the engine will continue the process
instance only when some external trigger is given. In this case, the task is
assigned to a group, which means that the every member of the group is a candidate to perform the task.
当任务创建后,startProcessInstanceByKey 也就返回了,因此user task activity也称之为’wait state’,也就是说引擎只有在接收到外部一个触发器之后才继续执行流程实例。在这里,任务赋给了一个小组,因此小组中的每一个成员都是执行任务可选人员。
Task
lists
任务列表
We can now retrieve this newly created task through the taskService.
下面我们就可以taskService通过获取我们刚刚创建的任务。
List<Task> tasks = taskService.findUnassignedTasks("fozzie");
. Note that the user we pass to this operation needs to
be a member of the accountancy group, since that was declared in the process definition:
注意:执行该方法的人员必须是accountancy 小组中的一员,因为在流程定义中我们是这么定义的:
<potentialOwner>
<resourceAssignmentExpression>
<formalExpression>accountancy</formalExpression>
</resourceAssignmentExpression>
</potentialOwner>
We could also use the task query API to get the same
results:
我们也可以通过使用任务查询 API 获取同样的结果:
List<Task> tasks = taskService.createTaskQuery().candidateUser("fozzie").list();
or
或
List<Task> tasks = taskService.createTaskQuery().candidateGroup("accountancy").list();
The business process described here is also deployed as
an example to the demo setup database. After running the demo
setup, log into the Activiti Explorer as fozzie (he's an accountant), and select in the drop down menu on
the right the 'Monthly
financial report' process.
这里所描述的业务流程已经部署在示例数据库中。运行完demo setup,你可以在Activiti Explorer中以fozzie(他属于accountan小组),并在右边的下拉菜单中选择‘Monthly financial report’流程。
As explained, the process will execute up to the first
user task. Since we're logged in as fozzie, we can see that there is a new
candidate task available for him after we've started the process instance. Note
that even if the process was started by someone else, the task would still be
visible as a candidate task to everyone in the accountancy group.
正如我们上面解释的,流程将创建第一个用户任务。当我们启动流程实例后,使用fozzie登录,在界面中就可以看到一个新的待确认的任务。注意,即使该流程是别人启动的,该任务仍然是一个待确认任务,可以被accountancy小组的所有成员看到。
Claiming the task
确认任务
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:
现在需要accountant小组的成员确认任务。通过确认任务,任务将被赋给一个特定人员作为任务的处理者,同时任务将从accountancy小组的其他成员任务列表中消失。确认任务则是需要通过下面的程序进行:
taskService.claim(task.getId(), "fozzie");
The task is now in the personal task list of the one that
claimed the task.
此时任务就会加入确认者个人任务列表中。
List<Task> tasks = taskService.findAssignedTasks("fozzie");
In the Activiti Explorer UI, clicking the claim button will call the same operation. The task will now
move to the personal task list of the logged on user.
在Activiti Explorer界面中,点击“claim”按钮也会执行相同的操作。任务就会移到登录者的个人任务列表中。
Completing the task
完成任务
The accountant can now start working on the financial
report. Once the report is finished, he can complete the task, which means that all work for that task is done.
会计人员此时就可以开始编制财务报表。一但报表完成,就可以完成任务了,意味着本任务中的所有工作都做完了。
taskService.complete(task.getId());
For the Activiti engine, this is an external signal that
the process instance execution must be continued. The single outgoing
transition out of the task is followed, bringing the execution in the second
task ('verification
of the report'). The same mechanism as
described for the first task will now happen, with the small difference that
the task will be assigned to the management group.
对于Activiti引擎,这是一外部触发器迫使流程实例继续执行。接下来只有一个外出流向,该流向将使流程执行第二个任务(“verification of the report”)。接下来所发生的和第一个任务的处理机制一样,只不过稍有不同的就是任务将赋给management 小组。
In the demo setup, completing the task is done by
clicking the complete button in the task list. Since Fozzie isn't an
accountant, we need to log out of the Activiti Explorer and login in as kermit (which is a manager). The second task is now visible in
the unassigned task lists.
在示例中,可以通过点击“complete”按钮来完成任务。因为Fozzie不是manager小组的成员,我们需要登出并且使用kemit(他是manager小组的成员)登录。此时第二个任务就会显示在待确认的任务列表中。
Ending the process
结束流程
The verification task can be retrieved and claimed in
exactly the same way as before. Completing this second task, will bring process
execution at the end event, which finishes the process instance. The process
instance and all related runtime execution data is removed from the datastore.
该任务可以像上面一样获取和确认。完成该任务将使流程到达end event,这将结束整个流程。此时流程实例以及相关所有的运行数据都会从数据库中移除。
When you log into Activiti Probe you can verify this,
since no records will be found in the table where the process executions are
stored.
你可以通过登录Acitivit Probe来验证,登录后你可以发现在存储流程执行数据的表中没有任何记录。
Future enhancements
后续改进
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 Activiti, you will be able to enhance the business
process by
显然,对于实际应用来说这个流程是太简单了。不过,当你学习完Activiti中所提供BPMN2.0结构,就可以对业务流程进行以下改进:
-
defining a timer start event that automatically starts a process instance at the
end of every month.
-
定义一个timer start event在每个月定时启动一个流程实例
-
defining gateways that act as decisions. This way, a manager could reject the financial
report which would recreate the task for the accountant.
-
定义gateway用来进行判断。此时经理就可以驳回财务报表重新为会计人员创建一个任务
-
declaring and using variables, such that we can store or reference the report such that it can be
visualized while verifying it.
-
声明和使用variable,这样就可以存储相应的报表,在验证的时候就可以查看了
-
defining a service task at the end of the process that will send the report
to every shareholder.
-
在流程结束的时候定义一个service task,自动的将报表发送给每一个股东
- etc.
-
等
- 大小: 56.2 KB
- 大小: 24.8 KB
- 大小: 75.2 KB
- 大小: 99 KB
- 大小: 51.8 KB
分享到:
相关推荐
赠送jar包:activiti-json-converter-5.21.0.jar; 赠送原API文档:activiti-json-converter-5.21.0-javadoc.jar; 赠送源代码:activiti-json-converter-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
这个“activiti-userguide-5-16”压缩包文件包含了 Activiti 5.16 版本的用户指南,帮助我们深入理解并有效使用这个流程管理工具。 1. **BPMN 2.0 规范**:Business Process Model and Notation 2.0(业务流程模型...
赠送jar包:activiti-engine-5.21.0.jar; 赠送原API文档:activiti-engine-5.21.0-javadoc.jar; 赠送源代码:activiti-engine-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-engine-5.21.0.pom; 包含...
赠送jar包:activiti-json-converter-5.21.0.jar; 赠送原API文档:activiti-json-converter-5.21.0-javadoc.jar; 赠送源代码:activiti-json-converter-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
赠送jar包:activiti-image-generator-5.21.0.jar; 赠送原API文档:activiti-image-generator-5.21.0-javadoc.jar; 赠送源代码:activiti-image-generator-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
赠送jar包:activiti-common-rest-5.21.0.jar; 赠送原API文档:activiti-common-rest-5.21.0-javadoc.jar; 赠送源代码:activiti-common-rest-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-common-rest-...
赠送jar包:activiti-bpmn-model-5.21.0.jar; 赠送原API文档:activiti-bpmn-model-5.21.0-javadoc.jar; 赠送源代码:activiti-bpmn-model-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-bpmn-model-...
activiti-spring-boot-starter-7.1.0.M1
赠送jar包:activiti-image-generator-5.21.0.jar; 赠送原API文档:activiti-image-generator-5.21.0-javadoc.jar; 赠送源代码:activiti-image-generator-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
activiti-spring-boot-starter-basic-6.0.0适配springboot2.1.2
activiti-bpmn-converter-5.18.0-sources.jar
赠送jar包:activiti-process-validation-5.21.0.jar; 赠送原API文档:activiti-process-validation-5.21.0-javadoc.jar; 赠送源代码:activiti-process-validation-5.21.0-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:activiti-bpmn-converter-5.21.0.jar; 赠送原API文档:activiti-bpmn-converter-5.21.0-javadoc.jar; 赠送源代码:activiti-bpmn-converter-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
activiti-bpmn-converter-5.16.4.jar
本文将详细介绍如何在SpringBoot项目中整合Activiti,并通过提供的"springboot-activiti-test-master.zip"压缩包进行实战演练。 首先,我们需要了解SpringBoot与Activiti的基本概念。SpringBoot旨在简化Spring应用...
1、将以下四个文件(见附件Activiti Designer 5.18.1插件补丁)拷贝到自己的eclipse的plugin文件夹下面,重启eclipse ...2、将activiti-designer-5.18.0文件夹copy到eclipse\dropins目录下; 3、重启eclipse即可
eclipse 安装activiti activiti-designer-5.18.0.zip 附带eclipse 以及activiti-designer-5.18.0.zip 安装包 eclipse下载链接https://www.eclipse.org/downloads/packages/release/luna/sr2
【 activiti-explorer-eclipse项目 】是一个基于Activiti工作流引擎的Eclipse插件项目。 Activiti 是一个开源的业务流程管理系统(BPMN 2.0)和工作流引擎,它允许开发者轻松地在应用程序中集成业务流程管理功能。这...
Activiti的Eclipse插件activiti-designer安装资料包,包含activiti-designer-5.18.0.zip、org.eclipse.emf.transaction_1.4.0.201306111400.jar、org.eclipse.emf.validation.ui_1.7.0.201403111711.jar、org....
1. **流程建模**: Activiti Designer 提供了一个图形化用户界面,通过拖放方式可以轻松创建和配置各种流程元素,如开始事件、结束事件、任务、网关和泳道等。这使得非技术背景的业务人员也能参与到流程设计中,提升...