-
-
Notifications
You must be signed in to change notification settings - Fork 111
Description
We've recently faced an issue when exporting MSP file and re-importing back to MSP (or to our application using MPXJ) - some tasks were moved in the hierarchy structure.
The issue was caused by wrongly calculated outlineLevel and the root cause that when constructing task graph in our code, we did not follow
depth-first search (we constructed WBS structure / summary tasks first and non-summary tasks only after that). After calling org.mpxj.TaskContainer#synchronizeTaskIDToHierarchy upon MSP export, the task IDs were re-calculated correctly but oulineLevel for some tasks was wrong.
To solve the issue, we are using custom synchronizeTaskIdToHierarchy that also re-calculates outlineLevel for each task.
private static void synchronizeTaskIdToHierarchy(ProjectFile projectFile) {
int currentId = projectFile.getTasks().getByID(0) == null ? 1 : 0;
synchronizeTaskIdToHierarchy(projectFile, currentId, 1);
}
private static int synchronizeTaskIdToHierarchy(ChildTaskContainer parentTask, int currentId, int level) {
var newId = currentId;
for (Task task : parentTask.getChildTasks()) {
task.setID(newId);
task.setOutlineLevel(level);
newId = synchronizeTaskIdToHierarchy(task, newId + 1, level + 1);
}
return newId;
}
Would not it make sense to do the same thing in the library (since both id and outlineLevel are used to create hierarchy in MSP)?