5 Replies Latest reply on Oct 8, 2010 4:14 PM by shannonsumner

    Find Tasks by Candidate-Group Name

    shannonsumner

      Hello all,

       

      Is there a way to find all Tasks by Candidate-Group name?  I.E.  If 5 tasks are unassigned but have a candidate-group of 'Sales Department' - can I query them if I only know the Candidate-Group name?

       

      I hope that makes sense,

       

      Shannon

        • 1. Re: Find Tasks by Candidate-Group Name
          mwohlf

          I don't think this is possible with the API, but you certainly can do this with a bit of hql hackery, the database schema is here:

          http://community.jboss.org/wiki/jbpm4DataBaseModel

          check the JBPM4_PARTICIPATION table for the entries with the group names and find the associated tasks

          • 2. Re: Find Tasks by Candidate-Group Name
            wcanom

            I also need to query  the tasks for the group's ID_. Could someone give an example of how to check the participation of a group task.

             

            thanks

            • 3. Re: Find Tasks by Candidate-Group Name
              mwohlf

              Hi William,

              I suppose this is what you want to do:

               

              public class TaskCandidatesTest extends JbpmTestCase {
              
                public void testCandidatePutsTaskBackInGroup() {
                  deployJpdlXmlString(
                    "<process name='CandidatePutsTaskBackInGroup'>" +
                    "  <start>" +
                    "    <transition to='review' />" +
                    "  </start>" +
                    "  <task name='review' " +
                    "        candidate-groups='sales-dept'>" +
                    "    <transition to='wait' />" +
                    "  </task>" +
                    "  <state name='wait'/>" +
                    "</process>"
                  );
                  
                  ProcessInstance processInstance = executionService.startProcessInstanceByKey("CandidatePutsTaskBackInGroup");
                  String pid = processInstance.getId();
                  
                  Task task = taskService.createTaskQuery().processInstanceId(pid).uniqueResult();
                  assertNull(task.getAssignee());
              
                  processEngine.execute(
                     new Command<Void>() {
                       public Void execute(Environment environment) throws Exception {
                         DbSessionImpl dbSessionImpl = environment.get(DbSessionImpl.class);
                         Session session = dbSessionImpl.getSession();
                         assertNotNull(session);
                         
                         List<Task> list =
                         session.createQuery(
                                 " select p.task from " + ParticipationImpl.class.getName() + " p "
                                 + " where p.groupId = :groupId ")
                           .setParameter("groupId", "sales-dept")
                           .list();
              
                          assertEquals(1, list.size());
                          assertEquals("review", list.get(0).getName());
              
                         return null;
                       }
                     }
                  );
              
                  taskService.takeTask(task.getId(), "johndoe");
                  
                  task = taskService.createTaskQuery().processInstanceId(pid).uniqueResult();
                  assertEquals("johndoe", task.getAssignee());
              
                  taskService.assignTask(task.getId(), null);
                  
                  task = taskService.getTask(task.getId());
                  assertNull(task.getAssignee());
                }
               
              }
              
              
              
              • 4. Re: Find Tasks by Candidate-Group Name
                wcanom

                Thanks Michael. This was exactly what I needed. I am new to  JBPM 4 programming model  and had no idea how to create and execute the command. Again many thanks.

                • 5. Re: Find Tasks by Candidate-Group Name
                  shannonsumner

                  Thanks Michael - this is what I came up with ...

                   

                   

                  /**
                       * Gets the unassigned tasks by group.
                       *
                       * @param strGroupId
                       *             the str group id
                       * @return the unassigned tasks by group
                       */
                      private List<Task> getUnassignedTasksByGroup(final String strGroupId)
                      {
                          final ParamCommand<List<Task>> paramCommand = new ParamCommand<List<Task>>()
                          {
                  
                              private static final long serialVersionUID = 1L;
                  
                              @SuppressWarnings("unchecked")
                              public final List<Task> execute(final Environment environment)
                              {
                                  DbSessionImpl dbSessionImpl = environment
                                          .get(DbSessionImpl.class);
                                  Session session = dbSessionImpl.getSession();
                  
                                  return session
                                          .createQuery(
                                                  " select participation.task from "
                                                          + ParticipationImpl.class
                                                                  .getName()
                                                          + " participation "
                                                          + " join participation.task as task "
                                                          + " where participation.groupId = :groupId"
                                                          + " and task.assignee is null ")
                                          .setParameter("groupId", params.get("strGroupId"))
                                          .list();
                  
                              }
                          };
                  
                          return processEngine.execute(paramCommand.setParam("strGroupId",
                                  strGroupId));
                  
                      }
                  
                      /**
                       * Gets the workgroup tasks by group.
                       *
                       * @param strGroupId
                       *             the str group id
                       * @return the workgroup tasks by group
                       */
                      private List<Task> getWorkgroupTasksByGroup(final String strGroupId)
                      {
                          final ParamCommand<List<Task>> paramCommand = new ParamCommand<List<Task>>()
                          {
                  
                              private static final long serialVersionUID = 1L;
                  
                              @SuppressWarnings("unchecked")
                              public final List<Task> execute(final Environment environment)
                              {
                                  DbSessionImpl dbSessionImpl = environment
                                          .get(DbSessionImpl.class);
                                  Session session = dbSessionImpl.getSession();
                  
                                  return session
                                          .createQuery(
                                                  " select participation.task from "
                                                          + ParticipationImpl.class
                                                                  .getName()
                                                          + " participation "
                                                          + " join participation.task as task "
                                                          + " where participation.groupId = :groupId"
                                                          + " and task.assignee is not null ")
                                          .setParameter("groupId", params.get("strGroupId"))
                                          .list();
                  
                              }
                          };
                  
                          return processEngine.execute(paramCommand.setParam("strGroupId",
                                  strGroupId));
                  
                      }