Java Code Examples for net.sf.mpxj.Task#getChildTasks()

The following examples show how to use net.sf.mpxj.Task#getChildTasks() . 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: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 2
Source File: SynchroReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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: ProjectCommanderReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 4
Source File: AstaReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 5
Source File: JsonWriter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method is called recursively to write a task and its child tasks
 * to the JSON file.
 *
 * @param task task to write
 */
private void writeTask(Task task) throws IOException
{
   writeFields(null, task, TaskField.values());
   for (Task child : task.getChildTasks())
   {
      writeTask(child);
   }
}
 
Example 6
Source File: MpxjQuery.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Helper method called recursively to list child tasks.
 *
 * @param task task whose children are to be displayed
 * @param indent whitespace used to indent hierarchy levels
 */
private static void listHierarchy(Task task, String indent)
{
   for (Task child : task.getChildTasks())
   {
      System.out.println(indent + "Task: " + child.getName() + "\t" + child.getStart() + "\t" + child.getFinish());
      listHierarchy(child, indent + " ");
   }
}
 
Example 7
Source File: PrimaveraPMFileWriter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Used to write the child tasks of a parent task to the PM XML file.
 *
 * @param parent parent Task instance
 */
private void writeChildTasks(Task parent)
{
   for (Task task : parent.getChildTasks())
   {
      writeTask(task);
   }
}
 
Example 8
Source File: PrimaveraReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 9
Source File: PrimaveraReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * See the notes above.
 *
 * @param parentTask parent task.
 */
private void updateWork(Task parentTask)
{
   if (parentTask.hasChildTasks())
   {
      ProjectProperties properties = m_project.getProjectProperties();

      Duration actualWork = null;
      Duration baselineWork = null;
      Duration remainingWork = null;
      Duration work = null;

      for (Task task : parentTask.getChildTasks())
      {
         updateWork(task);

         actualWork = Duration.add(actualWork, task.getActualWork(), properties);
         baselineWork = Duration.add(baselineWork, task.getBaselineWork(), properties);
         remainingWork = Duration.add(remainingWork, task.getRemainingWork(), properties);
         work = Duration.add(work, task.getWork(), properties);
      }

      parentTask.setActualWork(actualWork);
      parentTask.setBaselineWork(baselineWork);
      parentTask.setRemainingWork(remainingWork);
      parentTask.setWork(work);
   }
}
 
Example 10
Source File: PrimaveraReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 11
Source File: PrimaveraPMFileReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 12
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * 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 13
Source File: P3DatabaseReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * See the notes above.
 *
 * @param parentTask parent task.
 */
private void updateDates(Task parentTask)
{
   if (parentTask.hasChildTasks())
   {
      int finished = 0;
      Date startDate = parentTask.getStart();
      Date finishDate = parentTask.getFinish();
      Date actualStartDate = parentTask.getActualStart();
      Date actualFinishDate = parentTask.getActualFinish();
      Date earlyStartDate = parentTask.getEarlyStart();
      Date earlyFinishDate = parentTask.getEarlyFinish();
      Date lateStartDate = parentTask.getLateStart();
      Date lateFinishDate = parentTask.getLateFinish();

      for (Task task : parentTask.getChildTasks())
      {
         updateDates(task);

         startDate = DateHelper.min(startDate, task.getStart());
         finishDate = DateHelper.max(finishDate, task.getFinish());
         actualStartDate = DateHelper.min(actualStartDate, task.getActualStart());
         actualFinishDate = DateHelper.max(actualFinishDate, task.getActualFinish());
         earlyStartDate = DateHelper.min(earlyStartDate, task.getEarlyStart());
         earlyFinishDate = DateHelper.max(earlyFinishDate, task.getEarlyFinish());
         lateStartDate = DateHelper.min(lateStartDate, task.getLateStart());
         lateFinishDate = DateHelper.max(lateFinishDate, task.getLateFinish());

         if (task.getActualFinish() != null)
         {
            ++finished;
         }
      }

      parentTask.setStart(startDate);
      parentTask.setFinish(finishDate);
      parentTask.setActualStart(actualStartDate);
      parentTask.setEarlyStart(earlyStartDate);
      parentTask.setEarlyFinish(earlyFinishDate);
      parentTask.setLateStart(lateStartDate);
      parentTask.setLateFinish(lateFinishDate);

      //
      // Only if all child tasks have actual finish dates do we
      // set the actual finish date on the parent task.
      //
      if (finished == parentTask.getChildTasks().size())
      {
         parentTask.setActualFinish(actualFinishDate);
      }
   }
}
 
Example 14
Source File: SureTrakDatabaseReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * See the notes above.
 *
 * @param parentTask parent task.
 */
private void updateDates(Task parentTask)
{
   if (parentTask.hasChildTasks())
   {
      int finished = 0;
      Date startDate = parentTask.getStart();
      Date finishDate = parentTask.getFinish();
      Date actualStartDate = parentTask.getActualStart();
      Date actualFinishDate = parentTask.getActualFinish();
      Date earlyStartDate = parentTask.getEarlyStart();
      Date earlyFinishDate = parentTask.getEarlyFinish();
      Date lateStartDate = parentTask.getLateStart();
      Date lateFinishDate = parentTask.getLateFinish();

      for (Task task : parentTask.getChildTasks())
      {
         updateDates(task);

         startDate = DateHelper.min(startDate, task.getStart());
         finishDate = DateHelper.max(finishDate, task.getFinish());
         actualStartDate = DateHelper.min(actualStartDate, task.getActualStart());
         actualFinishDate = DateHelper.max(actualFinishDate, task.getActualFinish());
         earlyStartDate = DateHelper.min(earlyStartDate, task.getEarlyStart());
         earlyFinishDate = DateHelper.max(earlyFinishDate, task.getEarlyFinish());
         lateStartDate = DateHelper.min(lateStartDate, task.getLateStart());
         lateFinishDate = DateHelper.max(lateFinishDate, task.getLateFinish());

         if (task.getActualFinish() != null)
         {
            ++finished;
         }
      }

      parentTask.setStart(startDate);
      parentTask.setFinish(finishDate);
      parentTask.setActualStart(actualStartDate);
      parentTask.setEarlyStart(earlyStartDate);
      parentTask.setEarlyFinish(earlyFinishDate);
      parentTask.setLateStart(lateStartDate);
      parentTask.setLateFinish(lateFinishDate);

      //
      // Only if all child tasks have actual finish dates do we
      // set the actual finish date on the parent task.
      //
      if (finished == parentTask.getChildTasks().size())
      {
         parentTask.setActualFinish(actualFinishDate);
      }
   }
}
 
Example 15
Source File: PhoenixReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * See the notes above.
 *
 * @param parentTask parent task.
 */
private void updateDates(Task parentTask)
{
   if (parentTask.hasChildTasks())
   {
      int finished = 0;
      Date plannedStartDate = parentTask.getStart();
      Date plannedFinishDate = parentTask.getFinish();
      Date actualStartDate = parentTask.getActualStart();
      Date actualFinishDate = parentTask.getActualFinish();
      Date earlyStartDate = parentTask.getEarlyStart();
      Date earlyFinishDate = parentTask.getEarlyFinish();
      Date lateStartDate = parentTask.getLateStart();
      Date lateFinishDate = parentTask.getLateFinish();

      for (Task task : parentTask.getChildTasks())
      {
         updateDates(task);

         plannedStartDate = DateHelper.min(plannedStartDate, task.getStart());
         plannedFinishDate = DateHelper.max(plannedFinishDate, task.getFinish());
         actualStartDate = DateHelper.min(actualStartDate, task.getActualStart());
         actualFinishDate = DateHelper.max(actualFinishDate, task.getActualFinish());
         earlyStartDate = DateHelper.min(earlyStartDate, task.getEarlyStart());
         earlyFinishDate = DateHelper.max(earlyFinishDate, task.getEarlyFinish());
         lateStartDate = DateHelper.min(lateStartDate, task.getLateStart());
         lateFinishDate = DateHelper.max(lateFinishDate, task.getLateFinish());

         if (task.getActualFinish() != null)
         {
            ++finished;
         }
      }

      parentTask.setStart(plannedStartDate);
      parentTask.setFinish(plannedFinishDate);
      parentTask.setActualStart(actualStartDate);
      parentTask.setEarlyStart(earlyStartDate);
      parentTask.setEarlyFinish(earlyFinishDate);
      parentTask.setLateStart(lateStartDate);
      parentTask.setLateFinish(lateFinishDate);

      //
      // Only if all child tasks have actual finish dates do we
      // set the actual finish date on the parent task.
      //
      if (finished == parentTask.getChildTasks().size())
      {
         parentTask.setActualFinish(actualFinishDate);
      }

      Duration duration = null;
      if (plannedStartDate != null && plannedFinishDate != null)
      {
         duration = m_projectFile.getDefaultCalendar().getWork(plannedStartDate, plannedFinishDate, TimeUnit.DAYS);
         parentTask.setDuration(duration);
      }
   }
}
 
