A.9. Activities, Tasks and Sub-Processes

A.9.1. Activity

"An Activity is work that is performed within a Business Process." [7]

This is opposed to the execution semantics of other elements that defined the Process logic.

An Activity can be further specified as a Sub-Process or a Task: while Task is atomic, that is represents a single piece of work, a Sub-Process is compound, that is it can be broken down into multiple Process elements.

An Activity in jBPM expects one incoming and one outgoing flow. If you want to design an activity with multiple incoming and multiple outgoing flows, set the value of the system property jbpm.enable.multi.con to true.

Activities have the basic properties just like any other Process element (ID and Name). Note that Activities (all of their subtypes, that is, Tasks, Sub-Process) have additional properties specific for the given Activity or Task type.

A.9.2. Activity mechanisms

A.9.2.1. Multiple instances

Activities can be run in multiple instances on execution. Individual instances are run in a sequential manner. The instances are run based on a collection of elements: for every element in the collection, a new Activity instance is created..

Every Activity has therefore the Collection Expression attribute that defines the collection with elements to iterate through.

A.9.2.2. Activity types

A.9.2.2.1. Call Activity

“A Call Activity identifies a point in the Process where a global Process or a Global Task is used. The Call Activity acts as a 'wrapper' for the invocation of a global Process or Global Task within the execution. The activation of a call Activity results in the transfer of control to the called global Process or Global Task. [8]

A Call Activity, previously Reusable Sub-Process, represents an invocation of a Process from within a Process. The Activity must have one incoming and one outgoing Flow.

When the execution flow reaches the Activity, an instance of the Process with the ID defined by the Activity is created.

Attributes

Called Element
ID of the Process to be called and instantiated by the Activity

A.9.3. Tasks

A.9.3.1. Task types

A Task is the smallest unit of work in a Process flow and to help identify the various types of Tasks that can be performed, Red Hat JBoss BPM Suite uses the BPMN guidelines to separate them based on the types of inherent behavior that the Tasks might represent.

A Task that doesn’t serve a direct defined purpose is either called the None Task or the Abstract Task (deprecated).

The different types of tasks available in JBoss BPM Suite are listed here, except for the User Task.

We define the User Task in another section (see Section A.9.5, “User Task”).

A.9.3.2. Generic Task

"Abstract Task: Upon activation, the Abstract Task completes. This is a conceptual model only; an Abstract Task is never actually executed by an IT system." [9]

A.9.3.3. Send Task

"Send Task: Upon activation, the data in the associated Message is assigned from the data in the Data Input of the Send Task. The Message is sent and the Send Task completes." [10]

Attributes

MessageRef
the MessageRef ID of the generated Message
Note

In Red Hat JBoss BPM Suite 6.x, the Send task is not supported. A custom WorkItemHandler implementation is needed to use the Send task.

A.9.3.4. Receive Task

"Upon activation, the Receive Task begins waiting for the associated Message. When the Message arrives, the data in the Data Output of the Receive Task is assigned from the data in the Message, and Receive Task completes." [11]

Attributes

MessageRef
the associated Message

A.9.3.5. Manual Task

"Upon activation, the Manual Task is distributed to the assigned person or group of people. When the work has been done, the Manual Task completes. This is a conceptual model only; a Manual Task is never actually executed by an IT system." [12]

A.9.3.6. Service Task

A Service Task is used with the built-in ServiceTaskHandler to invoke Java methods or Web Services.

Implementation
The underlying technology that will be used to implement this task. You can use unspecified or WebService where WebService is the default value.
OperationRef
This attribute specifies the operation that is invoked by the Service Task. (typically method of Java class or method of WebService).
A.9.3.6.1. Using a Service Task to Call a WebService

Service Task can be used to invoke a web service using a BPMN2 specification.

