/** * Creates a new GanttTask and copies all fields from the given task (excluding the predecessor and any children). * @param task * @return */ public static final GanttTask convertToGanttObject(final TaskDO task) { final GanttTaskImpl ganttObject = new GanttTaskImpl(); ganttObject.setId(task.getId()); ganttObject.setPredecessorOffset(task.getGanttPredecessorOffset()); ganttObject.setRelationType(task.getGanttRelationType()); ganttObject.setDuration(task.getDuration()); ganttObject.setStartDate(task.getStartDate()); ganttObject.setEndDate(task.getEndDate()); ganttObject.setProgress(task.getProgress()); ganttObject.setType(task.getGanttObjectType()); ganttObject.setDescription(task.getDescription()); ganttObject.setTitle(task.getTitle()); return ganttObject; }
@Test public void getNextId() { GanttTaskImpl root = new GanttTaskImpl(); root.addChild(new GanttTaskImpl(5)); assertEquals(-1, root.getNextId()); root.addChild(new GanttTaskImpl(-1)); assertEquals(-2, root.getNextId()); root.addChild(new GanttTaskImpl(-5)); assertEquals(-6, root.getNextId()); root.addChild(new GanttTaskImpl(-6)); assertEquals(-7, root.getNextId()); } }
/** * Sets the calculated start and end dates (including the children) to null (recalculation is forced when calculated time will be needed). <br/> * Please note: The calculation is only done at the first usage. */ @Override public GanttTaskImpl recalculate() { this.calculatedStartDate = this.calculatedEndDate = null; this.startDateCalculated = this.endDateCalculated = false; if (this.children != null) { for (final GanttTask child : this.children) { ((GanttTaskImpl) child).recalculate(); } } return this; }
private GanttTaskImpl createActivity(final int durationDays) { final GanttTaskImpl activity = new GanttTaskImpl(); if (durationDays >= 0) { activity.setDuration(new BigDecimal(durationDays)); } activity.setId(counter++); return activity; }
private GanttTaskImpl createGanttObject(final GanttTaskImpl parent, final String workpackageCode, final String title, final String durationDays, final GanttTask dependsOnGanttObject, final GanttRelationType type, final int dependDayOffset) { final GanttTaskImpl node = new GanttTaskImpl(); node.setTitle(title); node.setWorkpackageCode(workpackageCode); node.setDuration(new BigDecimal(durationDays)); node.setVisible(true); if (dependsOnGanttObject != null) { node.setPredecessor(dependsOnGanttObject); } if (type != null) { node.setRelationType(type); } if (dependDayOffset != 0) { node.setPredecessorOffset(dependDayOffset); } if (parent != null) { parent.addChild(node); } node.setPredecessor(dependsOnGanttObject); return node; }
final GanttTaskImpl activity1 = createActivity(10).setTitle("activity1"); final DayHolder day = new DayHolder(); day.setDate(2010, Calendar.FEBRUARY, 5); activity1.setStartDate(day.getDate()); assertDates("2010-02-05", "2010-02-19", activity1); activity1.setStartDate(null); day.addWorkingDays(10); activity1.setEndDate(day.getDate()); assertDates("2010-02-05", "2010-02-19", activity1); final GanttTaskImpl activity2 = createActivity(5).setTitle("activity2"); activity2.setPredecessor(activity1); assertDate(2010, Calendar.FEBRUARY, 19, GanttUtils.getCalculatedStartDate(activity2)); activity2.setPredecessorOffset(2); assertDate(2010, Calendar.FEBRUARY, 19, GanttUtils.getCalculatedStartDate(activity2)); activity2.recalculate(); assertDate(2010, Calendar.FEBRUARY, 23, GanttUtils.getCalculatedStartDate(activity2)); final GanttTaskImpl a1 = createActivity(1).setTitle("a1"); day.setDate(2010, Calendar.FEBRUARY, 1); a1.setStartDate(day.getDate()); final GanttTaskImpl a2 = createActivity(10).setTitle("a2"); a2.setPredecessor(a1); final GanttTaskImpl a2_1 = createActivity(10).setTitle("a2_1"); a2_1.setPredecessor(a2).setRelationType(GanttRelationType.START_START); a2.addChild(a2_1); final GanttTaskImpl a2_2 = createActivity(2).setTitle("a2_2"); a2_2.setPredecessor(a2).setRelationType(GanttRelationType.START_START); a2.addChild(a2_2);
assertEquals("No output because there is no further information in the GanttObject tree.", "", ganttChartDO.getGanttObjectsAsXml()); findById(rootObject, getTask(prefix + "2").getId()).setPredecessorOffset(5).setDuration(new BigDecimal("12")); findById(rootObject, getTask(prefix + "1.1").getId()).setDuration(new BigDecimal("2")); ganttChartDao.writeGanttObjects(ganttChartDO, rootObject); String xml = transform(prefix, "<ganttObject id='{}'>" ganttChartDao.writeGanttObjects(ganttChartDO, ganttObject); assertEquals(xml, ganttChartDO.getGanttObjectsAsXml()); assertEquals("duration", BigDecimal.TEN, findById(ganttObject, getTask(prefix + "1").getId()).getDuration()); assertEquals("startDate", dh.getDate(), findById(ganttObject, getTask(prefix + "1").getId()).getStartDate()); + "</children>" + "</ganttObject>"), ganttChartDO.getGanttObjectsAsXml()); findById(ganttObject, getTask(prefix + "1").getId()).setStartDate(null); ganttChartDao.writeGanttObjects(ganttChartDO, ganttObject); ganttObject = ganttChartDao.readGanttObjects(ganttChartDO).getRootObject(); assertNull("Start date should be stored as null (start date of task is set).", findById(ganttObject, getTask(prefix + "1").getId()) .getStartDate()); findById(ganttObject, getTask(prefix + "1").getId()).addChild(new GanttTaskImpl(-1).setTitle("Child of 1")); findById(ganttObject, getTask(prefix + "1.1").getId()).addChild( new GanttTaskImpl(-2).setTitle("Child of 1.1").addChild(new GanttTaskImpl(-3).setTitle("Grand child of 1.1"))); ganttChartDao.writeGanttObjects(ganttChartDO, ganttObject); xml = transform(prefix, "<ganttObject id='{}'>"
final GanttTaskImpl a1 = createActivity(1).setTitle("a1"); day.setDate(2010, Calendar.SEPTEMBER, 1); a1.setStartDate(day.getDate()); final GanttTaskImpl a2 = createActivity(-1).setTitle("a2"); final GanttTaskImpl a2_1 = createActivity(2).setTitle("a2_1"); a2_1.setPredecessor(a1); a2.addChild(a2_1); final GanttTaskImpl a2_2 = createActivity(2).setTitle("a2_2"); a2_2.setPredecessor(a2_1); a2.addChild(a2_2); assertDates("2010-09-01", "2010-09-02", a1); assertDates("2010-09-02", "2010-09-06", a2_1); // 2010-09-04 to 2010-09-05 is a weekend. assertDates("2010-09-06", "2010-09-08", a2_2); assertDates("2010-09-02", "2010-09-08", a2); a2.setDuration(TWO); assertDates("Start date calculated from children and duration is fixed", "2010-09-02", "2010-09-06", a2); a2.setStartDate(day.getDate()); assertDates("Start date and duration are fixed", "2010-09-01", "2010-09-03", a2); a2.setStartDate(null).setDuration(null).setPredecessor(a1).setPredecessorOffset(1); assertDates("Start date is calculated from predecessor.", "2010-09-03", "2010-09-08", a2); a2.setDuration(TWO); assertDates("Start date is calculated from predecessor and duration is fixed.", "2010-09-03", "2010-09-07", a2); a2.setRelationType(GanttRelationType.FINISH_START).setDuration(null); // Default -> same results: assertDates("Start date is calculated from predecessor.", "2010-09-03", "2010-09-08", a2); a2.setDuration(TWO); assertDates("Start date is calculated from predecessor and duration is fixed.", "2010-09-03", "2010-09-07", a2); a2.setRelationType(GanttRelationType.START_START).setDuration(null); assertDates("Start date is calculated from predecessor.", "2010-09-02", "2010-09-08", a2);
final GanttTaskImpl a1 = new GanttTaskImpl(1).setTitle("B"); assertEquals(0, GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a1, a1)); GanttTaskImpl a2 = new GanttTaskImpl(1).setTitle("A"); assertEquals(0, GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a1, a1)); // Same id a2 = new GanttTaskImpl(2).setTitle("A"); assertTrue("Start date not given, use alphabetical order instead.", GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a1, a2) > 0); a1.setStartDate(day.getDate()); assertTrue("a1.startDate before a2.startDate = null (now).", GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a1, a2) < 0); GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a2, a1) > 0); day.addWorkingDays(2); a2.setStartDate(day.getDate()); assertTrue("a1.startDate before a2.startDate.", GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a1, a2) < 0); assertTrue("a1.startDate before a2.startDate.", GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a2, a1) > 0); a1.setStartDate(day.getDate()); assertTrue("Same start date -> alphabetical order", GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a1, a2) > 0); assertTrue("Same start date -> alphabetical order", GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a2, a1) < 0); day.addWorkingDays(2); a2.setEndDate(day.getDate()); final Date a1StartDate = a1.getStartDate(); a1.setStartDate(null); assertTrue("a1.endDate = null after a2.endDate", GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a1, a2) > 0); assertTrue("a1.endDate = null before a2.endDate", GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a2, a1) < 0); a1.setEndDate(day.getDate()); a1.setStartDate(a1StartDate); assertTrue("Same start and end date -> alphabetical order", GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a1, a2) > 0);
final GanttTask rootObject = data.getRootObject(); final GanttChartDO ganttChartDO = new GanttChartDO().setTask(rootTask); findById(rootObject, id1).setDuration(new BigDecimal("10.000")).setProgress(10); // Modified. findById(rootObject, id3).setDuration(new BigDecimal("2")).setProgress(2); // Modified. findById(rootObject, id4).setDuration(new BigDecimal("10.000")).setProgress(10); // Unmodified findById(rootObject, id5).setDuration(null).setProgress(null); // Modified ganttChartDao.writeGanttObjects(ganttChartDO, rootObject); final String xml = transform(prefix, "<ganttObject id='{}'>"
/** * Get the next free id for new Gantt tasks to insert (starting with -1). Positive values are reserved for Gantt tasks related to tasks * (of ProjectForge's TaskTree) (the id is equals to the task id). * @return */ public int getNextId() { final Integer id = getNextId(this, -1); return id != null ? id : -1; }
@Override protected Object newInstance(final Class<?> clazz, final Element el, final String attrName, final String attrValue) { if ("predecessor".equals(attrName) == true && XmlConstants.NULL_IDENTIFIER.equals(attrValue) == true) { // Field should set to null. return Status.IGNORE; } if (GanttTask.class.isAssignableFrom(clazz) == true) { final GanttTask ganttObject = getGanttObject(taskTree, ganttChartData, el); if (ganttObject == null) { return new GanttTaskImpl(); // Gantt task not related to a ProjectForge task. } return ganttObject; } else if (Collection.class.isAssignableFrom(clazz) == true) { final GanttTask ganttObject = getGanttObject(taskTree, ganttChartData, el.getParent()); if (ganttObject != null && ganttObject.getChildren() != null) { return ganttObject.getChildren(); } } return null; }
final DayHolder day = new DayHolder(); day.setDate(2010, Calendar.JUNE, 1); task1.setStartDate(day.getDate()); createGanttObject(phase1, "002", "Task 2 (finish-start)", "10", task1, GanttRelationType.FINISH_START, 10); final GanttTaskImpl task3 = createGanttObject(phase1, "003", "Task 3 (finish-start II)", "5", task1, null, 0); final GanttTaskImpl task5 = createGanttObject(phase1, "005", "Task 5", "5"); day.add(Calendar.MONTH, 1); task5.setStartDate(day.getDate()); createGanttObject(phase1, "006", "Task 6 (finish-finish)", "3", task5, GanttRelationType.FINISH_FINISH, 0); createGanttObject(phase1, "007", "Task 7 (finish_finish)", "3", task5, GanttRelationType.FINISH_FINISH, -8); final GanttTaskImpl task12 = createGanttObject(phase1, "012", "Task 12", "5"); day.add(Calendar.WEEK_OF_YEAR, 3); task12.setStartDate(day.getDate()); createGanttObject(phase1, "013", "Task 13 (start-finish)", "3", task12, GanttRelationType.START_FINISH, -5); createGanttObject(phase1, "014", "Task 14 (start-finish)", "3", task12, GanttRelationType.START_FINISH, 5); final GanttTaskImpl task16 = createGanttObject(phase1, "016", "Task 16", "6"); day.add(Calendar.WEEK_OF_YEAR, 1); task16.setStartDate(day.getDate()); return phase1;
private Integer getNextId(final GanttTask node, final int id) { Integer result = null; if (node == null) { return null; } if (node.getId() != null && ((Integer) node.getId()) <= id) { result = ((Integer) node.getId()) - 1; } final List<GanttTask> children = node.getChildren(); if (children == null) { return result; } for (final GanttTask child : children) { final Integer i = getNextId(child, id); if (i == null) { continue; } if (result != null && i <= result || result == null && i <= id) { result = i; } } return result; } }
@Test public void hasDuration() { final GanttTask task = new GanttTaskImpl(); assertFalse("duration should be 0.", task.hasDuration()); task.setDuration(BigDecimal.TEN); assertTrue("duration should be 10.", task.hasDuration()); final DayHolder day = new DayHolder(); day.setDate(2010, Calendar.AUGUST, 13); task.setStartDate(day.getDate()); assertTrue("duration should be 10.", task.hasDuration()); task.setDuration(null); assertFalse("duration should be null.", task.hasDuration()); day.add(Calendar.DAY_OF_MONTH, 1); task.setEndDate(day.getDate()); assertTrue("duration expected.", task.hasDuration()); } }