TaskQuery when using custom Group/User Manager
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2015 04:17 PM
Hi
I've overridden the User/Group Manager and Factories similar to the LDAP example. This means that the DB tables ACT_ID_GROUP,USER, and MEMBERSHIP are empty.
Essentially, I'd like to use the TaskQuery to grab a list of tasks for a given user; this would include all tasks where one of the following apply:
I've overridden the User/Group Manager and Factories similar to the LDAP example. This means that the DB tables ACT_ID_GROUP,USER, and MEMBERSHIP are empty.
Essentially, I'd like to use the TaskQuery to grab a list of tasks for a given user; this would include all tasks where one of the following apply:
- User is assigned
- User's id is contained in the list of the task's CandidateUsers
- One or more of User's groups are contained in the list of CandidateGroups (Groups need to be determined by GroupManager, not the DB)
The method TaskCandidateOrAssigned in TaskQuery seems to have some comments alluring to the fact that there are issues with candidate groups. Using the standard query.candidateOrAssigned() does not work correctly as it uses a direct join on the ACT_ID_MEMEBERSHIP table.
What is the correct way to obtain the tasks as required above? Or maybe I need to do multiple queries and create a union myself.
Thanks,
Bill
Labels:
- Labels:
-
Archive
7 REPLIES 7
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2015 05:22 AM
You are correct, that does seem to be tightly (too tightly!) coupled with the membership table.
I would say a custom query is the only solution to solve it (or do multiple queries, but that's not nice)
I would say a custom query is the only solution to solve it (or do multiple queries, but that's not nice)

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2015 03:58 PM
Hi all,
I have the same situation with user/groups/membership.
How to write such custom query using Activiti API?
Thanks in advance
I have the same situation with user/groups/membership.
How to write such custom query using Activiti API?
Thanks in advance
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2016 03:47 AM
how to write the custom query?my users and groups not in the same db
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2015 05:11 PM
I ended up doing something like this (obtain your groupIds for the user however you need to do it):
<java>
@Transactional(readOnly = true)
public List<Task> findCandidateTasks(User context) {
Assert.notNull(context);
String userId = context.getId();
LOG.debug("Getting assigned, candidate user, and candidate group tasks for user: {}", userId);
List<Task> candidateUserTasks = taskService.createTaskQuery().
includeProcessVariables().
taskCandidateUser(userId).
orderByTaskCreateTime().asc().list();
LOG.debug("Found: {} candidate user tasks for user: {}", candidateUserTasks.size(), userId);
List<Task> assignedTasks = taskService.createTaskQuery().includeProcessVariables().
taskAssignee(userId).orderByTaskCreateTime().asc().list();
LOG.debug("Found: {} assigned user tasks for user: {}", assignedTasks.size(), userId);
//Get your groupIds however you do it (identityService, custom method, etc.)
List<String> groupIds = getGroupIdsByUserId(userId);
List<Task> groupCandidateTasks = taskService.createTaskQuery().includeProcessVariables().
taskCandidateGroupIn(groupIds).
orderByTaskCreateTime().asc().list();
LOG.debug("Found: {} group tasks for user: {}", groupTasks.size(), userId);
Set<Task> candidateTasks = Sets.newHashSet();
candidateTasks.add(assigneeTasks);
candidateTasks.add(candidateUserTasks);
candidateTasks.add(candidateGroupTasks);
LOG.debug("got {} total group/user candidate tasks for user {}", candidateTasks.size(), userId);
List<Task> candidateTaskList = Lists.newArrayList(candidateTasks);
Collections.sort(candidateTaskList);
return candidateTaskList;
}
</java>
In my code, I actually created a TaskWrapper class to make sure both sorting works by creation date and equals uses the task id. YMMV.
<java>
@Transactional(readOnly = true)
public List<Task> findCandidateTasks(User context) {
Assert.notNull(context);
String userId = context.getId();
LOG.debug("Getting assigned, candidate user, and candidate group tasks for user: {}", userId);
List<Task> candidateUserTasks = taskService.createTaskQuery().
includeProcessVariables().
taskCandidateUser(userId).
orderByTaskCreateTime().asc().list();
LOG.debug("Found: {} candidate user tasks for user: {}", candidateUserTasks.size(), userId);
List<Task> assignedTasks = taskService.createTaskQuery().includeProcessVariables().
taskAssignee(userId).orderByTaskCreateTime().asc().list();
LOG.debug("Found: {} assigned user tasks for user: {}", assignedTasks.size(), userId);
//Get your groupIds however you do it (identityService, custom method, etc.)
List<String> groupIds = getGroupIdsByUserId(userId);
List<Task> groupCandidateTasks = taskService.createTaskQuery().includeProcessVariables().
taskCandidateGroupIn(groupIds).
orderByTaskCreateTime().asc().list();
LOG.debug("Found: {} group tasks for user: {}", groupTasks.size(), userId);
Set<Task> candidateTasks = Sets.newHashSet();
candidateTasks.add(assigneeTasks);
candidateTasks.add(candidateUserTasks);
candidateTasks.add(candidateGroupTasks);
LOG.debug("got {} total group/user candidate tasks for user {}", candidateTasks.size(), userId);
List<Task> candidateTaskList = Lists.newArrayList(candidateTasks);
Collections.sort(candidateTaskList);
return candidateTaskList;
}
</java>
In my code, I actually created a TaskWrapper class to make sure both sorting works by creation date and equals uses the task id. YMMV.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2016 07:30 AM
I have the same situation with user/groups/membership. and i use or condition, but nothing task return. why?
List<Task> tasks = taskService.createTaskQuery()
.processDefinitionKey("leaveProcess") // 后期要改
.taskAssignee(user.getUsername())
.or()
.taskCandidateUser(user.getUsername())
// .taskCandidateOrAssigned(user.getUsername())
.list();
List<Task> tasks = taskService.createTaskQuery()
.processDefinitionKey("leaveProcess") // 后期要改
.taskAssignee(user.getUsername())
.or()
.taskCandidateUser(user.getUsername())
// .taskCandidateOrAssigned(user.getUsername())
.list();

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2016 07:35 AM
if i change the code to below, it can return a task list.
List tasks = taskService.createTaskQuery()
.processDefinitionKey("leaveProcess") // 后期要改
.taskAssignee(user.getUsername())
// .taskCandidateOrAssigned(user.getUsername())
.list();
i use 5.19.0.2
List tasks = taskService.createTaskQuery()
.processDefinitionKey("leaveProcess") // 后期要改
.taskAssignee(user.getUsername())
// .taskCandidateOrAssigned(user.getUsername())
.list();
i use 5.19.0.2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2016 05:15 AM
the or() method is supposed to be used in a block with endOr(). Everything in the middle of that block will be or-ed.
