}
private TaskObject addTask(final TaskTree taskTree, final List<TaskObject> topLevelTasks, final TaskDO task,
final Map<Integer, TaskObject> rtaskMap)
{
TaskObject rtask = rtaskMap.get(task.getId());
if (rtask == null) {
// ancestor task not part of the result list, create it:
if (taskDao.hasSelectAccess(PFUserContext.getUser(), task, false) == false) {
// User has no access, ignore this part of the task tree.
return null;
}
rtask = createRTask(task);
rtaskMap.put(task.getId(), rtask);
}
final TaskDO parent = taskTree.getTaskById(task.getParentTaskId());
if (parent == null) {
// this is the root node, ignore it:
return null;
}
if (taskTree.isRootNode(parent) == true) {
topLevelTasks.add(rtask);
return rtask;
}
TaskObject parentRTask = rtaskMap.get(task.getParentTaskId());
if (parentRTask == null) {
// Get and insert parent task first:
parentRTask = addTask(taskTree, topLevelTasks, parent, rtaskMap);
}
if (parentRTask != null) {
parentRTask.add(rtask);
}
return rtask;
}