@Override public Assignment apply(Task task, TaskContext taskContext, String excludedUser) { UserInfo userInfo = (UserInfo) ((org.jbpm.services.task.commands.TaskContext) taskContext).get(EnvironmentName.TASK_USER_INFO); List<OrganizationalEntity> excluded = getExcludedEntities(task, userInfo); // Get the the users from the task's the potential owners List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners().stream() .filter(oe -> oe instanceof User && !excluded.contains(oe)) .collect(Collectors.toList()); // Get the users belonging to groups that are potential owners task.getPeopleAssignments().getPotentialOwners().stream().filter(oe -> oe instanceof Group) .forEach(oe -> { Iterator<OrganizationalEntity> groupUsers = userInfo.getMembersForGroup((Group) oe); if (groupUsers != null) { groupUsers.forEachRemaining(user -> { if (user != null && !excluded.contains(user) && !potentialOwners.contains(user)) { potentialOwners.add(user); } }); } }); if (excludedUser != null) { logger.debug("Removing excluded user {} from the list of eligible users", excludedUser); potentialOwners.removeIf(entity -> entity.getId().equals(excludedUser)); } String queueName = getQueueName(task); CircularQueue<OrganizationalEntity> mappedQueue = synchronizedQueue(queueName, potentialOwners); OrganizationalEntity owner = mappedQueue.take(); return new Assignment(owner.getId()); }