5 Replies Latest reply on Aug 26, 2009 5:49 AM by freak182

    Query on remaining task

      Hello,

      I have to display the next possible task aside from the current task in the task instance.

      here is the scenario:

      I have a process definition compose of 5 task: A, B, C, D, E
      Now, I started the process then the current task is A and it is in taskinstance table. Now when the user process task A, A now is in completed stated while task B is in on_progress state. both task A and B now in taskinstance table for specified process instance.

      Now problem is how can I display the next possible not completed task. In this case B (still on on_progress state), C, D, E.

      version used: jbpm 3.2.5

      Thanks a lot.
      Cheers.

        • 1. Re: Query on remaining task
          kukeltje

          Display where? In the tasklist? Or the taskform of this task? Or.....?

          • 2. Re: Query on remaining task

            Hello,

            Sorry, just wanted to have the list of all possible task.

            Thanks a lot.
            Cheers.

            • 3. Re: Query on remaining task

              Try TaskQuery, it may be useful to you

              • 4. Re: Query on remaining task
                kukeltje

                all non-completed but started tasks are in the console. You *might* need to use the refresh button though

                • 5. Re: Query on remaining task

                  Hello,

                  Just wanted to share how I accomplished this query. although it is not, let say hibernate way or jbpm way, but it work.

                  
                  @SuppressWarnings("unchecked")
                   public List<Task> findNextTasksByProcessInstance(final ProcessInstance process)
                   {
                   try {
                   return (List<Task>) jbpmTemplate.execute(new JbpmCallback() {
                  
                   public Object doInJbpm(JbpmContext context)
                   throws JbpmException {
                  
                   final long processDefId = process.getProcessDefinition().getId();
                  
                   final GraphSession sess = context.getGraphSession();
                   final ProcessDefinition def = sess.getProcessDefinition(processDefId);
                   final Map<String, Task> task = def.getTaskMgmtDefinition().getTasks();
                   final Set<String> taskSet = task.keySet();
                  
                   final Session session = context.getSession();
                   final Query query = session.getNamedQuery("findNextTasksByProcessInstance");
                   query.setEntity("processInstance", process);
                   final List<String> taskInstance = query.list();
                  
                   return JbpmEngineUtils.getNextTasks(taskSet, taskInstance, task);
                   }
                   });
                   } catch (Exception e) {
                   throw new CCTIException("No task instance get", e);
                   }
                   }
                  


                  then subtract the activeTask from possibletask:

                  public static List<String> getNextTasks(Set<String> possibleTask,List<String> completedTask,Map<String,Task> task)
                   {
                   final List<String> nextTasks = new ArrayList<String>();
                  
                   final Set<String> tmpPossibleTask = new HashSet<String>(possibleTask);
                   final List<String> tmpActiveTask = new ArrayList<String>(completedTask);
                   final Map<String, Task> mapTask = new HashMap<String, Task>(task);
                  
                   for(String s : tmpActiveTask)
                   {
                   if ( tmpPossibleTask.contains(s) )
                   {
                   tmpPossibleTask.remove(s);
                   }
                   }
                   Iterator<String> ite = tmpPossibleTask.iterator();
                   while (ite.hasNext()) {
                   final String string = ite.next();
                   final Task taskLeft = mapTask.get(string);
                   nextTasks.add(taskLeft.getDescription());
                   }
                   return nextTasks;
                   }