Uploaded image for project: 'jBPM'
  1. jBPM
  2. JBPM-2801

Support querying for Tasks by their executionId

XMLWordPrintable

    • Icon: Patch Patch
    • Resolution: Duplicate
    • Icon: Major 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)

      { 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();

              Unassigned Unassigned
              perchrh Per Christian Henden (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: