Information Technology Reference
In-Depth Information
In the current status of the API, the methods provided by this listener interface allow you
to implement your own code before and after any changes made to a task. The
TaskEvent class used to describe the occurrence of each event gives you a reference to
the task instance and a TaskContext object that will hold a few useful references, as
shown in the following code:
public interface TaskContext extends Context {
TaskPersistenceContext getPersistenceContext();
void setPersistenceContext(TaskPersistenceContext
context);
UserGroupCallback getUserGroupCallback();
}
A TaskPersistenceContext object gives you data access methods to query and/or
change the task persistence, especially tasks, groups, users, and task data. It also has meth-
ods to control the status of the database connection and the transaction, so they do provide
a lot of power when deciding to alter the persistence of our model.
In the project human-task-extension-points , you will find a test file called Hu-
manTaskListenersTest.java . In this file, you will find an example of using a
listener to keep an in-memory list of all the activities done in the tasks. We create a special
listener implementation called LogTaskChangeListener and add a very simple
TaskLog object for each after method of the listener, as follows:
public void afterTaskClaimedEvent(TaskEvent event) {
logs.add(new TaskLog(event.getTask().getId(),
"TaskClaimed"));
}
After this, we provide a get method for the logs we create and validate it from the test.
The process of configuring listeners for the Task Service can be done through the Hu-
manTaskServiceFactory class, as shown in the following code snippet:
TaskService taskService = HumanTaskServiceFactory.
newTaskServiceConfigurator().
entityManagerFactory(emf).
userGroupCallback(ugCallback).
Search WWH ::




Custom Search