Java Code Examples for net.sf.mpxj.ProjectFile#getTaskByID()
The following examples show how to use
net.sf.mpxj.ProjectFile#getTaskByID() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskBaselinesTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test baseline fixed costs. * * @param project project * @param startTaskID initial task ID * @param maxBaselines maximum baselines to test * @return task ID for next tests */ private int testFixedCosts(ProjectFile project, int startTaskID, int maxBaselines) { int taskID = startTaskID; for (int index = 0; index < maxBaselines; index++) { Task task = project.getTaskByID(Integer.valueOf(taskID)); taskID++; Number value; if (index == 0) { value = task.getBaselineFixedCost(); } else { value = task.getBaselineFixedCost(index); } assertEquals(FIXED_COSTS[index], value.toString()); } return taskID; }
Example 2
Source File: TaskBaselinesTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test baseline starts. * * @param project project * @param startTaskID initial task ID * @param maxBaselines maximum baselines to test * @return task ID for next tests */ private int testStarts(ProjectFile project, int startTaskID, int maxBaselines) { int taskID = startTaskID; for (int index = 0; index < maxBaselines; index++) { Task task = project.getTaskByID(Integer.valueOf(taskID)); taskID++; Date value; if (index == 0) { value = task.getBaselineStart(); } else { value = task.getBaselineStart(index); } assertEquals(STARTS[index], m_dateFormat.format(value)); } return taskID; }
Example 3
Source File: TaskFinishesTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test an individual project. * * @param file project file */ private void testTaskFinishDates(File file) throws Exception { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); if (reader instanceof MPDDatabaseReader) { assumeJvm(); } boolean isMpxFile = reader instanceof MPXReader; int maxIndex = isMpxFile ? 5 : 10; ProjectFile project = reader.read(file); for (int index = 1; index <= maxIndex; index++) { Task task = project.getTaskByID(Integer.valueOf(index)); assertEquals("Finish" + index, task.getName()); testTaskFinishDates(file, task, index, maxIndex, isMpxFile); } }
Example 4
Source File: TaskCostsTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test an individual project. * * @param file project file */ private void testTaskCosts(File file) throws MPXJException { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); if (reader instanceof MPDDatabaseReader) { assumeJvm(); } int maxIndex = reader instanceof MPXReader ? 3 : 10; ProjectFile project = reader.read(file); for (int index = 1; index <= maxIndex; index++) { Task task = project.getTaskByID(Integer.valueOf(index)); assertEquals("Cost" + index, task.getName()); testTaskCosts(file, task, index, maxIndex); } }
Example 5
Source File: TaskLinksTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test a relationship between two tasks. * * @param project parent project * @param taskID1 first task * @param taskID2 second task * @param name1 expected task name 1 * @param name2 expected task name 1 * @param type expected relation type * @param lagDuration expected lag duration * @param lagUnits expected lag units */ private void testTaskLinks(ProjectFile project, int taskID1, int taskID2, String name1, String name2, RelationType type, double lagDuration, TimeUnit lagUnits) { Task task1 = project.getTaskByID(Integer.valueOf(taskID1)); Task task2 = project.getTaskByID(Integer.valueOf(taskID2)); assertEquals(name1, task1.getName()); assertEquals(name2, task2.getName()); List<Relation> relations = task2.getPredecessors(); assertEquals(1, relations.size()); Relation relation = relations.get(0); assertEquals(task2, relation.getSourceTask()); assertEquals(task1, relation.getTargetTask()); assertEquals(type, relation.getType()); assertEquals(lagUnits, relation.getLag().getUnits()); assertTrue(NumberHelper.equals(lagDuration, relation.getLag().getDuration(), 0.0001)); }
Example 6
Source File: TaskStartsTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test an individual project. * * @param file project file */ private void testTaskStartDates(File file) throws Exception { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); if (reader instanceof MPDDatabaseReader) { assumeJvm(); } boolean isMpxFile = reader instanceof MPXReader; int maxIndex = isMpxFile ? 5 : 10; ProjectFile project = reader.read(file); for (int index = 1; index <= maxIndex; index++) { Task task = project.getTaskByID(Integer.valueOf(index)); assertEquals("Start" + index, task.getName()); testTaskStartDates(file, task, index, maxIndex, isMpxFile); } }
Example 7
Source File: TaskBaselinesTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test baseline costs. * * @param project project * @param startTaskID initial task ID * @param maxBaselines maximum baselines to test * @return task ID for next tests */ private int testCosts(ProjectFile project, int startTaskID, int maxBaselines) { int taskID = startTaskID; for (int index = 0; index < maxBaselines; index++) { Task task = project.getTaskByID(Integer.valueOf(taskID)); taskID++; Number value; if (index == 0) { value = task.getBaselineCost(); } else { value = task.getBaselineCost(index); } assertEquals(COSTS[index], value.toString()); } return taskID; }
Example 8
Source File: TaskBaselinesTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test baseline estimated starts. * * @param project project * @param startTaskID initial task ID * @param maxBaselines maximum baselines to test * @return task ID for next tests */ private int testEstimatedStarts(ProjectFile project, int startTaskID, int maxBaselines) { int taskID = startTaskID; for (int index = 0; index < maxBaselines; index++) { Task task = project.getTaskByID(Integer.valueOf(taskID)); taskID++; Date value; if (index == 0) { value = task.getBaselineEstimatedStart(); } else { value = task.getBaselineEstimatedStart(index); } assertEquals(ESTIMATED_STARTS[index], m_dateFormat.format(value)); } return taskID; }
Example 9
Source File: TaskBaselinesTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test baseline works. * * @param project project * @param startTaskID initial task ID * @param maxBaselines maximum baselines to test * @return task ID for next tests */ private int testWorks(ProjectFile project, int startTaskID, int maxBaselines) { int taskID = startTaskID; for (int index = 0; index < maxBaselines; index++) { Task task = project.getTaskByID(Integer.valueOf(taskID)); taskID++; Duration value; if (index == 0) { value = task.getBaselineWork(); } else { value = task.getBaselineWork(index); } assertEquals(WORKS[index], value.toString()); } return taskID; }
Example 10
Source File: TaskFlagsTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test an individual project. * * @param file project file */ private void testTaskFlags(File file) throws MPXJException { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); if (reader instanceof MPDDatabaseReader) { assumeJvm(); } int maxIndex = reader instanceof MPXReader ? 10 : 20; ProjectFile project = reader.read(file); for (int index = 1; index <= maxIndex; index++) { Task task = project.getTaskByID(Integer.valueOf(index)); assertEquals("Flag" + index, task.getName()); testTaskFlags(file, task, index, maxIndex); } }
Example 11
Source File: AssignmentFlagsTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test an individual project. * * @param file project file */ private void testAssignmentFlags(File file) throws MPXJException { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); if (reader instanceof MPDDatabaseReader) { assumeJvm(); } int maxIndex = reader instanceof MPXReader ? 10 : 20; ProjectFile project = reader.read(file); for (int index = 1; index <= maxIndex; index++) { Task task = project.getTaskByID(Integer.valueOf(index)); assertEquals("Task " + index, task.getName()); testAssignmentFlags(file, task, index, maxIndex); } }
Example 12
Source File: TaskBaselinesTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test baseline estimated finishes. * * @param project project * @param startTaskID initial task ID * @param maxBaselines maximum baselines to test * @return task ID for next tests */ private int testEstimatedFinishes(ProjectFile project, int startTaskID, int maxBaselines) { int taskID = startTaskID; for (int index = 0; index < maxBaselines; index++) { Task task = project.getTaskByID(Integer.valueOf(taskID)); taskID++; Date value; if (index == 0) { value = task.getBaselineEstimatedFinish(); } else { value = task.getBaselineEstimatedFinish(index); } assertEquals(ESTIMATED_FINISHES[index], m_dateFormat.format(value)); } return taskID; }
Example 13
Source File: AssignmentTextTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test an individual project. * * @param file project file */ private void testAssignmentText(File file) throws MPXJException { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); if (reader instanceof MPDDatabaseReader) { assumeJvm(); } int maxIndex = 30; ProjectFile project = reader.read(file); for (int index = 1; index <= maxIndex; index++) { Task task = project.getTaskByID(Integer.valueOf(index)); assertEquals("Task " + index, task.getName()); testAssignmentText(file, task, index, maxIndex); } }
Example 14
Source File: MppFilterTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Validate filter logical operator evaluation. * * @param mpp project file */ private void testLogicalOperatorEvaluation(ProjectFile mpp) { Task task6 = mpp.getTaskByID(Integer.valueOf(6)); Task task7 = mpp.getTaskByID(Integer.valueOf(7)); FilterContainer filters = mpp.getFilters(); // Number1==13 && Number2==7 Filter filter = filters.getFilterByName("Filter 19"); assertFalse(filter.evaluate(task6, null)); assertTrue(filter.evaluate(task7, null)); // Number1==12 || Number1==13 filter = filters.getFilterByName("Filter 20"); assertTrue(filter.evaluate(task6, null)); assertTrue(filter.evaluate(task7, null)); // Duration==10d && Number1==13 && Number2==7 filter = filters.getFilterByName("Filter 21"); assertFalse(filter.evaluate(task6, null)); assertTrue(filter.evaluate(task7, null)); // Duration==10d || Number1==12 || Number2==7 filter = filters.getFilterByName("Filter 22"); assertTrue(filter.evaluate(task6, null)); assertTrue(filter.evaluate(task7, null)); // Duration==10d && Number1==12 || Number1==13 filter = filters.getFilterByName("Filter 23"); assertTrue(filter.evaluate(task6, null)); assertTrue(filter.evaluate(task7, null)); }
Example 15
Source File: DefaultDurationFormatTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Ensure that where the duration format is listed as "21" in the MSPDI file, we use the default duration format, * as defined in the project properties. */ @Test public void testDefaultDateFormat() throws Exception { ProjectFile file = new MSPDIReader().read(MpxjTestData.filePath("project/default-duration-format/DefaultDurationFormat.xml")); Task task = file.getTaskByID(Integer.valueOf(1)); assertDurationEquals(2, TimeUnit.WEEKS, task.getDuration()); }
Example 16
Source File: TaskDurationsTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test duration values. * * @param file project file * @param reader reader used to parse the file * @param project project file */ private void testDurationValues(File file, ProjectReader reader, ProjectFile project) { int maxIndex = reader instanceof MPXReader ? 3 : 10; for (int index = 1; index <= maxIndex; index++) { Task task = project.getTaskByID(Integer.valueOf(index)); assertEquals("Duration" + index, task.getName()); testTaskDurations(file, task, index, maxIndex); } }
Example 17
Source File: TaskDeletionTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test an individual project. * * @param file project file * @param expectedNames expected task names */ private void testTaskDeletion(File file, String[] expectedNames) throws MPXJException { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); ProjectFile project = reader.read(file); assertEquals(expectedNames.length + 1, project.getTasks().size()); for (int index = 0; index < expectedNames.length; index++) { Task task = project.getTaskByID(Integer.valueOf(index + 1)); assertNotNull(file.getName() + " Task " + (index + 1), task); assertEquals(file.getName() + " Task " + task.getID(), expectedNames[index], task.getName()); } }
Example 18
Source File: TaskTextValuesTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test an individual project. * * @param file project file */ private void testTaskTextValues(File file) throws MPXJException { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); ProjectFile project = reader.read(file); assertEquals(file.getName() + " number of tasks", EXPECTED_VALUES.length + 1, project.getTasks().size()); for (int loop = 0; loop < EXPECTED_VALUES.length; loop++) { Task task = project.getTaskByID(Integer.valueOf(loop + 1)); assertEquals(file.getName() + " task name", EXPECTED_VALUES[loop][0], task.getName()); assertEquals(file.getName() + " start text", EXPECTED_VALUES[loop][1], task.getStartText()); assertEquals(file.getName() + " finish text", EXPECTED_VALUES[loop][2], task.getFinishText()); assertEquals(file.getName() + " duration text", EXPECTED_VALUES[loop][3], task.getDurationText()); } }
Example 19
Source File: BasicTest.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * Ensure that we are reading MPP9 flags correctly. This test reads a * file where the tasks alternately have values of either all true, or * all false. Each pair of tasks increases by one in outline level. * * @throws Exception */ @Test public void testMPP9Flags1() throws Exception { File in = new File(MpxjTestData.filePath("legacy/mpp9flags1.mpp")); ProjectFile mpp = new MPPReader().read(in); Task parentTask = mpp.getTaskByID(Integer.valueOf(0)); assertNotNull("Parent task missing", parentTask); List<Task> tasks = parentTask.getChildTasks(); assertTrue("Not enough tasks", (tasks.size() > 0)); assertTrue("Not an even number of tasks", (tasks.size() % 2 == 0)); Iterator<Task> iter = tasks.iterator(); Task task; while (iter.hasNext()) { task = iter.next(); assertFalse(task.getName(), task.getFlag(1)); assertFalse(task.getName(), task.getFlag(2)); assertFalse(task.getName(), task.getFlag(3)); assertFalse(task.getName(), task.getFlag(4)); assertFalse(task.getName(), task.getFlag(5)); assertFalse(task.getName(), task.getFlag(6)); assertFalse(task.getName(), task.getFlag(7)); assertFalse(task.getName(), task.getFlag(8)); assertFalse(task.getName(), task.getFlag(9)); assertFalse(task.getName(), task.getFlag(10)); assertFalse(task.getName(), task.getFlag(11)); assertFalse(task.getName(), task.getFlag(12)); assertFalse(task.getName(), task.getFlag(13)); assertFalse(task.getName(), task.getFlag(14)); assertFalse(task.getName(), task.getFlag(15)); assertFalse(task.getName(), task.getFlag(16)); assertFalse(task.getName(), task.getFlag(17)); assertFalse(task.getName(), task.getFlag(18)); assertFalse(task.getName(), task.getFlag(19)); assertFalse(task.getName(), task.getFlag(20)); task = iter.next(); assertTrue(task.getName(), task.getFlag(1)); assertTrue(task.getName(), task.getFlag(2)); assertTrue(task.getName(), task.getFlag(3)); assertTrue(task.getName(), task.getFlag(4)); assertTrue(task.getName(), task.getFlag(5)); assertTrue(task.getName(), task.getFlag(6)); assertTrue(task.getName(), task.getFlag(7)); assertTrue(task.getName(), task.getFlag(8)); assertTrue(task.getName(), task.getFlag(9)); assertTrue(task.getName(), task.getFlag(10)); assertTrue(task.getName(), task.getFlag(11)); assertTrue(task.getName(), task.getFlag(12)); assertTrue(task.getName(), task.getFlag(13)); assertTrue(task.getName(), task.getFlag(14)); assertTrue(task.getName(), task.getFlag(15)); assertTrue(task.getName(), task.getFlag(16)); assertTrue(task.getName(), task.getFlag(17)); assertTrue(task.getName(), task.getFlag(18)); assertTrue(task.getName(), task.getFlag(19)); assertTrue(task.getName(), task.getFlag(20)); } }
Example 20
Source File: MppTaskTest.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * Tests Relations. * * @param mpp mpp file */ private void testRelations(ProjectFile mpp) { List<Task> listAllTasks = mpp.getTasks(); assertNotNull(listAllTasks); Task task1 = mpp.getTaskByID(Integer.valueOf(1)); Task task2 = mpp.getTaskByID(Integer.valueOf(2)); Task task3 = mpp.getTaskByID(Integer.valueOf(3)); Task task4 = mpp.getTaskByID(Integer.valueOf(4)); Task task5 = mpp.getTaskByID(Integer.valueOf(5)); List<Relation> listPreds = task2.getPredecessors(); Relation relation = listPreds.get(0); assertEquals(1, relation.getTargetTask().getUniqueID().intValue()); assertEquals(RelationType.FINISH_START, relation.getType()); assertEquals(task1, relation.getTargetTask()); listPreds = task3.getPredecessors(); relation = listPreds.get(0); assertEquals(2, relation.getTargetTask().getUniqueID().intValue()); assertEquals(RelationType.START_START, relation.getType()); Duration duration = relation.getLag(); if (duration.getUnits() == TimeUnit.DAYS) { assertEquals(1, (int) duration.getDuration()); } else { if (duration.getUnits() == TimeUnit.HOURS) { assertEquals(8, (int) duration.getDuration()); } } listPreds = task4.getPredecessors(); relation = listPreds.get(0); assertEquals(3, relation.getTargetTask().getUniqueID().intValue()); assertEquals(RelationType.FINISH_FINISH, relation.getType()); boolean removed = task4.removePredecessor(relation.getTargetTask(), relation.getType(), relation.getLag()); assertTrue(removed); listPreds = task4.getPredecessors(); assertTrue(listPreds.isEmpty()); task4.addPredecessor(relation.getTargetTask(), relation.getType(), relation.getLag()); task4.addPredecessor(task2, RelationType.FINISH_START, Duration.getInstance(0, TimeUnit.DAYS)); listPreds = task4.getPredecessors(); removed = task4.removePredecessor(task2, RelationType.FINISH_FINISH, Duration.getInstance(0, TimeUnit.DAYS)); assertFalse(removed); task4.addPredecessor(task2, RelationType.FINISH_START, Duration.getInstance(0, TimeUnit.DAYS)); listPreds = task4.getPredecessors(); removed = task4.removePredecessor(task2, RelationType.FINISH_START, Duration.getInstance(0, TimeUnit.DAYS)); assertTrue(removed); listPreds = task4.getPredecessors(); relation = listPreds.get(0); assertEquals(3, relation.getTargetTask().getUniqueID().intValue()); assertEquals(RelationType.FINISH_FINISH, relation.getType()); listPreds = task5.getPredecessors(); relation = listPreds.get(0); assertEquals(4, relation.getTargetTask().getUniqueID().intValue()); assertEquals(RelationType.START_FINISH, relation.getType()); }