[
https://jira.jboss.org/jira/browse/JBPM-2801?page=com.atlassian.jira.plug...
]
Per Christian Henden updated JBPM-2801:
---------------------------------------
Attachment: addExecutionIdToTaskQuery.diff
Patch to add support for querying for tasks by executionId.
Obviously will no more than one task be returned by such a query, but I don't see that
as a problem.
Support querying for Tasks by their executionId
-----------------------------------------------
Key: JBPM-2801
URL:
https://jira.jboss.org/jira/browse/JBPM-2801
Project: jBPM
Issue Type: Patch
Security Level: Public(Everyone can see)
Affects Versions: jBPM 4.x
Reporter: Per Christian Henden
Fix For: jBPM 4.x
Attachments: addExecutionIdToTaskQuery.diff
I have a case where I need to look up tasks in an EventListener.
What's available to me is the EventListenerExecution (ExecutionImpl).
I found no simple way of doing this. The attched patch adds the ability to query by
executionId in a TaskQuery, exactly like in a HistoryTaskQuery.
The simplest way to do this today (as far as I know) is:
DbSession taskDbSession = EnvironmentImpl.getFromCurrent(DbSession.class);
Task = taskDbSession.findTaskByExecution(execution);
I dislike using the DbSession object this way, it would be better to use the JBPM API.
Using HistoryTaskService (which is part of the API) is possible, but is too much work:
//Find all tasks related to the current execution
final List<HistoryTask> relatedTasks =
processEngine.getHistoryService().createHistoryTaskQuery().executionId(execution.getId()).list();
//Find all active tasks of the current execution
final List<HistoryTask> activeTasks = new ArrayList<HistoryTask>();
for (HistoryTask ht : relatedTasks) {
if (ht.getState() == null) {
activeTasks.add(ht);
}
}
if (activeTasks.size() > 1) {
throw new IllegalStateException("Got multiple matching tasks!");
} else if (activeTasks.isEmpty()) {
throw new IllegalStateException("Got no matching tasks!");
}
return activeTasks.get(0);
With the new code:
Task t =
processEngine.getTaskService().createTaskQuery().executionId(execution).uniqueResult();
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira