Java Code Examples for net.sf.mpxj.Task#getResourceAssignments()
The following examples show how to use
net.sf.mpxj.Task#getResourceAssignments() .
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: MpxjQuery.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * This method displays the resource assignments for each task. This time * rather than just iterating through the list of all assignments in * the file, we extract the assignments on a task-by-task basis. * * @param file MPX file */ private static void listAssignmentsByTask(ProjectFile file) { for (Task task : file.getTasks()) { System.out.println("Assignments for task " + task.getName() + ":"); for (ResourceAssignment assignment : task.getResourceAssignments()) { Resource resource = assignment.getResource(); String resourceName; if (resource == null) { resourceName = "(null resource)"; } else { resourceName = resource.getName(); } System.out.println(" " + resourceName); } } System.out.println(); }
Example 2
Source File: PrimaveraReader.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * See the notes above. * * @param parentTask parent task */ private void updateTaskCosts(Task parentTask) { double baselineCost = 0; double actualCost = 0; double remainingCost = 0; double cost = 0; //process children first before adding their costs for (Task child : parentTask.getChildTasks()) { updateTaskCosts(child); baselineCost += NumberHelper.getDouble(child.getBaselineCost()); actualCost += NumberHelper.getDouble(child.getActualCost()); remainingCost += NumberHelper.getDouble(child.getRemainingCost()); cost += NumberHelper.getDouble(child.getCost()); } List<ResourceAssignment> resourceAssignments = parentTask.getResourceAssignments(); for (ResourceAssignment assignment : resourceAssignments) { baselineCost += NumberHelper.getDouble(assignment.getBaselineCost()); actualCost += NumberHelper.getDouble(assignment.getActualCost()); remainingCost += NumberHelper.getDouble(assignment.getRemainingCost()); cost += NumberHelper.getDouble(assignment.getCost()); } parentTask.setBaselineCost(NumberHelper.getDouble(baselineCost)); parentTask.setActualCost(NumberHelper.getDouble(actualCost)); parentTask.setRemainingCost(NumberHelper.getDouble(remainingCost)); parentTask.setCost(NumberHelper.getDouble(cost)); }
Example 3
Source File: BasicTest.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * The files sample.mpp, sample98.mpp and sample.xml contain identical * data produced by MS Project. This method contains validation tests * on that data to ensure that the three file formats are being read * consistently. * * @param file ProjectFile instance */ private void commonTests(ProjectFile file) { // // Test the remaining work attribute // Task task = file.getTaskByUniqueID(Integer.valueOf(2)); List<ResourceAssignment> assignments = task.getResourceAssignments(); assertEquals(2, assignments.size()); for (ResourceAssignment assignment : assignments) { switch (NumberHelper.getInt(assignment.getResource().getID())) { case 1: { assertEquals(200, (int) assignment.getRemainingWork().getDuration()); assertEquals(TimeUnit.HOURS, assignment.getRemainingWork().getUnits()); break; } case 2: { assertEquals(300, (int) assignment.getRemainingWork().getDuration()); assertEquals(TimeUnit.HOURS, assignment.getRemainingWork().getUnits()); break; } default: { assertTrue("Unexpected resource", false); break; } } } }
Example 4
Source File: MPXWriter.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * Write a task. * * @param record task instance * @throws IOException */ private void writeTask(Task record) throws IOException { m_buffer.setLength(0); // // Write the task // int[] fields = m_taskModel.getModel(); int field; m_buffer.append(MPXConstants.TASK_RECORD_NUMBER); for (int loop = 0; loop < fields.length; loop++) { field = fields[loop]; if (field == -1) { break; } TaskField taskField = MPXTaskField.getMpxjField(field); Object value = record.getCachedValue(taskField); value = formatType(taskField.getDataType(), value); m_buffer.append(m_delimiter); m_buffer.append(format(value)); } stripTrailingDelimiters(m_buffer); m_buffer.append(MPXConstants.EOL); m_writer.write(m_buffer.toString()); // // Write the task notes // String notes = record.getNotes(); if (notes.length() != 0) { writeNotes(MPXConstants.TASK_NOTES_RECORD_NUMBER, notes); } // // Write the recurring task // if (record.getRecurringTask() != null) { writeRecurringTask(record.getRecurringTask()); } // // Write any resource assignments // if (record.getResourceAssignments().isEmpty() == false) { for (ResourceAssignment assignment : record.getResourceAssignments()) { writeResourceAssignment(assignment); } } m_eventManager.fireTaskWrittenEvent(record); }
Example 5
Source File: MppAssignmentTest.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * Validate custom field values. * * @param mpp project file * @throws Exception */ private void testCustomFields(ProjectFile mpp) throws Exception { DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm"); Task task = mpp.getTaskByID(Integer.valueOf(1)); assertEquals("Task One", task.getName()); List<ResourceAssignment> assignments = task.getResourceAssignments(); ResourceAssignment assignment1 = assignments.get(0); assertEquals("Resource One", assignment1.getResource().getName()); ResourceAssignment assignment2 = assignments.get(1); assertEquals("Resource Two", assignment2.getResource().getName()); for (int loop = 0; loop < 10; loop++) { assertEquals("Assignment 1 baseline cost " + (loop + 1), BASELINE_COSTS[0][loop], assignment1.getBaselineCost(loop + 1).intValue()); assertEquals("Assignment 2 baseline cost " + (loop + 1), BASELINE_COSTS[1][loop], assignment2.getBaselineCost(loop + 1).intValue()); assertEquals("Assignment 1 baseline work " + (loop + 1), BASELINE_WORKS[0][loop], (int) assignment1.getBaselineWork(loop + 1).getDuration()); assertEquals("Assignment 2 baseline work " + (loop + 1), BASELINE_WORKS[1][loop], (int) assignment2.getBaselineWork(loop + 1).getDuration()); assertEquals("Assignment 1 baseline work " + (loop + 1), TimeUnit.HOURS, assignment1.getBaselineWork(loop + 1).getUnits()); assertEquals("Assignment 2 baseline work " + (loop + 1), TimeUnit.HOURS, assignment2.getBaselineWork(loop + 1).getUnits()); assertEquals("Assignment 1 baseline start " + (loop + 1), BASELINE_STARTS[0][loop], df.format(assignment1.getBaselineStart(loop + 1))); assertEquals("Assignment 2 baseline start " + (loop + 1), BASELINE_STARTS[1][loop], df.format(assignment2.getBaselineStart(loop + 1))); assertEquals("Assignment 1 baseline finish " + (loop + 1), BASELINE_FINISHES[0][loop], df.format(assignment1.getBaselineFinish(loop + 1))); assertEquals("Assignment 2 baseline finish " + (loop + 1), BASELINE_FINISHES[1][loop], df.format(assignment2.getBaselineFinish(loop + 1))); assertEquals("Assignment 1 start " + (loop + 1), CUSTOM_START[0][loop], df.format(assignment1.getStart(loop + 1))); assertEquals("Assignment 2 start " + (loop + 1), CUSTOM_START[1][loop], df.format(assignment2.getStart(loop + 1))); assertEquals("Assignment 1 finish " + (loop + 1), CUSTOM_FINISH[0][loop], df.format(assignment1.getFinish(loop + 1))); assertEquals("Assignment 2 finish " + (loop + 1), CUSTOM_FINISH[1][loop], df.format(assignment2.getFinish(loop + 1))); assertEquals("Assignment 1 date " + (loop + 1), CUSTOM_DATE[0][loop], df.format(assignment1.getDate(loop + 1))); assertEquals("Assignment 2 date " + (loop + 1), CUSTOM_DATE[1][loop], df.format(assignment2.getDate(loop + 1))); assertEquals("Assignment 1 duration " + (loop + 1), CUSTOM_DURATION[0][loop], assignment1.getDuration(loop + 1).getDuration(), 0.01); assertEquals("Assignment 2 duration " + (loop + 1), CUSTOM_DURATION[1][loop], assignment2.getDuration(loop + 1).getDuration(), 0.01); assertEquals("Assignment 1 duration " + (loop + 1), TimeUnit.DAYS, assignment1.getDuration(loop + 1).getUnits()); assertEquals("Assignment 2 duration " + (loop + 1), TimeUnit.DAYS, assignment2.getDuration(loop + 1).getUnits()); assertEquals("Assignment 1 cost " + (loop + 1), CUSTOM_COST[0][loop], assignment1.getCost(loop + 1).doubleValue(), 0.01); assertEquals("Assignment 2 cost " + (loop + 1), CUSTOM_COST[1][loop], assignment2.getCost(loop + 1).doubleValue(), 0.01); } for (int loop = 0; loop < CUSTOM_TEXT.length; loop++) { assertEquals("Assignment 1 text " + (loop + 1), CUSTOM_TEXT[0][loop], assignment1.getText(loop + 1)); assertEquals("Assignment 2 text " + (loop + 1), CUSTOM_TEXT[1][loop], assignment2.getText(loop + 1)); } for (int loop = 0; loop < CUSTOM_NUMBER.length; loop++) { assertEquals("Assignment 1 number " + (loop + 1), CUSTOM_NUMBER[0][loop], assignment1.getNumber(loop + 1).intValue()); assertEquals("Assignment 2 number " + (loop + 1), CUSTOM_NUMBER[1][loop], assignment2.getNumber(loop + 1).intValue()); } for (int loop = 0; loop < CUSTOM_FLAG.length; loop++) { assertBooleanEquals("Assignment 1 flag " + (loop + 1), CUSTOM_FLAG[0][loop], assignment1.getFlag(loop + 1)); assertBooleanEquals("Assignment 2 flag " + (loop + 1), CUSTOM_FLAG[1][loop], assignment2.getFlag(loop + 1)); } }