HumanTask engine comes with a humantask event generator. These task events are generated when a task goes trough a state transition. An event contains details about tasks and its state transition. So by writing a custom event listener to these events, a developer can easily enhance the HumanTask engine's functionalities.
What developer can do with a task event listener.
- Can do custom java code/ web service invocations.
- Can retrieve task information.
- Developer free to implement their own logic depending on their requirement.
Sample Event Listener.
EventListener class should implement HumanTaskEventListener class and onEvent method. See following sample code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.wso2.carbon.humantask.sample; | |
import org.wso2.carbon.humantask.core.api.event.HumanTaskEventListener; | |
import org.wso2.carbon.humantask.core.api.event.TaskEventInfo; | |
import org.wso2.carbon.humantask.core.dao.TaskType; | |
public class SimpleEventListener implements HumanTaskEventListener { | |
@Override | |
public void onEvent(TaskEventInfo taskEventInfo) { | |
System.out.println("[ Task ID : " + taskEventInfo.getTaskInfo().getId() + " ] [ Event : " + taskEventInfo.getEventType() + " ] at " + taskEventInfo.getTaskInfo().getModifiedDate()); | |
if (taskEventInfo.getTaskInfo().getType() == TaskType.TASK) { | |
System.out.println("\tTask Name :" + taskEventInfo.getTaskInfo().getName()); | |
System.out.println("\tTask Subject :" + taskEventInfo.getTaskInfo().getSubject()); | |
System.out.println("\tTask Description :" + taskEventInfo.getTaskInfo().getDescription()); | |
System.out.println("\tTask Owner : " + taskEventInfo.getTaskInfo().getOwner()); | |
} else if (taskEventInfo.getTaskInfo().getType() == TaskType.NOTIFICATION) { | |
System.out.println("\tNotification Name :" + taskEventInfo.getTaskInfo().getName()); | |
System.out.println("\tNotification Subject :" + taskEventInfo.getTaskInfo().getSubject()); | |
System.out.println("\tNotification Description :" + taskEventInfo.getTaskInfo().getDescription()); | |
} | |
} | |
} |
How to deploy a custom listener to WSO2 BPS
- Build a jar file of including your listener.
- Copy it into
/repository/components/lib. Where is the root directory of BPS server. - Uncomment TaskEventListeners in HumanTask configuration file (
/repository/conf/humantask.xml) and give your Event Listener class name for ClassName.
eg: - Start BPS.
- Execute a task.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<TaskEventListeners> | |
<ClassName>org.wso2.carbon.humantask.sample.SampleEventListener</ClassName> | |
</TaskEventListeners> |
Note: you can have multiple listener classes.