`
cd826
  • 浏览: 129048 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

jBPM Developers Guide(jBPM开发指南)--Chapter 3. BPMN 2.0(第四部分)

    博客分类:
  • BPMN
阅读更多

 

3.8.9. Tasks(任务)

    A task represents work that needs to be done by an external entity, such as a human actor or an automated service.

 

    一个任务表示工作需要被外部实体完成,比如人工或自动服务。

 

    It's important to note that the BPMN semantics of a 'task' differ from the JPDL semantics. In JPDL, the concept 'task' is always used in the context of a human actor doing some type of work. When the process engine encounters a task in JPDL, it will create a task in some human actor's task list and it will behave as a wait state. In BPMN 2.0 however, there are several task types, some indicating a wait state (eg. the User Task and some indicating an automatic activity (eg. the Service Task). So take good care not to confuse the meaning of the task concept when switching languages.

 

    重要的是注意BPMN语法的'task'jPDL语法的区别。在jPDL中,'task'的概念总是用在人工做一些事情的环境。jPDL流程引擎在遇到task时,它会创建一个task 并分配一些人进行处理,然后它会进入等待状态。然而在BPMN 2.0中, 这里有很多任务类型,一些表示等待状态(比如,User Task 一些表示自动活动(比如,Service Task。所以在切换流程语言时要小心不要混淆了任务的概念。

 

    Tasks are depicted by a rounded rectangle, typically containing a text inside. The type of the task (user task, service task, script task, etc.) is shown as a little icon on the left top corner of the rectangle. Depending on the task type, the engine will execute different functionality.

 

    任务使用一个圆角矩形表示,一般内部包含一些文字。任务的类型(用户任务,服务任务,脚本任务,等等)使用小图标进行区分,显示在矩形的左上角。 根据任务的类型,引擎会执行不同的功能。


3.8.10. Task: User Task(任务:人工任务)

 

    A User task is the typical 'human task' that is found in practically every workflow or BPM software out there. When process execution reaches such a user task, a new human task is created in task list for a given user.

 

    user task是典型的'人工任务' 几乎在每个工作流软件或BPMN软件中都可以找到。当流程执行到达一个user task时, 任务列表中就会创建一个新人工任务,并分配给给定用户进行处理。

 

    The main difference with a manual task (which also signifies work for a human actor) is that the task is known to the process engine. The engine can track the completion, assignee, time, etc which is not the case for a manual task.

 

    和manual task(也表示将任务分配给人进行处理)的主要区别是user task也会被流程引擎记录。 引擎可以跟踪任务完成、分配、时间等等,而manual task则不可以。

 

    A user task is depicted as a rounded rectangle with a small user icon in the top left corner.

 

    user task描绘为一个圆角矩形,在左上角是一个小用户图标。


    A user task is defined as follows in the BPMN 2.0 XML:

 

    BPMN 2.0user task XM定义如下:

<userTask id="myTask" name="My task" />
    According to the specification, multiple implementations are possible (Webservice, WS-humantask, etc.), as stated by using the implementation attribute. Currently, only the standard jBPM task mechanism is available, so there is no point (yet) in defining the 'implementation' attribute.

 

    根据规范,user task可以采用多种实现(WebService, WS-humantask,等等),使用implementation属性来标示。 当前,只有标准的jBPM任务机制才可以用,所以这里还没有定义'implementation'属性的功能。

 

    The BPMN 2.0 specification contains quite a few ways of assigning user tasks to user(s), group(s), role(s), etc. The current BPMN 2.0 jBPM implementation allows to assign tasks using a resourceAssignmentExpression, combined with the humanPerformer or PotentialOwner construct. It is to be expected that this area will evolve future releases.

 

    BPMN 2.0规范包含了一些方法把任务分配给用户、组、角色等等。当前的BPMN 2.0 jBPM实现允许使用resourceAssignmentExpression结合humanPerformer PotentialOwner结构来分配任务。这部分希望在未来的版本里能够得到进一步演化。

 

    A potentialOwner is used when you want to make a certain user, group, role, etc. a candidate for a certain task. Take the following example. Here the candidate group for the task 'My task' will be the 'management' group. Also note that a resource must be defined outside the process, such that the task assignment can reference the resource. In fact, any activity can reference one or more resource elements. Currently, only defining this resource is enough (since it is a required attribute by the spec), but this will be enhanced in a later release (eg. resources can have runtime parameters).

 

    potentialOwner用来,当你想把一个任务分配给一个候选的人, 组,角色时(这里所说的意思是当你需要分配给一个组时则系统为该组建立一个任务,并不会为该组中每个人员建立一个任务,即组里面的人员都是任务候选人)。如下面例子所示。这里的'My task'任务的候选人组是'management'用户组。也要注意,这是需要在流程外部定义一个资源, 这样任务分配器才可以引用到这个资源。实际上,任何活动都可以引用一个或多个资源元素。当前,只需要定义这个资源就可以了(因为它是规范中的一个必须的元素),但是在以后的发布中会进行加强(比如,资源可以拥有运行时参数)。 

<resource id="manager" name="manager" /> 

<process ...>

...        
        
<userTask id="myTask" name="My task">
  <potentialOwner resourceRef="manager" jbpm:type="group">
    <resourceAssignmentExpression>
      <formalExpression>management</formalExpression>
    </resourceAssignmentExpression>
  </potentialOwner>
</userTask> 
    Note that we are using a specific extension here (jbpm:type="group"), to define this is a group assignment. If this attribute is removed, the group semantics will be used as default (which would be ok in this example). Now suppose that Peter and Mary are a member of the management group (here using the default identity service):

 

    注意,我们使用了一个特定的后缀 (jbpm:type="group"),来定义这是一个用户组的分配方式。如果删除了这个属性,就会默认使用用户组的语法(在这个例子中也是没问题的)。现在假设PeterMarymanagement组的成员 (这里使用默认的身份服务)

identityService.createGroup("management");
    
identityService.createUser("peter", "Peter", "Pan");
identityService.createMembership("peter", "management");
    
identityService.createUser("mary", "Mary", "Littlelamb");
identityService.createMembership("mary", "management"); 
    Then both peter and mary can look in their task list for this task (code snippet from the example unit test):

 

    PeterMary都可以在他们的任务列表中看到这条任务 (代码来自实例单元测试):

// Peter and Mary are both part of management, so they both should see the task
List<Task> tasks = taskService.findGroupTasks("peter");
assertEquals(1, tasks.size());
 tasks = taskService.findGroupTasks("mary");
assertEquals(1, tasks.size());
    
// Mary claims the task
Task task = tasks.get(0);
taskService.takeTask(task.getId(), "mary");
assertNull(taskService.createTaskQuery().candidate("peter").uniqueResult());
    
taskService.completeTask(task.getId());
assertProcessInstanceEnded(processInstance);
     When the assignment should be done to a candidate user, just use the jbpm:type="user" attribute.

 

    当分配方式为候选用户时,可使用jbpm:type="user"属性。

<userTask id="myTask" name="My User task">
  <potentialOwner resourceRef="employee" jbpm:type="user">
    <resourceAssignmentExpression>
      <formalExpression>peter</formalExpression>
    </resourceAssignmentExpression>
  </potentialOwner>
</userTask>
    In this example, peter will be able to find the task since he's a candidate user for the task.

 

    在这个例子里,Peter可以看到任务,因为他是这个任务的候选用户。

List<Task> tasks = taskService.createTaskQuery().candidate("peter").list(); 
    A human performer is used when you want to assign a task directly to a certain user, group, role, etc. The way to do this looks very much like that of the potential owner.

 

    human performer用来,当你想把一个任务直接分配给一个确定人、组、角色时(这里需要注意当你分配给一个组时,系统将为该组中每一个人员建立一个任务,并不为该组建立任务)。这个方法的使用方式看起来和potential owner很像。

<resource id="employee" name="employee" />      

<process ...>

...        
         
<userTask id="myTask" name="My User task">
  <humanPerformer resourceRef="employee">
    <resourceAssignmentExpression>
      <formalExpression>mary</formalExpression>
    </resourceAssignmentExpression>
  </humanPerformer>
</userTask>

 

    In this example, the task will be directly assigned to Mary. She can now find the task in her task list:

 

    在这个例子中,任务会直接分配给Mary。她可以在自己的任务列表中看到这个任务:

List<Task> tasks = taskService.findPersonalTasks("mary");
    Since the task assignment is done through the use of a formalExpression, it's also possible to define expressions that are evaluated at runtime. The expressions itself need to be put inside a ${}, as usual in jBPM. For example, if a process variable 'user' is defined, then it can be used inside an expression. More complex expressions are of course possible.

 

    因为任务分配可以通过使用 formalExpression来完成,它也可以定义一个表达式中,该表达式在运行期进行解析。表达式本身需要放在 ${}中,这和jBPM一样。比如,如果流程变量中定义了一个'user'变量,那么它可以用在表达式中。当然也可以使用更复杂的表达式。

<userTask id="myTask" name="My User task">
  <humanPerformer resourceRef="employee">
    <resourceAssignmentExpression>
      <formalExpression>${user}</formalExpression>
    </resourceAssignmentExpression>
  </humanPerformer>
</userTask>
    Note that it is not needed to use the 'jbpm:type' on a humanPerformer element, since only direct user assignments can be done. If a task needs to be assigned to a role or group, use the potentialOwner with a group type (when you assign a task to a group, all members of that group will always be candidate users for that group - hence the usage of potentialOwner).

 

    注意不需要在humanPerformer元素中使用'jbpm:type',因为只能进行直接用户分配。如果任务需要被分配给一个角色或一个组,使用potentialOwnergroup类型(当你把任务分配给一个组时, 组中的所有成员都会成为候选用户 - 参考potentialOwner的用法)。

 

3.8.11. Task: Java Service Task(任务:Java服务任务)

 

    A Service Task is an automatic activity that calls some sort of service, such as a web service, Java service, etc. Currently, only Java service invocations are supported by the jBPM engine, but Web service invocations are planned for a future release.

 

    Service Task是一个自动活动,它会调用一系列的服务, 比如web servicejava service等等。当前jBPM引擎只支持调用java service,但是web service的调用在未来的版本中已经做了计划。



    Defining a service task requires quite a few lines of XML (the BPEL influence is certainly visible here). Of course, in the near future, we expect that tooling will simplify this area a lot. A service task is defined as follows:

 

    定义一个服务任务需要好几行XML(这里就可以看到BPEL的影响力)。 当然,在不久的未来,我们希望有工具可以把这部分大量的简化。一个服务任务需要如下定义:

<serviceTask id="MyServiceTask" name="My service task" 
  implementation="Other" operationRef="myOperation" /> 
    The service task has a required id and an optional name. The implementation attribute is used to indicate what the type of the invoked service is. Possible values are WebService, Other or Unspecified. Since we've only implemented the Java invocation, only the Other choice will do something useful for the moment.


    服务任务定义需要一个必填的
id和一个可选的 nameimplementation元素是用来表示调用服务的类型。可选值有WebService, Other或者Unspecified 因为我们只实现了Java调用,所以现在只能选择Other

 

    The service task will invoke a certain operation that is referenced by the operationRef attribute using the id of an operation. Such an operation is part of an interface as shown below. Every operation has at least one input message and at most one output message.

 

    服务任务将调用operationRef属性中引用operation。每个操作都是interface的一部分,定义如下所示。每个操作都至少有一个 输入信息,并且最多有一个输出信息。

<interface id="myInterface"
    name="org.jbpm.MyJavaServicek">
    <operation id="myOperation2" name="myMethod">
      <inMessageRef>inputMessage</inMessageRef>
      <outMessageRef>outputMessage</outMessageRef>
    </bpmn:operation>
</interface> 
    For a Java service, the name of the interface is used to specificy the fully qualified classname of the Java class. The name of the operation is then used to specify the name of the method that must be called. The input/output message that represent the parameters/return value of the Java method are defined as follows:

 

    对于java服务,接口的名称用来指定java类的全类名。操作的名称 用来指定将要调用方法名。输入/输出信息表示着java方法的参数/返回值,定义如下所示:

<message id="inputMessage" name="input message" structureRef="myItemDefinition1" />

 

    Several elements in BPMN are so-called 'item-aware', including this message construct. This means that they are involved in storing or reading items during process execution. The data structure to hold these elements is specified using a reference to an ItemDefinition. In this context, the message specifies its data structure by referencing an Itemdefinition in the structureRef attribute.

 

    包括这个消息结构在内,BPMN中很多元素叫做'item感知'。这意味着它们会在流程执行过程中保存或读取item。负责这些元素的数据结构需要使用ItemDefinition。在这个环境下,消息指定了它的数据结构,通过引用 structureRef属性中定义的ItemDefinition

<itemDefinition id="myItemDefinition1" >
    <jbpm:arg>
      <jbpm:object expr="#{var1}" />
    </jbpm:arg>
  </itemDefinition>
  
  <itemDefinition id="myItemDefinition2">
    <jbpm:var name="returnVar" />
  </itemDefinition> 
    Do note that this is not fully standard BPMN 2.0 as by the specification (hence the 'jbpm' prefix). In fact, according to the specification, the ItemDefinition shouldn't contain more than a data structure definition. The actual mapping between input paramaters, with a ceratin data structure, is done in the ioSpecification section of the serviceTask. However, the current jBPM BPMN 2.0 implementation hasn't implemented that construct yet. So, this means that the current usage as described above, will probably change in the near future.

 

    注意,这写的不完全是BPMN 2.0标准(因此都有'jbpm'的前缀)。实际上,根据标准,ItemDefinition不应该包含多余一个数据结构定义。对于输入参数的数据结构映射,应该在serviceTaskioSpecification部分来定义。然而,当前jBPM BPMN 2.0实现还没有实现。所以,这意味着上面所描述的使用方法,很可能在不久的未来就会出现变化。

 

    Important note: Interfaces, ItemDefinitions and messages are defined outside a <process>. See the example ServiceTaskTest for a concrete process and unit test.

 

    重要提醒:InterfaceItemDefinitionsMessage都需要定义在 <process>外边。可以参考实际流程和单元测试示例 ServiceTaskTest

 

  • 大小: 6.1 KB
  • 大小: 6.7 KB
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics