0 Replies Latest reply on Dec 3, 2014 5:06 AM by akoskm

    Retrieving the number of tasks assigned to an owner in TaskLifeCycleEventListener

    akoskm Newbie

      I already asked this on #jbpm but so far I have no idea how to implement this.


      I want to retrieve the number of tasks assigned to an owner, _after_ the task data is persisted.

      For this purpose I implemented the TaskLifeCycleEventListener interface and the afterTaskAddedEvent method like:


      public void afterTaskAddedEvent(TaskEvent event) {
          PeopleAssignments ppa = event.getTask().getPeopleAssignments();
          if (ppa != null) {
              for (OrganizationalEntity oe : ppa.getPotentialOwners()) {
                  Long taskCount = kbManager.getTaskCountByPotentialOwner(oe.getId());
                  // do something with taskCount


      I guess the problem is that I'm executing my query in a new transaction, because the tasks list is always empty . Here is the method I'm calling in from the listener:


      public long getTaskCountByPotentialOwner(String owner) {
          Query q = this.em.createNamedQuery("NewTasksAssignedAsPotentialOwner");
          List<Status> newStatus = new ArrayList();
          q.setParameter("userId", owner);
          q.setParameter("status", newStatus);
          q.setParameter("groupIds", GROUP_ID);
          Collection<AuditTaskImpl> tasks = q.getResultList();
          if (tasks == null || tasks.size() == 0) {
              return 0;
          return tasks.size();


      Note that the this.em I'm using here is created from the same EntityManagerFactory which is used to create my RuntimeEnvironment:

      RuntimeEnvironment environment = RuntimeEnvironmentBuilder.getDefault()
                                                                .registerableItemsFactory(new DefaultRegisterableItemsFactory() {
                                                                  public List<TaskLifeCycleEventListener> getTaskListeners() {
                                                                      List<TaskLifeCycleEventListener> defaultListeners = new ArrayList<>();
                                                                      defaultListeners.add(new JPATaskLifeCycleEventListener());
                                                                      // add any custom listeners
                                                                      // add listeners from deployment descriptor
                                                                      defaultListeners.add(new MyTaskLifeCycleEventListener());
                                                                      return defaultListeners;