First, the web service must be configured as a part of the process definition. This can be done using a few dedicated constructs:

  1. In the process definition BPMN2 source, import the WSDL:

    <import importType="http://schemas.xmlsoap.org/wsdl/"
            location="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"
            namespace="http://ws.cdyne.com/WeatherWS/"/>
  2. Define the message, interface, and operations:

    <itemDefinition id="_2-2-4_InMessageType" />
    <message id="_2-2-4_InMessage" itemRef="_2-2-4_InMessageType" />
    
    <interface id="_2-2-4_ServiceInterface" name="" implementationRef="Weather">
      <operation id="_2-2-4_ServiceOperation" name="hello" implementationRef="GetCityWeatherByZIP">
        <inMessageRef>_2-2-4_InMessage</inMessageRef>
      </operation>
    </interface>
    IMPORTANT
    Ensure that the implementationRef attribute for both the interface and operations points to a valid service and operations in WSDL.
  3. Set the implementation attribute to a web service (the default value is used if no attribute is specified) and the operationRef attribute to the defined operation:

    <serviceTask id="_2"
                 name="Service Task"
                 operationRef="_2-2-4_ServiceOperation"
                 implementation="##WebService" >
      ...
    </serviceTask>

To use a request or response object of the service as a variable, they must all implement the java.io.Serializable interface in order to be properly persisted. To do so, configure JAXB to add the interface while generating classes from WSDL:

  1. Create an XML binding file with the following content.

    <?xml version="1.0" encoding="UTF-8"?>
    <bindings xmlns="http://java.sun.com/xml/ns/jaxb"
              xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
              xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
              xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
              version="2.1">
      <globalBindings>
        <serializable uid="1" />
      </globalBindings>
    </bindings>
  2. Add the Apache CXF Maven plugin (cxf-codegen-plugin) to the project’s pom.xml file:

    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.cxf</groupId>
          <artifactId>cxf-codegen-plugin</artifactId>
          <version>CXF_VERSION</version>
          ...
        </plugin>
      </plugins>
    <build>

A.9.3.7. Business Rule Task

“A Business Rule Task provides a mechanism for the Process to provide input to a Business Rules Engine and to get the output of calculations that the Business Rules Engine might provide. [13]

The Task defines a set of rules that need to be evaluated and fired on Task execution. Any rule defined as part of the ruleflow group in a rule resource is fired.

When a Rule Task is reached in the Process, the engine starts executing the rules with the defined ruleflow group. When there are no more active rules with the ruleflow group, the execution continues to the next Element. During the ruleflow group execution, new activations belonging to the active ruleflow group can be added to the Agenda as these are changed by the other rules. Note that the Process continues immediately to the next Element if there are no active rules of the ruleflow group.

If the ruleflow group was already active, the ruleflow group remains active and the execution continues if all active rules of the ruleflow group have been completed.

Attributes

RuleFlow Group
the name of the rule flow group that includes the set of rules to be evaluated by the Task

A.9.3.8. Script Task

A Script Task represents a script that should be executed during the Process execution.

The associated Script can access any variables and globals.

When using a Script Task follow these rules:

  • Avoid low-level implementation details in the Process: A Script Task could be used to manipulate variables but other concepts like a Service Task should be your first choice when modeling more complex behavior in a higher-level manner.
  • The script should be executed immediately; if there is the possibility that the execution could take some time, use an asynchronous Service Task.
  • Avoid contacting external services through a Script Task: it would be interacting with external services without the knowledge of the engine, which can be problematic. Model communication with an external service using a Service Task.
  • Scripts should not throw exceptions. Runtime exceptions should be caught and for example managed inside the script or transformed into signals or errors that can then be handled inside the process.

When a Script Task is reached during execution, the script is performer and the outgoing Flow is taken.

Script
script to be executed
ScriptLanguage
language the script is defined in (currently supported languages are Java, JavaScript, and MVEL)

From JBoss BPM Suite 6.2 onwards, JavaScript is supported as dialect in Script Tasks. To define a Script Task in Business Central and JBoss Developer Studio using the process design tool:

  1. Select a Script Task object from the Object Library menu on the left hand side and add it to the process design tool.
  2. In the Properties panel on the right hand side, open the Script property.
  3. Add the script to be executed to the Expression Editor and click Ok.

Example A.8. Script Task in Business Central using JavaScript

Script Task JavaScript

A.9.4. Sub-Process

