AnsweredAssumed Answered

Fetch tasks that are available to be claimed by a specific user

Question asked by jwestra on Mar 15, 2016
Latest reply on Mar 25, 2016 by jbarrez
I just want to be sure I'm not missing an API somewhere.

Goal: fetch tasks that are available to be claimed by a specific user.

My requirements for the list are as follows:
———————————————
1. Tasks must be unassigned (assignee == null)
2. Includes: All tasks where candidate groups is empty and candidate users is empty (e.g., anybody can claim these tasks)
3. Includes: All tasks where my user is a member of any candidate groups
4. Includes: All tasks where my user is specified a candidate user

It appears from the TaskQuery APIs that this is several queries and then mixing & matching to get a distinct set of Tasks to return. 

Here are the queries I am making to achieve the goal above, but it is 3 queries and I use a Set<Task> to weed out duplicates as well.
Am I doing it all wrong here??


public List<Task> findAvailableTasks(String user, List<String> groups) {
      Set<Task> availableTasks = new HashSet<Task>();
      
      if (groups!= null && !groups.isEmpty()) {
             List<Task> candidateGroupTasks = taskService.createTaskQuery()
               .taskCandidateGroupIn(groups)
               .list();
         
         availableTasks.addAll(candidateGroupTasks);
      }
      
      List<Task> candidateUserTasks = taskService.createTaskQuery()
            .taskCandidateUser(user)
            .list();
               
      availableTasks.addAll(candidateUserTasks);
      
      List<Task> unassignedTasks = taskService.createTaskQuery()
            .taskUnassigned()
            .list();
               
      availableTasks.addAll(unassignedTasks);
      
         /* This compiles but returns nothing.
                            I don't know what I am doing here for sure!
         availableTasks = taskService.createTaskQuery()
               .taskCandidateGroupIn(groups)
               .or()
               .taskCandidateUser(user)
               .endOr()
               .or()
               .taskUnassigned()
               .endOr()
               .orderByTaskPriority()
               .desc()
               .list();
         */
      
      
      return new ArrayList<Task>(availableTasks);
   }

Outcomes