}
final QueryFilter queryFilter = new QueryFilter(myFilter);
if (myFilter.getTaskId() != null) {
List<Integer> descendants = null;
List<Integer> ancestors = null;
final TaskNode node = taskTree.getTaskNodeById(myFilter.getTaskId());
if (myFilter.isIncludeDescendentTasks() == true) {
descendants = node.getDescendantIds();
}
if (myFilter.isInherit() == true || myFilter.isIncludeAncestorTasks() == true) {
ancestors = node.getAncestorIds();
}
if (descendants != null || ancestors != null) {
final List<Integer> taskIds = new ArrayList<Integer>();
if (descendants != null) {
taskIds.addAll(descendants);
}
if (ancestors != null) {
taskIds.addAll(ancestors);
}
taskIds.add(node.getId());
queryFilter.add(Restrictions.in("task.id", taskIds));
} else {
queryFilter.add(Restrictions.eq("task.id", myFilter.getTaskId()));
}
}
if (myFilter.getGroupId() != null) {
final GroupDO group = new GroupDO();
group.setId(myFilter.getGroupId());
queryFilter.add(Restrictions.eq("group", group));
}
final List<GroupTaskAccessDO> qlist = getList(queryFilter);
List<GroupTaskAccessDO> list;
if (myFilter.getTaskId() != null && myFilter.isInherit() == true && myFilter.isIncludeAncestorTasks() == false) {
// Now we have to remove all inherited entries of ancestor nodes which are not declared as recursive.
list = new ArrayList<GroupTaskAccessDO>();
final TaskNode taskNode = taskTree.getTaskNodeById(myFilter.getTaskId());
if (taskNode == null) { // Paranoia
list = qlist;
} else {
for (final GroupTaskAccessDO access : qlist) {
if (access.isRecursive() == false) {
final TaskNode accessNode = taskTree.getTaskNodeById(access.getTaskId());
// && myFilter.getTaskId().equals(access.getTaskId()) == false) {
if (accessNode.isParentOf(taskNode) == true) {
// This entry is not recursive and inherited, therefore this entry will be ignored.
continue;
}
}
list.add(access);