“A Sub-Process is an Activity whose internal details have been modeled using Activities, Gateways, Events, and Sequence Flows. A Sub-Process is a graphical object within a Process, but it also can be 'opened up’to show a lower-level Process. [14]

Therefore, a Sub-Process can be understood as a compound Activity or a Process in a Process. When reached during execution, the Element context is instantiated and the encapsulated process triggered. Note that, if you use a Terminating End Event inside a Sub-Process, the entire Process instance that contains the Sub-Process is terminated, not just the Sub-Process. A Sub-Process, just like a Process, ends when there are no more active Elements in it.

The following Sub-Process types are supported:

  • Ad-Hoc Sub-Process: Sub-Process with no strict Element execution order
  • Embedded Sub-Process: a "real" Sub-Process that is a part of the Parent Process execution and shares its data
  • Reusable Sub-Process: a Sub-Process that is independent from its parent Process
  • Event Sub-Process: a Sub-Process that is only triggered on a start event or a timer.

Note that any Sub-Process type can be also a Multi-Instance Sub-Process.

A.9.4.1. Embedded Sub-Process

An Embedded Sub-Process is a Sub-Process that encapsulates a part of the process.

It must contain a Start Event and at least one End Event. Note that the Element allows you to define local Sub-Process variables, that are accessible to all Elements inside this container.

A.9.4.2. AdHoc Sub-Process

“An Ad-Hoc Sub-Process is a specialized type of Sub-Process that is a group of Activities that have no REQUIRED sequence relationships. A set of Activities can be defined for the Process, but the sequence and number of performances for the Activities is determined by the performers of the Activities. [15]

“An Ad-Hoc Sub-Process or Process contains a number of embedded inner Activities and is intended to be executed with a more flexible ordering compared to the typical routing of Processes. Unlike regular Processes, it does not contain a complete, structured BPMN diagram description—i.e., from Start Event to End Event. Instead the Ad-Hoc Sub-Process contains only Activities, Sequence Flows, Gateways, and Intermediate Events. An Ad-Hoc Sub-Process MAY also contain Data Objects and Data Associations. The Activities within the Ad-Hoc Sub- Process are not REQUIRED to have incoming and outgoing Sequence Flows. However, it is possible to specify Sequence Flows between some of the contained Activities. When used, Sequence Flows will provide the same ordering constraints as in a regular Process. To have any meaning, Intermediate Events will have outgoing Sequence Flows and they can be triggered multiple times while the Ad-Hoc Sub-Process is active.[16]

The Elements of an AdHoc Sub-Process are executed in parallel.

AdHocCompletionCondition
the condition that once met the execution is considered successful and finishes
AdHocCancelRemainingInstances
if set to true, once the AdHocCompletionCondition is met, execution of any Elements is immediately canceled.

A.9.4.3. Multi-instance Sub-Process

A Multiple Instance Sub-Process is a Sub-Process that is instantiated/run multiple times when its execution is triggered. The instances are created in a sequential manner: a new Sub-Process instance is created only after the previous instance has finished.

A Multiple instance Sub-Process has one incoming Connection and one outgoing Connection.

Collection expression

Variable that represents the collection of elements that are to be iterated over (The variable must be an array or be of the java.util.Collection type.)

If the collection expression evaluates to null or an empty collection, the Multi-Instances Sub-Process is completed immediately and the outgoing flow is taken.

Variable Name
Variable that will store the collection element used in the currently running iteration

A.9.4.4. Event Sub-Process

An Event Sub-Process becomes active when its start event gets triggered. It can interrupt the parent process context or run in parallel to it.

With no outgoing or incoming connections, only an event or a timer can trigger these Sub-Processes. These Sub-Processes are not part of the regular control flow. Although self-contained, they are executed in the context of the bounding Sub-Process.

You would use these Sub-Processes within a process flow to handle events that happen external to the main process flow. For example, while booking a flight, two events may occur: (interrupting) cancel booking, or (non-interrupting) check booking status. Both these events can be modeled using the Event Sub-Process.

A.9.5. User Task

"A User Task is a typical 'workflow' Task where a human performer performs the Task with the assistance of a software application and is scheduled through a task list manager of some sort." [17]

