[jboss-user] [jBPM Users] - Re: EventListener questions
sebastian.s
do-not-reply at jboss.com
Wed Nov 4 15:31:54 EST 2009
I decided to use the start event because so I can use a TaskQuery instead of HistoryTaskQuery. I just want to gain access to the properties of the task the transition originates from.
process definition:
| <?xml version="1.0" encoding="UTF-8"?>
|
| <process name="process" xmlns="http://jbpm.org/4.0/jpdl" key="process" version="1">
| <start name="start1" g="74,95,48,48">
| <transition name="to task1" to="task1" g="1,-23"/>
| </start>
| <end name="end1" g="73,270,48,48"/>
| <task name="task1" g="215,141,92,52" assignee="alex">
| <on event="start">
| <event-listener class="listeners.TaskEventListener" />
| </on>
| <transition name="to task2" to="task2" g="-50,-21"/>
| </task>
| <task name="task2" g="214,270,92,52" assignee="mike">
| <transition name="to end1" to="end1" g="-48,-21"/>
| </task>
| </process>
|
EventListener:
| package listeners;
|
| import java.util.Set;
|
| import org.jbpm.api.Configuration;
| import org.jbpm.api.ProcessEngine;
| import org.jbpm.api.TaskService;
| import org.jbpm.api.listener.EventListener;
| import org.jbpm.api.listener.EventListenerExecution;
| import org.jbpm.api.task.Task;
|
| public class TaskEventListener implements EventListener {
|
| private static final long serialVersionUID = 1L;
| private ProcessEngine processEngine;
| private TaskService taskService;
|
| public TaskEventListener() {
| processEngine = Configuration.getProcessEngine();
| taskService = processEngine.getTaskService();
| }
|
| @Override
| public void notify(EventListenerExecution execution) throws Exception {
| Set<String> activities = execution.findActiveActivityNames();
| String activityName = activities.iterator().next();
| // this works: task1 (= the name of the activity is shown)
| System.out.println(activityName);
| // this does not work, getting null here
| Task task = taskService.createTaskQuery().activityName(activityName).uniqueResult();
| System.out.println(task);
| }
|
| }
|
Unit test:
| package tests;
|
|
| import java.util.List;
|
| import org.jbpm.api.Configuration;
| import org.jbpm.api.ProcessEngine;
| import org.jbpm.api.ProcessInstance;
| import org.jbpm.api.task.Task;
| import org.jbpm.test.JbpmTestCase;
|
| public class TaskEventListenerTest extends JbpmTestCase {
|
| String deploymentId;
|
| protected void setUp() throws Exception {
| super.setUp();
| ProcessEngine engine = Configuration.getProcessEngine();
| deploymentId = engine.getRepositoryService().createDeployment().addResourceFromClasspath("process.jpdl.xml").deploy();
| }
|
| public void testTaskEventListener() {
| ProcessInstance processInstance = executionService.startProcessInstanceByKey("process");
| List<Task> tasks = taskService.findPersonalTasks("alex");
| taskService.completeTask(tasks.get(0).getId());
| tasks = taskService.findPersonalTasks("mike");
| taskService.completeTask(tasks.get(0).getId());
| }
|
| protected void tearDown() throws Exception {
| repositoryService.deleteDeploymentCascade(deploymentId);
| super.tearDown();
| }
|
| }
|
Why is the task not found using the TaskQuery?
My second question would be: Why is there a citeria called processInstanceId although as far as I recall the class Task has a member variable called executionId and so is associated with its execution and not with its process instance, right?
http://docs.jboss.com/jbpm/v4/javadocs/org/jbpm/api/task/Task.html
Anyway the activityName is a better criteria because I might have several tasks active at the same time.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4264017#4264017
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4264017
More information about the jboss-user
mailing list