Drools 5.1.1 _ doc_drools Flow
Chapter 2 human tasks)
An important aspect of work flow and BPM is human task management. Although some work performed in the process can be automatically executed, some tasks need to be executed in interaction with human participants.
Drools streams support the use of human tasks, and use special human task nodes in the process-table this interaction. These nodes allow process designers to define task types, participants, and data associated with tasks. We also implement
A task service that can be used to manage these human tasks. However, if needed, you can enable integration with any other solution, because it is plug-in.
To start using human tasks in your process, you first need to (1) include human task nodes in your task, (2) Integrate a task management component of your choice (for example, we provide WS-HT implementation ),
(3) Use a user interface to allow end users to interact with human task management components. The following sections describe these elements in detail.
10.1. human tasks within the Process
Drools streams support the use of human tasks within a process by using a special human task node (as shown in ). The human task node represents the atomic task that needs to be executed by the human participant.
Although drools streams have a special human node used to include human tasks within a process, human tasks are simply considered to be other types of external services that need to be called,
Therefore, it can be simply implemented as a special type of work item. The only special thing about human tasks is that we must increase support for swimming lanes,
Make it easy to assign tasks to users (see later ). A human task contains the following attributes:
- ID: the node ID (which is unique in a node container ).
- Name: name of the node.
- Taskname: the name of the human task.
- Priority: an integer that indicates the priority of a human task.
- Comment: Comments associated with human tasks.
- Actorid: ID of the participant responsible for executing the human task. You can use commas as separators to specify a list of participants.
- Skippable: Specifies whether a human task can be skipped (for example, let the participants decide not to execute the human task ).
- Content: The data associated with this task.
- Lane lane: This human task is part of the lane. Swimming makes it easy to assign multiple human tasks to the same participants. For more information, see How to use the swimming pool.
- Wait for completion: If this attribute is true, the human task node will continue (that is, the completion or other termination statuses of the task) only when the human task has been terminated. Otherwise, after the human task is created, it will continue immediately.
- On-entry and On-exit actions: the action performed when the node is entered or exited.
- Parameter mapping: The parameter that allows the process variable value to be copied to the human task. When a human task is created, the value is copied.
- Result mapping: Allows copying the result parameter value of a human task to a flow variable. When a human task is completed, the value is copied. Note: You can use result ing only when "wait for completion" is set to true. The human task has a result variable "result" that contains data returned by human participants. The variable "actorid" contains the ID of the participant who actually executes the task.
- Timers: timer connected to this node (for details, see the 'timers 'Section ).
- Parentid: allows you to specify the parent task id. When this task is a subtask of another task (for details, see the 'subtask' section ).
When selecting a human task node, You can edit these variables in the attribute view, or double-click the human task node. After the custom human task editor is opened, you can also edit the most important attributes, as shown below.
Note: You can directly specify the values of different parameters (actorid, priority, content, and so on) (in this case, each execution of this process will be the same ),
You can also make the data in the process instance into a special context ). For example, you can use # {expression} for string-type parameters}
Embed a value in a string. This value is retrieved when a work item is created, and # {...} is replaced by the tostring () value of the variable. The expression can be a simple variable name (in this case, it will be parsed as the value of the variable)
But it may also be a more advanced mvel expression, such as # {person. Name. firstname }. For example, when sending an email,
The subject of an email can include such items as "dear # {customer. name },...". For other types of variables, you can use parameter ing or map the value of a variable to a parameter.
10.1.1. Swimming channels (lanes)
A human task node can be combined with a swimming pool to assign multiple human tasks to similar participants. Tasks in the same swimming pool are assigned to the same participants.
If you specify an actorid for the first task in the swimming pool, the actorid will be allocated to the swimming pool. This actorid will be used for all other tasks created in that swimming path, even if the task has been specified with an actorid.
When a human task is completed as part of a swimming track, the actorid of the swimming track is set to the actorid of the executed human task. For example,
This allows allocation of a human task to a group of users, as well as allocation of future swimming tasks to users declared by the first task. If a task is re-assigned to another user at a time point, the assignment of the task is automatically changed.
To add a human task to a swimming track, simply specify the name of the swimming track as the value of the "Transport Lane" parameter of the human task node. To do this, click the background of the Process, open the process attributes, and click "renew lanes. You can add a new swimming pool.
10.2. Human task management component
As far as the concerned drools stream engine is concerned, human tasks are similar to any other external service that needs to be called and implemented as an extension of common work items.
Therefore, the process itself contains only an abstract description of the human tasks to be executed, and a work item handler is responsible for binding this abstract task to a special implementation.
You can insert any backend (back-end) to use our pluggable work item handler (for details, see the special domain process section.
However, we provide the implementation of such a human task management component based on the WS-humantask specification. If you do not need to integrate your own special human Task component,
You can use this service. It manages the task lifecycle (creation, declaration, completion, and so on) and persistently stores the task status. It also supports functions such as internationalization, calendar integration, assignments, proxy, and term.
Since we don't want to implement a customized solution when a standard is available, we choose to implement our service based on the WS-humantask (WS-HT) Rules.
This specification defines in detail the task model, lifecycle, and many other features mentioned above. It is fairly comprehensive and can be found here in [http://download.boulder.ibm.com/ibmdl/pub/software/dw/specs/ws-bpel4people/WS-HumanTask_v1.pdf.
10.2.1. Task Lifecycle
From the process perspective, a human task is created when a human task node is triggered during the implementation of a process. When the human task has been completed or terminated
(Unless you set the "wait for completion" attribute to true and specify that the process does not need to wait for the completion of human tasks), the process will continue from that point. However,
Human tasks generally have an independent life cycle. Now let's quickly introduce this lifecycle, as shown in. For details, see the WS-humantask specification.
When a task is created, it starts from the "created" stage. It is usually automatically handed over to the "ready" status. At this time point, the task is displayed in the list of all participants allowed to execute the task.
Here, wait for one of these participants to claim the task and indicate that he or she will execute the task. Once a user claims a task, the status is changed to the "Reserved" stage. Note,
Tasks with only one potential participant are automatically assigned to the participant when the task is created. After claiming a task, the user decides to start the task at a later time. In this case,
The task status is changed to "inprogress ". Finally, once the task is executed, the user must complete the task (and can specify the result data related to the task). In this case,
The status is changed to "completed ". If the task cannot be completed, you can also use a fault response (you can use the associated fault data) to indicate it. In this case, the status is changed to "failed ".
The life cycle described above is a normal life cycle. This service also allows many other lifecycle methods, such:
- Delegate or forward a task, in which case it is assigned to another participant.
- Undo a task, so it is no longer claimed by a specific participant and re-displayed in the task list of all potential participants.
- Temporarily suspend and resume a task.
- Stop an ongoing task.
- Skip a task (if the task is marked as skipped), the task will not be executed in this case.
10.2.2. Connect the Task component to the drools stream engine.
Like any other external service, the task management component needs to register a work item Handler-responsible for converting abstract work items (in this case a human task)
For a specific call-integration with the drools stream engine. We have implemented such a work item Processing Program (Org. drools. process. workitem. wsht. wshumantaskhandler, In the drools-process-task module ),
So you can easily connect to this work item, like this:
Statefulknowledgesession session = ...;
Session. getworkitemmanager (). registerworkitemhandler ("human task", new wshumantaskhandler ());
By default, this handler will connect to the human task management component on port 9123 of the Local Machine. However, you can easily change it by calling the setconnection (IPaddress, Port) method on wshumantaskhandler.
Now, wshumantaskhandler uses Mina (http://mina.apache.org/) to test behavior in a C/S architecture. Mina uses messages between the client and the server,
Communication between the client and the server. This is why wshumantaskhandler has a minataskclient, which creates different messages for different actions executed by the server.
In this client (minataskclient in this implementation), we should understand the implementation of the following methods for interacting with human tasks:
Public void start (long taskid, string userid, taskoperationresponsehandler responsehandler)
Public void stop (long taskid, string userid, taskoperationresponsehandler responsehandler)
Public void release (long taskid, string userid, taskoperationresponsehandler responsehandler)
Public void suspend (long taskid, string userid, taskoperationresponsehandler responsehandler)
Public void resume (long taskid, string userid, taskoperationresponsehandler responsehandler)
Public void SKIP (long taskid, string userid, taskoperationresponsehandler responsehandler)
Public void delegate (long taskid, string userid, string targetuserid, taskoperationresponsehandler responsehandler)
Public void complete (long taskid, string userid, contentdata outputdata, taskoperationresponsehandler responsehandler )...
Using these methods, we will implement any type of Gui-end users will use it for their assigned tasks. If you view the signatures of these methods, you will notice that almost all of these methods obtain the following parameters:
- Taskid: ID of the task we operate on. You can pick it up from the user task list in the UI (User Interface.
- Userid: ID of the user who executes the action. User ID that can be signed in the application.
- Responsehandler: This is a processing program that captures responses and gets results, or only lets us know that the task has been completed.
As you think, all methods will create a message sent to the server, and the server will execute the logic that implements the correct action. One of the created messages may be as follows:
Public void complete (long taskid,
String userid,
Contentdata outputdata,
Taskoperationresponsehandler responsehandler ){
List <Object> ARGs = new arraylist <Object> (5 );
Args. Add (operation. Complete );
Args. Add (taskid );
Args. Add (userid );
Args. Add (null );
Args. Add (outputdata );
Command cmd = new command (counter. getandincrement (),
Commandname. operationrequest,
ARGs );
Handler. addresponsehandler (CMD. GETID (),
Responsehandler );
Session. Write (CMD );
}
Here we can see that a command is created, and the method parameter -- with the operation type we want to execute -- is inserted into the command, then this command uses session. the write (CMD) method is sent to the server.
If we look at the server implementation, when the command is received, we find that the logic to be executed depends on the operation type (this quantity is operation. Complete ).
If we look at the taskserverhandler class in the messagereceived method, when the task is created and the user does not interact with them, use taskservicesession to get, persist, and manage the human task information to execute taskoperation.
10.2.3. Start the task management component
The task management component is a completely independent service that communicates with the process engine. Therefore, we recommend that you start it as an independent service. To start the task server, you can use the following code snippet:
Entitymanagerfactory EMF = persistence. createentitymanagerfactory ("org. drools. Task ");
Taskservice = new taskservice (EMF );
Minataskserver Server = new minataskserver (taskservice );
Thread thread = new thread (server );
Thread. Start ();
The task management component uses Java persistence API (JPA) to store all task information in a persistent manner. To configure the persistence, modify the persistence. xml configuration file accordingly.
For details about how to do this, see the JPA document. The following sample shows how to use the task management component together with Hibernate and the memory database H2:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <persistence version="1.0" xsi:schemaLocation= "http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="org.drools.task"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>org.drools.task.Attachment</class> <class>org.drools.task.Content</class> <class>org.drools.task.BooleanExpression</class> <class>org.drools.task.Comment</class> <class>org.drools.task.Deadline</class> <class>org.drools.task.Comment</class> <class>org.drools.task.Deadline</class> <class>org.drools.task.Delegation</class> <class>org.drools.task.Escalation</class> <class>org.drools.task.Group</class> <class>org.drools.task.I18NText</class> <class>org.drools.task.Notification</class> <class>org.drools.task.EmailNotification</class> <class>org.drools.task.EmailNotificationHeader</class> <class>org.drools.task.PeopleAssignments</class> <class>org.drools.task.Reassignment</class> <class>org.drools.task.Status</class> <class>org.drools.task.Task</class> <class>org.drools.task.TaskData</class> <class>org.drools.task.SubTasksStrategy</class> <class>org.drools.task.OnParentAbortAllSubTasksEndStrategy</class> <class>org.drools.task.OnAllSubTasksEndParentEndStrategy</class> <class>org.drools.task.User</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> <property name="hibernate.connection.driver_class" value="org.h2.Driver"/> <property name="hibernate.connection.url" value="jdbc:h2:mem:mydb" /> <property name="hibernate.connection.username" value="sa"/> <property name="hibernate.connection.password" value="sasa"/> <property name="hibernate.connection.autocommit" value="false" /> <property name="hibernate.max_fetch_depth" value="3"/> <property name="hibernate.hbm2ddl.auto" value="create" /> <property name="hibernate.show_sql" value="true" /> </properties> </persistence-unit> </persistence>
When you start the task management component for the first time, you need to ensure that all necessary users and groups are added to the database. Before trying to assign a task to users and groups, our implementation requires that all users and groups be predefined. Therefore, make sure that you use the tasksession. adduser (user) and tasksession. addgroup (Group) Methods to add necessary users and groups to the database. Note that you need at least one "Administrator" user because all tasks are automatically assigned to this user as a management role.
The drools-process-task module contains an org. drools. task. runtaskservice class in the src/test/Java source folder, which can be used to start a Task Server. It automatically adds users and groups defined in the loadusers. mvel and loadgroups. mvel configuration files.
10.2.4. Interaction with the task management component
The task management component exposes various methods to manage the task lifecycle through a Java API. This allows the client to integrate (at a low level) task management components. Note: end users may not directly interact with this low-level interaction, but use one of the clients in the task list. These clients use these APIs to interact with the task management component.
Use the following image to describe the interaction:
As we can see in this image, we have minataskclient and minataskserver. They communicate with each other, send messages to query and operate human tasks. Step-by-Step interaction will be like this:
- Some clients need to complete some tasks. Therefore, he/she needs to create a minataskclient instance and connect it to the minataskserver to use a session to talk to each other. This is the first step in the image.
- Then, the client calls the complete () method in minataskclient with corresponding parameters. This will generate a new message (or command) and insert it into the session opened when the client connects to the server.
- This message must specify a type for the server to identify and know what to do when receiving the message. This is the second step in the image.
- At this time, taskserverhandler notices that there is a new message in the session, so there will be an analysis of the message type. In this case, it is the operation. Complete type,
- Because the client is successfully completing some tasks. Therefore, we need to complete the tasks that the user wants to complete. This is implemented through taskservicesession, which will trigger a special type of event and be processed by a special subclass of taskeventlistener. This is the third step in the image.
- When an event is received, taskeventlistener will know the status of the task if it is modified. This is to retrieve and modify the status of a specific task from the database through entitymanager. In this case,
- Because we are finishing a task, the status will be updated to completed. This is the fourth step in the image.
- Now, when the change is done, we need to notify the client that the task has been successfully completed. This is achieved by creating a response message. taskclienthandler will receive the message and inform minataskclient. This is the fifth step in the image.
10.3. Human Task Management Interface
10.3.1. Eclipse Integration
Drools ide contains an org. drools. Eclipse. Task plug-in that allows you to test and debug processes that use human tasks. In a human task view,
You can connect to a running task management component and request related tasks of a specific user (that is, the task user is a potential employer, or the task has been claimed by the user and is being run ).
Then, the lifecycle of these tasks can be executed, that is, claiming or releasing a task, starting or stopping the execution of a task, and completing a task. A screenshot of the human task view is displayed below.
You can configure the connected task management component on the drools task preference page (select Window> preferences and select drools task ). Here, you can specify the URL and port (default = 127.0.0.1: 9123)
10.3.2. webpage-based task view.
Our goal is to add a webpage-based view that end users can use to manage their drools 5.1 tasks.