The User Task cannot be performed automatically by the system and therefore requires an intervention of a human user, the Actor. Also, it is relatively atomic as opposed to such non-atomic Elements as Sub-Processes.

On execution, the User Task element is instantiated as a User Task that appears in the list of Tasks of one or multiple Actors.

If a User Task element defines a GroupID, it is displayed in Task lists of all users that are members of the group: any of the users can claim the Task. Once claimed, the Task disappears from the Task lists of the other users.

Note that User Task is implemented as a domain-specific Tasks and serve as base for your custom Task (see Section 4.15.1, “Work Item Definition”).

Actors
comma-separated list of users who are entitled to perform the generated User Task
Comment
A comment associated with this User Task. The JBoss BPM Suite Engine does not use this field but business users can enter extra information about this task.
Content
The data associated with this task. This attribute does not affect TaskService’s behavior.
CreatedBy
name of the user or ID of the Process that created the task
GroupID
comma-separated list of groups who are entitled to perform the generated User Task
Locale
locale the Element is defined for. This was intended to support internationalization (i18n), but this property is not used by the JBoss BPM Suite engine at the moment.
Notifications
Definition of notification applied on the Human Task (see Section A.9.5.3, “Notification” )
Priority
Integer value defining the User Task priority (the value influences the User Task ordering in the user Task list and the simulation outcome)
Reassignment
Definition of escalation applied on the Human Task (see Section A.9.5.2, “Reassignment” )
ScriptLanguage
One of Java or MVEL.
Skippable
Boolean value that defines if the User Task can be skipped (if true, the actor of the User Task can decide not to complete it and the User Task is never executed)
Task Name
Name of the User Task generated on runtime (displayed in the Task List of Business Central)

Note that any other displayed attributes are used by features not restricted to the User Task element and are described in the chapters dealing with the particular mechanism.

A.9.5.1. User Task lifecycle

When a User Task element is encountered during Process execution, a User Task instance is created. The User Task instance execution is preformed by the User Task service of the Task Execution Engine (see the Red Hat JBoss BPM Suite Administration and Configuration Guide ). The Process instance leaves the User Task element and continues the execution only when the associated User Task has been completed or aborted.

When the Process instance enters the User Task element, the User Task is the Created stage. This is usually a transient state and the User Task enters the Ready state immediately: the User Task appears in the Task Lists of all actors that are allowed to execute the task. As soon as one of the actors claims the User Task to indicate they are executing it, the User Task becomes Reserved. If a User Task has only one potential actor, it is automatically assigned to that actor upon creation. When the user who has claimed the User Task starts the execution, the User Task status changes to InProgress. On completion, the status changes to Completed or Failed depending on the execution outcome.

Note that the User Task lifecycle can include other statuses if the User Task is reassigned (delegated or escalated), revoked, suspended, stopped, or skipped. For further details, on the User Task lifecycle see the Web Services Human Task specification.

A.9.5.2. Reassignment

The reassignment mechanism is the mechanism implementing the escalation and delegation capabilities for User Tasks, that is, automatic reassignment of a User Task to another actor or group after a User Task has remained inactive for a certain amount of time.

Reassignment can be defined to take place either if the given User Task is for a given time in either of the following states:

  • not started: READY or RESERVED
  • not completed: IN_PROGRESS

When the conditions defined in the reassignment are met, the User Task is reassigned to the users or groups defined in the reassignment. If the actual owner is included in the new users or groups definition, the User Task is reset and reset to the READY state.

