[
https://jira.jboss.org/browse/JBPM-2801?page=com.atlassian.jira.plugin.sy...
]
HuiSheng Xu updated JBPM-2801:
------------------------------
Fix Version/s: (was: jBPM 4.x)
Support querying for Tasks by their executionId
-----------------------------------------------
Key: JBPM-2801
URL:
https://jira.jboss.org/browse/JBPM-2801
Project: jBPM
Issue Type: Patch
Security Level: Public(Everyone can see)
Affects Versions: jBPM 4.x
Reporter: Per Christian Henden
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/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira