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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #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: 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 #9
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 #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: 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 #12
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 #13
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 #14
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 #15
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 #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: 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 #18
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 #19
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 #20
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 #21
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 #22
Source File: FastTrackReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Extract the outline level from a task's WBS attribute. * * @param task Task instance * @return outline level */ private Integer getOutlineLevel(Task task) { String value = task.getWBS(); Integer result = Integer.valueOf(1); if (value != null && value.length() > 0) { String[] path = WBS_SPLIT_REGEX.split(value); result = Integer.valueOf(path.length); } return result; }
Example #23
Source File: PrimaveraPMFileReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Process resource assignments. * * @param project xml container */ private void processAssignments(ProjectType project) { List<ResourceAssignmentType> assignments = project.getResourceAssignment(); for (ResourceAssignmentType row : assignments) { Task task = m_projectFile.getTaskByUniqueID(mapTaskID(row.getActivityObjectId())); Resource resource = m_projectFile.getResourceByUniqueID(row.getResourceObjectId()); if (task != null && resource != null) { ResourceAssignment assignment = task.addResourceAssignment(resource); assignment.setUniqueID(row.getObjectId()); assignment.setRemainingWork(getDuration(row.getRemainingUnits())); assignment.setBaselineWork(getDuration(row.getPlannedUnits())); assignment.setActualWork(getDuration(row.getActualUnits())); assignment.setRemainingCost(row.getRemainingCost()); assignment.setBaselineCost(row.getPlannedCost()); assignment.setActualCost(row.getActualCost()); assignment.setActualStart(row.getActualStartDate()); assignment.setActualFinish(row.getActualFinishDate()); assignment.setBaselineStart(row.getPlannedStartDate()); assignment.setBaselineFinish(row.getPlannedFinishDate()); assignment.setGUID(DatatypeConverter.parseUUID(row.getGUID())); task.setActualCost(Double.valueOf(NumberHelper.getDouble(task.getActualCost()) + NumberHelper.getDouble(assignment.getActualCost()))); task.setRemainingCost(Double.valueOf(NumberHelper.getDouble(task.getRemainingCost()) + NumberHelper.getDouble(assignment.getRemainingCost()))); task.setBaselineCost(Double.valueOf(NumberHelper.getDouble(task.getBaselineCost()) + NumberHelper.getDouble(assignment.getBaselineCost()))); populateField(assignment, AssignmentField.WORK, AssignmentField.ACTUAL_WORK, AssignmentField.BASELINE_WORK); populateField(assignment, AssignmentField.COST, AssignmentField.ACTUAL_COST, AssignmentField.BASELINE_COST); populateField(assignment, AssignmentField.START, AssignmentField.ACTUAL_START, AssignmentField.BASELINE_START); populateField(assignment, AssignmentField.FINISH, AssignmentField.ACTUAL_FINISH, AssignmentField.BASELINE_FINISH); readUDFTypes(assignment, row.getUDF()); m_eventManager.fireAssignmentReadEvent(assignment); } } }
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: BasicTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Common tests for MSPDI fileExtended Attribute values. * * @param xml MSPDI file */ private void commonMspdiExtendedAttributeTests(ProjectFile xml) { List<Task> tasks = xml.getTasks(); assertEquals(2, tasks.size()); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); Task task = tasks.get(1); assertEquals("Task Text One", task.getText(1)); assertEquals("01/01/2004", df.format(task.getStart(1))); assertEquals("31/12/2004", df.format(task.getFinish(1))); assertEquals(99.95, task.getCost(1).doubleValue(), 0.0); assertEquals("18/07/2004", df.format(task.getDate(1))); assertTrue(task.getFlag(1)); assertEquals(55.56, task.getNumber(1).doubleValue(), 0.0); assertEquals(13.0, task.getDuration(1).getDuration(), 0.0); assertEquals(TimeUnit.DAYS, task.getDuration(1).getUnits()); List<Resource> resources = xml.getResources(); assertEquals(2, resources.size()); Resource resource = resources.get(1); assertEquals("Resource Text One", resource.getText(1)); assertEquals("01/01/2003", df.format(resource.getStart(1))); assertEquals("31/12/2003", df.format(resource.getFinish(1))); assertEquals(29.99, resource.getCost(1).doubleValue(), 0.0); assertEquals("18/07/2003", df.format(resource.getDate(1))); assertTrue(resource.getFlag(1)); assertEquals(5.99, resource.getNumber(1).doubleValue(), 0.0); assertEquals(22.0, resource.getDuration(1).getDuration(), 0.0); assertEquals(TimeUnit.DAYS, resource.getDuration(1).getUnits()); }
Example #26
Source File: MerlinReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Read all top level tasks. */ private void processTasks() throws SQLException { // // Yes... we could probably read this in one query in the right order // using a CTE... but life's too short. // List<Row> rows = getRows("select * from zscheduleitem where zproject=? and zparentactivity_ is null and z_ent=? order by zorderinparentactivity", m_projectID, m_entityMap.get("Activity")); for (Row row : rows) { Task task = m_project.addTask(); populateTask(row, task); processChildTasks(task); } }
Example #27
Source File: PhoenixReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Read an individual Phoenix task relationship. * * @param relation Phoenix task relationship */ private void readRelation(Relationship relation) { Task predecessor = m_activityMap.get(relation.getPredecessor()); Task successor = m_activityMap.get(relation.getSuccessor()); if (predecessor != null && successor != null) { Duration lag = relation.getLag(); RelationType type = relation.getType(); successor.addPredecessor(predecessor, type, lag); } }
Example #28
Source File: AstaReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Uses data from a bar to populate a task. * * @param row bar data * @param task task to populate */ private void populateBar(Row row, Task task) { Integer calendarID = row.getInteger("_CALENDAU"); if (calendarID == null) { calendarID = row.getInteger("_COMMON_CALENDAR"); } ProjectCalendar calendar = m_project.getCalendarByUniqueID(calendarID); //PROJID task.setUniqueID(row.getInteger("BARID")); task.setStart(row.getDate("STARV")); task.setFinish(row.getDate("ENF")); //NATURAL_ORDER //SPARI_INTEGER task.setName(row.getString("NAMH")); //EXPANDED_TASK //PRIORITY //UNSCHEDULABLE //MARK_FOR_HIDING //TASKS_MAY_OVERLAP //SUBPROJECT_ID //ALT_ID //LAST_EDITED_DATE //LAST_EDITED_BY //Proc_Approve //Proc_Design_info //Proc_Proc_Dur //Proc_Procurement //Proc_SC_design //Proc_Select_SC //Proc_Tender //QA Checked //Related_Documents task.setCalendar(calendar); task.setDuration(task.getEffectiveCalendar().getDuration(task.getStart(), task.getFinish())); }
Example #29
Source File: TurboProjectReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Read the leaf tasks for an individual WBS node. * * @param parent parent task * @param id first task ID */ private void readLeafTasks(Task parent, Integer id) { Integer currentID = id; Table table = getTable("A1TAB"); while (currentID.intValue() != 0) { if (m_projectFile.getTaskByUniqueID(currentID) == null) { readTask(parent, currentID); } currentID = table.find(currentID).getInteger("NEXT_TASK_ID"); } }
Example #30
Source File: SureTrakDatabaseReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Read resource assignments. */ private void readResourceAssignments() { for (MapRow row : m_tables.get("RES")) { Task task = m_activityMap.get(row.getString("ACTIVITY_ID")); Resource resource = m_resourceMap.get(row.getString("RESOURCE_ID")); if (task != null && resource != null) { task.addResourceAssignment(resource); } } }