net.sf.mpxj.Task Java Examples
The following examples show how to use
net.sf.mpxj.Task.
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 | 7 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 #2
Source File: ProjectTreeController.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Add tasks to the tree. * * @param parentNode parent tree node * @param parent parent task container */ private void addTasks(MpxjTreeNode parentNode, ChildTaskContainer parent) { for (Task task : parent.getChildTasks()) { final Task t = task; MpxjTreeNode childNode = new MpxjTreeNode(task, TASK_EXCLUDED_METHODS) { @Override public String toString() { return t.getName(); } }; parentNode.add(childNode); addTasks(childNode, task); } }
Example #3
Source File: BasicTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test to ensure that the basic task hierarchy is * represented correctly. * * @throws Exception */ @Test public void testStructure() throws Exception { ProjectFile file = new ProjectFile(); Task task1 = file.addTask(); assertNull(task1.getParentTask()); Task task2 = task1.addTask(); assertEquals(task2.getParentTask(), task1); task1.addTask(); List<Task> children = task1.getChildTasks(); assertEquals(children.size(), 2); List<Task> toplevel = file.getChildTasks(); assertEquals(toplevel.size(), 1); }
Example #4
Source File: MSPDIReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * When projectmanager.com exports schedules as MSPDI (via Aspose tasks) * they do not have finish dates, just a start date and a duration. * This method populates finish dates. * * @param task task to validate */ private void validateFinishDate(Task task) { if (task.getFinish() == null) { Date startDate = task.getStart(); if (startDate != null) { if (task.getMilestone()) { task.setFinish(startDate); } else { Duration duration = task.getDuration(); if (duration != null) { ProjectCalendar calendar = task.getEffectiveCalendar(); task.setFinish(calendar.getDate(startDate, duration, false)); } } } } }
Example #5
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 #6
Source File: SynchroReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Recursively update parent task dates. * * @param parentTask parent task */ private void updateDates(Task parentTask) { if (parentTask.hasChildTasks()) { Date plannedStartDate = null; Date plannedFinishDate = null; for (Task task : parentTask.getChildTasks()) { updateDates(task); plannedStartDate = DateHelper.min(plannedStartDate, task.getStart()); plannedFinishDate = DateHelper.max(plannedFinishDate, task.getFinish()); } parentTask.setStart(plannedStartDate); parentTask.setFinish(plannedFinishDate); } }
Example #7
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 #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: MSPDIWriter.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * This method writes extended attribute data for a task. * * @param xml MSPDI task * @param mpx MPXJ task */ private void writeTaskExtendedAttributes(Project.Tasks.Task xml, Task mpx) { Project.Tasks.Task.ExtendedAttribute attrib; List<Project.Tasks.Task.ExtendedAttribute> extendedAttributes = xml.getExtendedAttribute(); for (TaskField mpxFieldID : getAllTaskExtendedAttributes()) { Object value = mpx.getCachedValue(mpxFieldID); if (FieldTypeHelper.valueIsNotDefault(mpxFieldID, value)) { m_extendedAttributesInUse.add(mpxFieldID); Integer xmlFieldID = Integer.valueOf(MPPTaskField.getID(mpxFieldID) | MPPTaskField.TASK_FIELD_BASE); attrib = m_factory.createProjectTasksTaskExtendedAttribute(); extendedAttributes.add(attrib); attrib.setFieldID(xmlFieldID.toString()); attrib.setValue(DatatypeConverter.printExtendedAttribute(this, value, mpxFieldID.getDataType())); attrib.setDurationFormat(printExtendedAttributeDurationFormat(value)); } } }
Example #10
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 #11
Source File: MPD9AbstractReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Read task baseline values. * * @param row result set row */ protected void processTaskBaseline(Row row) { Integer id = row.getInteger("TASK_UID"); Task task = m_project.getTaskByUniqueID(id); if (task != null) { int index = row.getInt("TB_BASE_NUM"); task.setBaselineDuration(index, MPDUtility.getAdjustedDuration(m_project, row.getInt("TB_BASE_DUR"), MPDUtility.getDurationTimeUnits(row.getInt("TB_BASE_DUR_FMT")))); task.setBaselineStart(index, row.getDate("TB_BASE_START")); task.setBaselineFinish(index, row.getDate("TB_BASE_FINISH")); task.setBaselineWork(index, row.getDuration("TB_BASE_WORK")); task.setBaselineCost(index, row.getCurrency("TB_BASE_COST")); } }
Example #12
Source File: BasicTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * This test reads flags from an MPP9 file where each set of 20 tasks has * a single flag from 1-20 set. The next set of 20 tasks increases by * one outline level. * * @throws Exception */ @Test public void testMPP9Flags2() throws Exception { File in = new File(MpxjTestData.filePath("legacy/mpp9flags2.mpp")); ProjectFile mpp = new MPPReader().read(in); int index = 0; boolean[] flags; for (Task task : mpp.getTasks()) { if (task.getUniqueID().intValue() != 0 && task.getName().startsWith("Parent") == false) { flags = getFlagArray(task); assertTrue("Incorrect flag set in task " + task.getName(), testSingleFlagTrue(flags, index)); ++index; if (index == 20) { index = 0; } } } }
Example #13
Source File: AstaReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Adds a leaf node, which could be a task or a milestone. * * @param parentName parent bar name * @param row row to add * @param task task to populate with data from the row */ private void populateLeaf(String parentName, Row row, Task task) { if (row.getInteger("TASKID") != null) { populateTask(row, task); } else { populateMilestone(row, task); } String name = task.getName(); if (name == null || name.isEmpty()) { task.setName(parentName); } }
Example #14
Source File: TaskNumbersTest.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test an individual project. * * @param file project file */ private void testTaskNumbers(File file) throws MPXJException { ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName()); if (reader instanceof MPDDatabaseReader) { assumeJvm(); } int maxIndex = reader instanceof MPXReader ? 5 : 20; ProjectFile project = reader.read(file); for (int index = 1; index <= maxIndex; index++) { Task task = project.getTaskByID(Integer.valueOf(index)); assertEquals("Number" + index, task.getName()); testTaskNumbers(file, task, index, maxIndex); } }
Example #15
Source File: TurboProjectReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Read relationship data from a PEP file. */ private void readRelationships() { for (MapRow row : getTable("CONTAB")) { Task task1 = m_projectFile.getTaskByUniqueID(row.getInteger("TASK_ID_1")); Task task2 = m_projectFile.getTaskByUniqueID(row.getInteger("TASK_ID_2")); if (task1 != null && task2 != null) { RelationType type = row.getRelationType("TYPE"); Duration lag = row.getDuration("LAG"); Relation relation = task2.addPredecessor(task1, type, lag); m_eventManager.fireRelationReadEvent(relation); } } }
Example #16
Source File: PrimaveraPMFileWriter.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Writes task predecessor links to a PM XML file. * * @param task MPXJ Task instance */ private void writePredecessors(Task task) { List<Relation> relations = task.getPredecessors(); for (Relation mpxj : relations) { RelationshipType xml = m_factory.createRelationshipType(); m_project.getRelationship().add(xml); xml.setLag(getDuration(mpxj.getLag())); xml.setObjectId(Integer.valueOf(++m_relationshipObjectID)); xml.setPredecessorActivityObjectId(mpxj.getTargetTask().getUniqueID()); xml.setSuccessorActivityObjectId(mpxj.getSourceTask().getUniqueID()); xml.setPredecessorProjectObjectId(PROJECT_OBJECT_ID); xml.setSuccessorProjectObjectId(PROJECT_OBJECT_ID); xml.setType(RELATION_TYPE_MAP.get(mpxj.getType())); } }
Example #17
Source File: GanttDesignerReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Read an individual remark type from a Gantt Designer file. * * @param remark remark type */ private void processRemarks(GanttDesignerRemark remark) { for (GanttDesignerRemark.Task remarkTask : remark.getTask()) { Integer id = remarkTask.getRow(); Task task = m_projectFile.getTaskByID(id); String notes = task.getNotes(); if (notes.isEmpty()) { notes = remarkTask.getContent(); } else { notes = notes + '\n' + remarkTask.getContent(); } task.setNotes(notes); } }
Example #18
Source File: MerlinReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Extract a duration amount from the assignment, converting a percentage * into an actual duration. * * @param task parent task * @param work duration from assignment * @return Duration instance */ private Duration assignmentDuration(Task task, Duration work) { Duration result = work; if (result != null) { if (result.getUnits() == TimeUnit.PERCENT) { Duration taskWork = task.getWork(); if (taskWork != null) { result = Duration.getInstance(taskWork.getDuration() * result.getDuration(), taskWork.getUnits()); } } } return result; }
Example #19
Source File: PhoenixReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Locates a task within a child task container which matches the supplied UUID. * * @param parent child task container * @param uuid required UUID * @return Task instance or null if the task is not found */ private Task findChildTaskByUUID(ChildTaskContainer parent, UUID uuid) { Task result = null; for (Task task : parent.getChildTasks()) { if (uuid.equals(task.getGUID())) { result = task; break; } } return result; }
Example #20
Source File: ProjectCommanderReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Propagate start and end dates to summary tasks. * * @param parentTask parent task */ private void updateDates(Task parentTask) { if (parentTask.hasChildTasks()) { Date plannedStartDate = parentTask.getStart(); Date plannedFinishDate = parentTask.getFinish(); for (Task task : parentTask.getChildTasks()) { updateDates(task); plannedStartDate = DateHelper.min(plannedStartDate, task.getStart()); plannedFinishDate = DateHelper.max(plannedFinishDate, task.getFinish()); } parentTask.setStart(plannedStartDate); parentTask.setFinish(plannedFinishDate); } }
Example #21
Source File: TurboProjectReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Read data for an individual task from the tables in a PEP file. * * @param parent parent task * @param id task ID * @return task instance */ private Task readTask(ChildTaskContainer parent, Integer id) { Table a0 = getTable("A0TAB"); Table a1 = getTable("A1TAB"); Table a2 = getTable("A2TAB"); Table a3 = getTable("A3TAB"); Table a4 = getTable("A4TAB"); Task task = parent.addTask(); MapRow a1Row = a1.find(id); MapRow a2Row = a2.find(id); setFields(A0TAB_FIELDS, a0.find(id), task); setFields(A1TAB_FIELDS, a1Row, task); setFields(A2TAB_FIELDS, a2Row, task); setFields(A3TAB_FIELDS, a3.find(id), task); setFields(A5TAB_FIELDS, a4.find(id), task); task.setStart(task.getEarlyStart()); task.setFinish(task.getEarlyFinish()); if (task.getName() == null) { task.setName(task.getText(1)); } m_eventManager.fireTaskReadEvent(task); return task; }
Example #22
Source File: AstaReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Retrieve all child tasks below this task to the bottom of the hierarchy. * If the task has no child tasks then just add it to the array. * * @param tasks array to collect child tasks * @param task current task */ private void gatherChildTasks(List<Task> tasks, Task task) { if (task.hasChildTasks()) { task.getChildTasks().forEach(child -> gatherChildTasks(tasks, child)); } else { tasks.add(task); } }
Example #23
Source File: PrecedenceRecord.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void process(Context context) { Task currentTask = context.getTask(getString(0)); Task previousTask = context.getTask(getString(1)); if (currentTask != null && previousTask != null) { Relation relation = currentTask.addPredecessor(previousTask, getRelationType(2), getDuration(3)); context.getEventManager().fireRelationReadEvent(relation); } }
Example #24
Source File: PrimaveraPMFileReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Iterates through the tasks setting the correct * outline level and ID values. * * @param id current ID value * @param task current task * @param outlineLevel current outline level * @return next ID value */ private int updateStructure(int id, Task task, Integer outlineLevel) { task.setID(Integer.valueOf(id++)); task.setOutlineLevel(outlineLevel); outlineLevel = Integer.valueOf(outlineLevel.intValue() + 1); for (Task childTask : task.getChildTasks()) { id = updateStructure(id, childTask, outlineLevel); } return id; }
Example #25
Source File: GanttDesignerReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Read task data from a Gantt Designer file. * * @param gantt Gantt Designer file */ private void processTasks(Gantt gantt) { ProjectCalendar calendar = m_projectFile.getDefaultCalendar(); for (Gantt.Tasks.Task ganttTask : gantt.getTasks().getTask()) { String wbs = ganttTask.getID(); ChildTaskContainer parentTask = getParentTask(wbs); Task task = parentTask.addTask(); //ganttTask.getB() // bar type //ganttTask.getBC() // bar color task.setCost(ganttTask.getC()); task.setName(ganttTask.getContent()); task.setDuration(ganttTask.getD()); task.setDeadline(ganttTask.getDL()); //ganttTask.getH() // height //ganttTask.getIn(); // indent task.setWBS(wbs); task.setPercentageComplete(ganttTask.getPC()); task.setStart(ganttTask.getS()); //ganttTask.getU(); // Unknown //ganttTask.getVA(); // Valign task.setFinish(calendar.getDate(task.getStart(), task.getDuration(), false)); m_taskMap.put(wbs, task); } }
Example #26
Source File: SynchroReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Extract predecessor data. */ private void processPredecessors() { for (Map.Entry<Task, List<MapRow>> entry : m_predecessorMap.entrySet()) { Task task = entry.getKey(); List<MapRow> predecessors = entry.getValue(); for (MapRow predecessor : predecessors) { processPredecessor(task, predecessor); } } }
Example #27
Source File: PrimaveraPMFileWriter.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Writes a resource assignment to a PM XML file. * * @param mpxj MPXJ ResourceAssignment instance */ private void writeAssignment(ResourceAssignment mpxj) { ResourceAssignmentType xml = m_factory.createResourceAssignmentType(); m_project.getResourceAssignment().add(xml); Task task = mpxj.getTask(); Task parentTask = task.getParentTask(); Integer parentTaskUniqueID = parentTask == null ? null : parentTask.getUniqueID(); xml.setActivityObjectId(mpxj.getTaskUniqueID()); xml.setActualCost(getDouble(mpxj.getActualCost())); xml.setActualFinishDate(mpxj.getActualFinish()); xml.setActualOvertimeUnits(getDuration(mpxj.getActualOvertimeWork())); xml.setActualRegularUnits(getDuration(mpxj.getActualWork())); xml.setActualStartDate(mpxj.getActualStart()); xml.setActualUnits(getDuration(mpxj.getActualWork())); xml.setAtCompletionUnits(getDuration(mpxj.getRemainingWork())); xml.setPlannedCost(getDouble(mpxj.getActualCost())); xml.setFinishDate(mpxj.getFinish()); xml.setGUID(DatatypeConverter.printUUID(mpxj.getGUID())); xml.setObjectId(mpxj.getUniqueID()); xml.setPlannedDuration(getDuration(mpxj.getWork())); xml.setPlannedFinishDate(mpxj.getFinish()); xml.setPlannedStartDate(mpxj.getStart()); xml.setPlannedUnits(getDuration(mpxj.getWork())); xml.setPlannedUnitsPerTime(getPercentage(mpxj.getUnits())); xml.setProjectObjectId(PROJECT_OBJECT_ID); xml.setRateSource("Resource"); xml.setRemainingCost(getDouble(mpxj.getActualCost())); xml.setRemainingDuration(getDuration(mpxj.getRemainingWork())); xml.setRemainingFinishDate(mpxj.getFinish()); xml.setRemainingStartDate(mpxj.getStart()); xml.setRemainingUnits(getDuration(mpxj.getRemainingWork())); xml.setRemainingUnitsPerTime(getPercentage(mpxj.getUnits())); xml.setResourceObjectId(mpxj.getResourceUniqueID()); xml.setStartDate(mpxj.getStart()); xml.setWBSObjectId(parentTaskUniqueID); xml.getUDF().addAll(writeUDFType(FieldTypeClass.ASSIGNMENT, mpxj)); }
Example #28
Source File: PrimaveraReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * The Primavera WBS entries we read in as tasks have user-entered start and end dates * which aren't calculated or adjusted based on the child task dates. We try * to compensate for this by using these user-entered dates as baseline dates, and * deriving the planned start, actual start, planned finish and actual finish from * the child tasks. This method recursively descends through the tasks to do this. */ private void updateDates() { for (Task task : m_project.getChildTasks()) { updateDates(task); } }
Example #29
Source File: ProjectCommanderReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Read one or more child tasks. * * @param block task data * @param name task name * @param baseline task baseline data */ private void readChildTasks(Block block, String name, Block baseline) { Block cUsageTask = getChildBlock(block, "CUsageTask"); byte[] cUsageTaskBaselineData = getByteArray(cUsageTask, "CBaselineData"); Resource resource = readChildTaskResource(cUsageTask); List<Task> tasks = getChildBlocks(baseline, "CBar").map(bar -> readChildTask(name, bar, cUsageTaskBaselineData, resource)).collect(Collectors.toList()); if (tasks.size() > 1) { m_extraBarCounts.put(tasks.get(0), Integer.valueOf(tasks.size() - 1)); } }
Example #30
Source File: TaskFinishesTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test the finish date values for a task. * * @param file parent file * @param task task * @param testIndex index of number being tested * @param maxIndex highest index to test * @param useDateFormat true=use date-only format false=use date time format */ private void testTaskFinishDates(File file, Task task, int testIndex, int maxIndex, boolean useDateFormat) throws ParseException { DateFormat format = useDateFormat ? m_dateFormat : m_dateTimeFormat; for (int index = 1; index <= maxIndex; index++) { Date expectedValue = testIndex == index ? format.parse(DATES[index - 1]) : null; Date actualValue = task.getFinish(index); assertEquals(file.getName() + " Finish" + index, expectedValue, actualValue); } }