cancel
Showing results for 
Search instead for 
Did you mean: 

All tasks belonging to group A and B

torak
Champ in-the-making
Champ in-the-making
Hello!

I wish to find all tasks that have candidate groups A and B. In other others tasks that belongs to both groups (intersection), and not only one of them.

I have tried different ways, but can't find a solution, any tips?

Thanks

Edit - to clarify:

<userTask id=1 activiti:candidateGroups="A"/>
<userTask id=2 activiti:candidateGroups="A,B"/>

Users that are member of A should get task 1
Users that are member of A,B should get task 1 and 2

So the user has to be member of all the groups for it get the tasks.
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
Torak,

Currently there is no way of querying this in a single query.

Perhaps you can try to combine 2 queries (remove the duplicates):


List<Task> groupATasks = taskService.createTaskQuery().candidateGroup("A").list();
List<Task> groupBTasks = taskService.createTaskQuery().candidateGroup("B").list();

List<Task> tasks = mergeLists(groupATasks, groupBTasks);

torak
Champ in-the-making
Champ in-the-making
Fredrik, thanks for your answer.

This would give me the union of the tasks. However, my criteria for being a candidate is to be member of all the candidate groups for the task. Do you think it's possible to get such a list?

I think the following code should give such a list (if there had been a getCandidateGroups method in the task class.. Smiley Wink


List<Task> candiateTaskList = new ArrayList<Task>();

for(Task task: processEngine.getTaskService().createTaskQuery().taskUnnassigned().list()){
  boolean memberOfAllGroups = true;
  for(String canidateGroup: task.getCandidateGroups()){
       if(!userGroups.contains(canidateGroup)){
           memberOfAllGroups = false;
        }
    }
  if(memberOfAllGroups){
       candiateTaskList.add(task);
   }
}

Is there way to get the candidate groups for a task?

frederikherema1
Star Contributor
Star Contributor
Instead of creating the union of lists groupATasks and groupBTasks, creating the intersection should work…

Querying all tasks, and running trough them to check which candidate groups the task has, can introduce performance/memory issues when a lot of tasks are present. Limiting the query by groupA and groupB limits the tasks returned…

torak
Champ in-the-making
Champ in-the-making
Hey, you are right. I get the intersection like that.

However, it would have been great if there was first-class support for OR(union) and AND(intersection) in the query framework! Smiley Happy

Thanks.