Activiti User Guide -- Activit 用户指南 Part11

本文介绍用户任务的概念及其在流程管理中的应用,包括任务分配给个人或组的方式,并提供了简化任务分配的方法。

User task

用户任务

 

Description

描述

A 'user task' is used to model work that needs to be done by a human actor. When process executes arrives at such a user task, a new task is created in the task list of the user(s) or group(s) assigned to that task.

用户任务是为需要由人工处理的事务进行建模的。当流程执行到一个用户任务时,一个新的任务就会在任务列表中创建,并将任务分配给人或者小组。

Graphical notation

图形符号

A user task is visualized as a typical task (rounded rectangle), with a small user icon in the left upper corner.

用户任务表示是在普通任务(带圆角的矩形框)图形的左上方增加一个小人图标。


XML representation

XML 表示

A user task is defined in XML as follows. The id attribute is required, the name attribute is optional.

用户任务的XML定义如下。Id属性是必须的,而name属性则是可选的。

<userTask id="theTask" name="Important task" /> 
A user task can have also a description. In fact any BPMN 2.0 element can have a description, but for the moment we've only implemented it for user tasks since it makes most sense there. A description is defined by adding the documentation element. Note that only onedocumentation element is supported at the moment (can be multiple according to the specification).

用户任务还有一个描述。事实上在BPMN2.0中任何元素都可以有描述,但是当前我们只为用户实现该属性,因为这样更加有意义一点。描述是通过添加documentation元素来定义的。注意现在只允许添加一个documentation元素(标准中则可以添加多个)。

<userTask id="theTask" name="Schedule meeting" >
  <documentation>
          Schedule an engineering meeting for next week with the new hire.
        </documentation>
The description text can be retrieved from the task in the standard Java way:

通过标准的java方式在任务中就可以获取描述信息:

task.getDescription()

 

User assignment

用户指定

A user task can be directly assigned to a user. This is done by defining a humanPerformer sub element. Such a humanPerformerdefinition needs a resourceAssignmentExpression that actually defines the user. Currently, only formalExpressions are supported.

通过定义humanPerformer 一个子元素,可以将用户任务直接分配给一个用户。humanPerformer 定义需要一个resourceAssignmentExpression 来确定定义用户。当前,仅支持formalExpressions 表达式。

<process ...
  
  ...
  
  <userTask id='theTask' name='important task' >
    <humanPerformer>
      <resourceAssignmentExpression>
        <formalExpression>kermit</formalExpression>
      </resourceAssignmentExpression>
    </humanPerformer>
  </userTask>

 

Only one user can be assigned as human performer to the task. In Activiti terminology, this user is called the assignee. Task that have an assignee are not visible in the task lists of other people, and are found in the so-called personal task list of the assignee.

只能有一个用户用来执行任务。在Activiti中,用户也称之为处理者。那些有处理者的任务只能在该人员的个人任务列表中被看见,而其他人员的任务列表中则无法看到该任务。

 

Tasks directly assigned to users can be retrieved through the TaskService as follows:

被直接分配给用户的任务可以通过TaskService来获取,如下所示:

List<Task> tasks = taskService.findAssignedTasks("kermit");
Or the TaskQuery API can be used:

也可以使用TaskQuery API

List<Task> tasks = taskService.createTaskQuery().assignee("kermit").list();
Both code snippets will retrieve the tasks where the assignee currently is the given user.

上面两段代码都可以获取到分配给指定用户的任务列表。

 

Tasks can also be put in the so-called candidate task list of people. In that case, the potentialOwner construct must be used. The usage is similar to the humanPerformer construct. Do note that it is required to define for each element in the formal expression to specify if it is a user or a group (the engine cannot guess this).

任务也可以被放进一个称之为候选任务的任务列表中。此时,就需要potentialOwner 构件了。用法和humanPerformer 相近。不过在定义中需要为每一个表达式明确的指出是用户还是小组(因为引擎是不会知道的)。

<process ...
  
  ...
  
  <userTask id='theTask' name='important task' >
    <potentialOwner>
      <resourceAssignmentExpression>
        <formalExpression>user(kermit), group(management)</formalExpression>
      </resourceAssignmentExpression>
    </potentialOwner>
  </userTask>
Tasks defines with the potential owner construct, can be retrieved as follows (or a similar TaskQuery usage as for the tasks with an assignee):

使用 potential owner 进行定义的任务可以下面的代码(与直接进行分配的任务查询语法类似)进行获取:

List<Task> tasks = taskService.findUnassignedTasks("kermit");
This will retrieve all tasks where kermit is a candidate user, i.e. the formal expression contains user(kermit). This will also retrieve all tasks that are assigned to a group where kermit is a member of (e.g. group(management), if kermit is a member of that group). Note that the groups of the user are resolved at runtime and these can be managed through the IdentityService.

这将获取到所有以Kermit作为候选处理者的任务,因为我们在表达式中包含了user(kermit)。同时也会获取到分配给kermit所属小组的任务(例如group(management),同时kermit是该小组中的一员)。用户的小组信息在运行时进行解析,同时也可以通过IdentityService进行管理。

 

If no specifics are given whether the given text string is a user or group, the engine defaults to group. So the following would be the same as when group(accountancy) was declared.

如果没有指定给的表达式是岗位还是人员,那么引擎将默认任务是一个岗位。因此,下面的代码就和声明为group(accountancy)是一样的。

<formalExpression>accountancy</formalExpression>

 

Custom extension for simple task assignments

为简化任务分配进行的自定义扩展

It is clear that user and group assignments are quite cumbersome for use cases where the assignment is not complex. To avoid these complexities, custom extensions on the user task are possible.

显然对于一些不复杂的任务分配赋值这样来写的确是复杂很多。为了避免这种复杂性,为用户任务进行自定义扩展是可行的。

  • assignee attribute: this custom extension allows to directly assign a user task to a given user.
  • assignee attribute: 该自定义扩展直接为用户任务分配一个人员

<userTask id="theTask" name="my task" activiti:assignee="kermit" />

This is exactly the same as using a humanPerformer construct as defined above.

这和上面使用humanPerformer 来定义是一样的。

  • candidateUsers attribute: this custom extension allows to make a user a candidate for a task.
  • candidateUsers attribute: 该自定义扩展将备选人员赋值给一个任务

<userTask id="theTask" name="my task" activiti:candidateUsers="kermit, gonzo" />
This is exactly the same as using a potentialOwner construct as defined above. Note that it is not required to use the user(kermit)declaration as is the case with the potential owner construct, since the attribute can only be used for users.

这和上面使用potentialOwner 来定义是一样的。需要说明的是,这里不需要使用user(kermit)类似的写法,因为该属性只能使用人员。

  • candidateGroups attribute: this custom extension allows to make a group a candidate for a task.
  • candidateGroups attribute: 该自定义扩展允许将一个岗位赋值为一个任务。

<userTask id="theTask" name="my task" activiti:candidateGroups="management, accountancy" />
This is exactly the same as using a potentialOwner construct as defined above. Note that it is not required to use thegroup(management) declaration as is the case with the potential owner construct, since the attribute can only be used for groups.

这和上面使用potentialOwner 来定义是一样的。需要说明的是,这里不需要使用group(management) 类似的写法,因为该属性只能使用岗位。

  • candidateUsers and candidateGroups can both be defined on the same user task.
  • candidateUsers candidateGroups 可以同时使用在一个用户定义中。
首先,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、付费专栏及课程。

余额充值