Reassignment is defined in the Reassignment property of User Task elements. The property can take an arbitrary number of reassignment definitions with the following parameters:

  • Users: comma-separated list of user IDs that are reassigned to the task on escalation (Strings or expressions #{user-id})
  • Groups: comma separated list of group IDs that are reassigned to the task on escalation (Strings or expressions #{group-id})
  • Expires At: time definition when escalation is triggered (String values and expressions #{expiresAt}; for information on time format, see Section A.5, “Timing”)
  • Type: state the task needs to be in at the given Expires At time so that the escalation is triggered.

A.9.5.3. Notification

The Notification mechanism provides the capability to send an e-mail notification if a User Task is at the given time in one of the following states:

  • not started: READY or RESERVED
  • not completed: IN_PROGRESS

Notification is defined in the Notification property of User Task elements. The property can take an arbitrary number of notification definitions with the following parameters:

  • Type: state the User Task needs to be in at the given Expires At time so that the notification is triggered
  • Expires At: time definition when notification is triggered (String values and expressions #{expiresAt}; for information on time format, see Section A.5, “Timing”)
  • From: user or group ID of users used in the From field of the email notification message (Strings or expressions)
  • To Users: comma-separated list of user IDs the notification is to be sent to (Strings or expressions #{user-id})
  • To Groups: comma separated list of group IDs the notification is to be sent to (Strings or expressions #{group-id})
  • Reply To: user or group ID that receives any replies to the notification (Strings or expressions #{group-id})
  • Subject: subject of the email notification (Strings or expressions)
  • Body: body of the email notification (Strings and expression)
Available variables

Notification can reference Process variables (#{processVariable}) and Task variables (${taskVariable}).

In addition to custom Task variables, the notification mechanism can make use of the following local Task variables:

  • taskId: internal ID of the User Task instance
  • processInstanceId: internal ID of Task’s parent Process instance
  • workItemId: internal ID of a work item that created the User Task
  • processSessionId: knowledge session ID of the parent Process instance
  • owners: list of users and groups that are potential owners of the User Task
  • doc: map that contains regular task variables

Example A.9. Body of notification with variables

<html>
	<body>
		<b>${owners[0].id} you have been assigned to a task (task-id ${taskId})</b><br>
		You can access it in your task
		<a href="http://localhost:8080/jbpm-console/app.html#errai_ToolSet_Tasks;Group_Tasks.3">inbox</a><br/>
		Important technical information that can be of use when working on it<br/>
		- process instance id - ${processInstanceId}<br/>
		- work item id - ${workItemId}<br/>

		<hr/>

		Here are some task variables available
		<ul>
			<li>ActorId = ${doc['ActorId']}</li>
			<li>GroupId = ${doc['GroupId']}</li>
			<li>Comment = ${doc['Comment']}</li>
		</ul>
		<hr/>
		Here are all potential owners for this task
		<ul>
		$foreach{orgEntity : owners}
			<li>Potential owner = ${orgEntity.id}</li>
		$end{}
		</ul>

		<i>Regards from jBPM team</i>
	</body>
</html>


[7] Business Process Model and Notation (BPMN). Version 2.0, OMG Document Number: formal/2011-01-03 http://www.omg.org/spec/BPMN/2.0
[8] Business Process Model and Notation (BPMN). Version 2.0, OMG Document Number: formal/2011-01-03 http://www.omg.org/spec/BPMN/2.0
[9] Business Process Model and Notation (BPMN). Version 2.0, OMG Document Number: formal/2011-01-03 http://www.omg.org/spec/BPMN/2.0
[10] Business Process Model and Notation (BPMN). Version 2.0, OMG Document Number: formal/2011-01-03 http://www.omg.org/spec/BPMN/2.0
[11] Business Process Model and Notation (BPMN). Version 2.0, OMG Document Number: formal/2011-01-03 http://www.omg.org/spec/BPMN/2.0
[12] Business Process Model and Notation (BPMN). Version 2.0, OMG Document Number: formal/2011-01-03 http://www.omg.org/spec/BPMN/2.0
[13] Business Process Model and Notation (BPMN). Version 2.0, OMG Document Number: formal/2011-01-03 http://www.omg.org/spec/BPMN/2.0
[14] Business Process Model and Notation (BPMN). Version 2.0, OMG Document Number: formal/2011-01-03 http://www.omg.org/spec/BPMN/2.0
[15] Business Process Model and Notation (BPMN). Version 2.0, OMG Document Number: formal/2011-01-03 http://www.omg.org/spec/BPMN/2.0
[16] Business Process Model and Notation (BPMN). Version 2.0, OMG Document Number: formal/2011-01-03 http://www.omg.org/spec/BPMN/2.0
[17] Business Process Model and Notation (BPMN). Version 2.0, OMG Document Number: formal/2011-01-03 http://www.omg.org/spec/BPMN/2.0