-
Patch
-
Resolution: Duplicate
-
Major
-
None
-
jBPM 4.x
-
None
-
None
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)
}
if (activeTasks.size() > 1)
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();
- duplicates
-
JBPM-2901 add executionId Parameter for TaskQuery
- Resolved