3 Replies Latest reply on May 17, 2010 7:28 PM by Kiran Shenoy

    How to get list of tasks for all users and processes

    Kiran Shenoy Newbie

      We are developing a applicaiton with many process definitions.  We are also creating a admin console to display all the tasks assigned to various users for various processes in the system.  I am unable to figure out how to accomplish this any ideas ?

       

      Its straight forward to display the tasks for a given actor and process definition.  But do not know how to do this for all users and processes.

       

      We are using jbpm 3.2.8 on JBoss 4.3

        • 1. Re: How to get list of tasks for all users and processes
          Walter Seymore Newbie

          You can use an HQL query like this:

           

                  hql.append("select hpi, hti, ht ");

           

                  hql.append("from ");

           

                  hql.append(HistoryTaskInstanceImpl.class.getName());

                  hql.append(" as hti ");

                  hql.append(" left join hti.historyTask as ht  ");

                  hql.append(" join hti.historyProcessInstance as hpi  ");

           

                  appendWhereClause(" hpi.state = '" + active + "' ", hql);

          • 2. Re: How to get list of tasks for all users and processes
            Maurice de Chateau Newbie

            Hi Kiran,

             

            When you're looking for tasks (I'm guessing you're interested in TaskInstances instead of their definitions here) you have the possibility to use the jBPM API, but because in this API the tasks are mostly referred to through the process instance or the user they correspond to, that can be a bit cumbersome. You'd get something like the following:

             

                    JbpmContext jbpmCtx = JbpmConfiguration.getInstance().createJbpmContext();
                    try {
                        List<TaskInstance> allTasks = new ArrayList<TaskInstance>();
                        List<ProcessDefinition> pds = jbpmCtx.getGraphSession().findAllProcessDefinitions();
                        for (ProcessDefinition pd : pds) {
                            List<ProcessInstance> pis = jbpmCtx.getGraphSession().findProcessInstances(pd.getId());
                            for (ProcessInstance pi : pis) {
                                List<TaskInstance> tis = jbpmCtx.getTaskMgmtSession().findTaskInstancesByProcessInstance(pi);
                                allTasks.addAll(tis);
                            }
                        }

             

                        // allTasks now contains all available tasks...

             

                    } finally {
                        jbpmCtx.close();
                    }

             

            It's probably easier to try to get the list of task instances more directly from the jBPM database, much like the reply above indicates. But if you're not keen on using SQL (or HQL) in your queries, something like the following would do the trick as well:

             

                   List<TaskInstance> allTasks = jbpmCtx.getSession().createCriteria(TaskInstance.class).list();

             

            Hope this helps...

             

            Regards,

            Maurice

            • 3. Re: How to get list of tasks for all users and processes
              Kiran Shenoy Newbie

              Maurice,  thanks for your reply.  This is exactly what I was looking for. I will try this out and keep you posted.