Example 16
Source File: PlannerWriter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method writes data for a single task to a Planner file.
 *
 * @param mpxjTask MPXJ Task instance
 * @param taskList list of child tasks for current parent
 */
private void writeTask(Task mpxjTask, List<net.sf.mpxj.planner.schema.Task> taskList) throws JAXBException
{
   net.sf.mpxj.planner.schema.Task plannerTask = m_factory.createTask();
   taskList.add(plannerTask);
   plannerTask.setEnd(getDateTimeString(mpxjTask.getFinish()));
   plannerTask.setId(getIntegerString(mpxjTask.getUniqueID()));
   plannerTask.setName(getString(mpxjTask.getName()));
   plannerTask.setNote(mpxjTask.getNotes());
   plannerTask.setPercentComplete(getIntegerString(mpxjTask.getPercentageWorkComplete()));
   plannerTask.setPriority(mpxjTask.getPriority() == null ? null : getIntegerString(mpxjTask.getPriority().getValue() * 10));
   plannerTask.setScheduling(getScheduling(mpxjTask.getType()));
   plannerTask.setStart(getDateTimeString(DateHelper.getDayStartDate(mpxjTask.getStart())));
   if (mpxjTask.getMilestone())
   {
      plannerTask.setType("milestone");
   }
   else
   {
      plannerTask.setType("normal");
   }
   plannerTask.setWork(getDurationString(mpxjTask.getWork()));
   plannerTask.setWorkStart(getDateTimeString(mpxjTask.getStart()));

   ConstraintType mpxjConstraintType = mpxjTask.getConstraintType();
   if (mpxjConstraintType != ConstraintType.AS_SOON_AS_POSSIBLE)
   {
      Constraint plannerConstraint = m_factory.createConstraint();
      plannerTask.setConstraint(plannerConstraint);
      if (mpxjConstraintType == ConstraintType.START_NO_EARLIER_THAN)
      {
         plannerConstraint.setType("start-no-earlier-than");
      }
      else
      {
         if (mpxjConstraintType == ConstraintType.MUST_START_ON)
         {
            plannerConstraint.setType("must-start-on");
         }
      }

      plannerConstraint.setTime(getDateTimeString(mpxjTask.getConstraintDate()));
   }

   //
   // Write predecessors
   //
   writePredecessors(mpxjTask, plannerTask);

   m_eventManager.fireTaskWrittenEvent(mpxjTask);

   //
   // Write child tasks
   //
   List<net.sf.mpxj.planner.schema.Task> childTaskList = plannerTask.getTask();
   for (Task task : mpxjTask.getChildTasks())
   {
      writeTask(task, childTaskList);
   }
}
 
Example 17
Source File: AstaReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Populate summary task dates.
 * 
 * @param parentTask summary task
 */
private void updateDates(Task parentTask)
{
   if (parentTask.hasChildTasks())
   {
      int finished = 0;
      Date actualStartDate = parentTask.getActualStart();
      Date actualFinishDate = parentTask.getActualFinish();
      Date earlyStartDate = parentTask.getEarlyStart();
      Date earlyFinishDate = parentTask.getEarlyFinish();
      Date lateStartDate = parentTask.getLateStart();
      Date lateFinishDate = parentTask.getLateFinish();

      for (Task task : parentTask.getChildTasks())
      {
         updateDates(task);

         actualStartDate = DateHelper.min(actualStartDate, task.getActualStart());
         actualFinishDate = DateHelper.max(actualFinishDate, task.getActualFinish());
         earlyStartDate = DateHelper.min(earlyStartDate, task.getEarlyStart());
         earlyFinishDate = DateHelper.max(earlyFinishDate, task.getEarlyFinish());
         lateStartDate = DateHelper.min(lateStartDate, task.getLateStart());
         lateFinishDate = DateHelper.max(lateFinishDate, task.getLateFinish());

         if (task.getActualFinish() != null)
         {
            ++finished;
         }
      }

      parentTask.setActualStart(actualStartDate);
      parentTask.setEarlyStart(earlyStartDate);
      parentTask.setEarlyFinish(earlyFinishDate);
      parentTask.setLateStart(lateStartDate);
      parentTask.setLateFinish(lateFinishDate);

      //
      // Only if all child tasks have actual finish dates do we
      // set the actual finish date on the parent task.
      //
      if (finished == parentTask.getChildTasks().size())
      {
         parentTask.setActualFinish(actualFinishDate);
      }
   }
}