When I create children tasks, generated a wrong task ID:
public static void main(String[] args) throws IOException {
Project project = new Project();
project.set(Prj.DURATION_FORMAT, TimeUnitType.Hour);
Task rootTask = project.getRootTask();
Task a = rootTask.getChildren().add("A");
a.set(Tsk.DURATION, project.getDuration(0.5d, TimeUnitType.Day));
Task b = project.getRootTask().getChildren().add("B");
b.set(Tsk.DURATION, project.getDuration(0.5d, TimeUnitType.Day));
Task c = project.getRootTask().getChildren().add("C");
c.set(Tsk.DURATION, project.getDuration(0.5d, TimeUnitType.Day));
Task a2 = a.getChildren().add("A2");
a2.set(Tsk.DURATION, project.getDuration(0.5d, TimeUnitType.Day));
printTask(a);
printTask(a2);
printTask(b);
printTask(c);
}
private static void printTask(Task task) {
System.out.println(task.get(Tsk.ID) + " | " + task.get(Tsk.NAME) + " | " + task.get(Tsk.START) + " | " + task.get(Tsk.FINISH) + " | " + task.get(Tsk.DURATION));
}
Result:
1 | A | Wed Aug 26 08:00:00 BRT 2020 | Wed Aug 26 12:00:00 BRT 2020 | 0,5 days
4 | A2 | Wed Aug 26 08:00:00 BRT 2020 | Wed Aug 26 12:00:00 BRT 2020 | 0,5 days
2 | B | Wed Aug 26 08:00:00 BRT 2020 | Wed Aug 26 12:00:00 BRT 2020 | 0,5 days
3 | C | Wed Aug 26 08:00:00 BRT 2020 | Wed Aug 26 12:00:00 BRT 2020 | 0,5 days
The A2 task should be 2.
Another error happens using project.recalculate():
Project project = new Project();
project.set(Prj.DURATION_FORMAT, TimeUnitType.Hour);
project.setCalculationMode(CalculationMode.None);
Task rootTask = project.getRootTask();
Task a = rootTask.getChildren().add("A");
a.set(Tsk.DURATION, project.getDuration(0.5d, TimeUnitType.Day));
Task b = project.getRootTask().getChildren().add("B");
b.set(Tsk.DURATION, project.getDuration(0.5d, TimeUnitType.Day));
Task c = project.getRootTask().getChildren().add("C");
c.set(Tsk.DURATION, project.getDuration(0.5d, TimeUnitType.Day));
project.setCalculationMode(CalculationMode.Automatic);
project.recalculate();
Task d = project.getRootTask().getChildren().add("D");
c.set(Tsk.DURATION, project.getDuration(0.5d, TimeUnitType.Day));
printTask(a);
printTask(b);
printTask(c);
printTask(d);
Result:
1 | A | Wed Aug 26 08:00:00 BRT 2020 | Wed Aug 26 12:00:00 BRT 2020 | 0,5 days
2 | B | Wed Aug 26 08:00:00 BRT 2020 | Wed Aug 26 12:00:00 BRT 2020 | 0,5 days
3 | C | Wed Aug 26 08:00:00 BRT 2020 | Wed Aug 26 12:00:00 BRT 2020 | 0,5 days
5 | D | Wed Aug 26 08:00:00 BRT 2020 | Wed Aug 26 17:00:00 BRT 2020 | 8 hrs
The D task should be 4.
Version:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-tasks</artifactId>
<version>20.7</version>
<classifier>jdk17</classifier>
</dependency>