In previous chapter we implemented a jBPM human task to understand how to execute human task node. In this tutorial we will try to understand the notification and reassignment features in human task node.
1. Tech Stack
- Java 1.8 or higher version
- Eclipse IDE for Enterprise Java Developers
- jBPM7 plugin should install with eclipse IDE
We should have the following software to create/import a jBPM Project.
2. Create Example
For our example here, we will create a process with a human task node and then run/call a human task using org.kie.api.task.TaskService and also add a custom email listener to send emails. We will create the Eclipse Maven project as follows
Download counts: 1029
- After downloading, unzip the project.
- Go to Eclipse IDE -> File -> Import -> Maven -> Existing Maven project -> Select the project.
Added two human task nodes that are Task 1 and Task 2 in the BPM process. We have added reassignment and notification within the Human Task 1 node. Let us take a quick look.
usergroup.properties
Role groups are assigned to the user. One and the same user can have several roles separated by a comma
kumar=admin,analyst,user,rest-all,kie-server
elavarasan=analyst,Accounting,PM,kie-server
ram=analyst,HR,kie-server
Human Tasks will be assigned to above users. If user not started task, will send email notification and reassign to other user.
userinfo.properties
E-mail, user language and username are assigned to the user
elavarasan=elavarasanpk@gmail.com:en-UK:elavarasan
kumar=kumar@gmail.com:en-UK:kumar
ram=ram@gmail.com:en-UK:ram
Administrator=hitechpoints@gmail.com:en-UK:Administrator
3. User and group
Tasks can be assigned to one specific user. In that case, the task will show up on the task list of that specific user only. If a task is assigned to more than one user, any of those users can claim and execute this task.
Tasks can also be assigned to one or more groups. This means that any user that is part of the group can claim and execute the task.
4. Notification in Human Task
Email notifications can be sent, allowing notifications for tasks with the following status.
- not started notify
- not completed notify
Human Task 1 is assigned to the user ‘kumar’. If ‘Kumar’ has not started the task, a notification is sent to the administrator and to Kumar after 10 seconds.
- custom.email.properties – The property has SMTP mail configuration.
mail.smtp.host=smtp.gmail.com
mail.smtp.port=587
mail.smtp.auth=true
mail.smtp.starttls.enable=true
mail.username=test26031988@gmail.com
mail.password=nujnupzhnmqciqhk
mail.from=test26031988@gmail.com
mail.replyto=test26031988@gmail.com
- CustomEmailNotificationListener.java – The class executes the email notification functionality. The email notification is implemented in the onNotification method. This method is called by Human Task Notification
public void onNotification(NotificationEvent event, UserInfo userInfo) { }
Add the CustomEmailNotificationListener.java class to org.jbpm.services.task.deadlines.NotificationListener to make it register the notification listener
5. Reassignment in Human Task
User assigned to a task can be on vacation or too busy with other work. In such cases task should be automatically reassigned to another actor or group after expiries time. Escalation can be defined for tasks that are in following statuses.
- not started reassign
- not completed reassign
Re-assign human task 1 to user ‘Elavarasan’ if user ‘kumar’ has not started the task after 1 minute
ProcessMain.java is a standalone program and contains the code to execute BPMN files. All BPMN files are loaded into kiebase as processes. We need to pass the respective process IDs to the jBPM engine to execute them.
ProcessMain.java class has processTask method. It performs a human task using org.kie.api.task.TaskService.
After running the ProcessMain.java class, we get the output as