Java Code Examples for net.sf.mpxj.ProjectFile#getTasks()

The following examples show how to use net.sf.mpxj.ProjectFile#getTasks() . 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: TaskDateDump.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Dump data for all non-summary tasks to stdout.
 *
 * @param name file name
 */
public void process(String name) throws Exception
{
   ProjectFile file = new UniversalProjectReader().read(name);
   for (Task task : file.getTasks())
   {
      if (!task.getSummary())
      {
         System.out.print(task.getWBS());
         System.out.print("\t");
         System.out.print(task.getName());
         System.out.print("\t");
         System.out.print(format(task.getStart()));
         System.out.print("\t");
         System.out.print(format(task.getActualStart()));
         System.out.print("\t");
         System.out.print(format(task.getFinish()));
         System.out.print("\t");
         System.out.print(format(task.getActualFinish()));
         System.out.println();
      }
   }
}
 
Example 2
Source File: MpxjQuery.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method lists task predecessor and successor relationships.
 *
 * @param file project file
 */
private static void listRelationships(ProjectFile file)
{
   for (Task task : file.getTasks())
   {
      System.out.print(task.getID());
      System.out.print('\t');
      System.out.print(task.getName());
      System.out.print('\t');

      dumpRelationList(task.getPredecessors());
      System.out.print('\t');
      dumpRelationList(task.getSuccessors());
      System.out.println();
   }
}
 
Example 3
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Simple test to exercise iterating through the task predecessors.
 *
 * @throws Exception
 */
@Test public void testRelationList() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/sample.mpx"));
   ProjectFile mpx = new MPXReader().read(in);

   for (Task task : mpx.getTasks())
   {
      List<Relation> rels = task.getPredecessors();
      if (rels != null)
      {
         for (Relation rel : rels)
         {
            assertNotNull(mpx.getTaskByUniqueID(rel.getTargetTask().getUniqueID()));
         }
      }
   }
}
 
Example 4
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This test reads flags from an MPP8 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 testMPP8Flags2() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/mpp8flags2.mpp"));
   ProjectFile mpp = new MPPReader().read(in);
   int index = 0;
   boolean[] flags;

   for (Task task : mpp.getTasks())
   {
      if (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 5
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 6
Source File: MpxjQuery.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method lists all tasks defined in the file.
 *
 * @param file MPX file
 */
private static void listTasks(ProjectFile file)
{
   SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm z");

   for (Task task : file.getTasks())
   {
      Date date = task.getStart();
      String text = task.getStartText();
      String startDate = text != null ? text : (date != null ? df.format(date) : "(no start date supplied)");

      date = task.getFinish();
      text = task.getFinishText();
      String finishDate = text != null ? text : (date != null ? df.format(date) : "(no finish date supplied)");

      Duration dur = task.getDuration();
      text = task.getDurationText();
      String duration = text != null ? text : (dur != null ? dur.toString() : "(no duration supplied)");

      dur = task.getActualDuration();
      String actualDuration = dur != null ? dur.toString() : "(no actual duration supplied)";

      String baselineDuration = task.getBaselineDurationText();
      if (baselineDuration == null)
      {
         dur = task.getBaselineDuration();
         if (dur != null)
         {
            baselineDuration = dur.toString();
         }
         else
         {
            baselineDuration = "(no duration supplied)";
         }
      }

      System.out.println("Task: " + task.getName() + " ID=" + task.getID() + " Unique ID=" + task.getUniqueID() + " (Start Date=" + startDate + " Finish Date=" + finishDate + " Duration=" + duration + " Actual Duration" + actualDuration + " Baseline Duration=" + baselineDuration + " Outline Level=" + task.getOutlineLevel() + " Outline Number=" + task.getOutlineNumber() + " Recurring=" + task.getRecurring() + ")");
   }
   System.out.println();
}
 
Example 7
Source File: MpxjQuery.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 8
Source File: MpxjQuery.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method lists any notes attached to tasks.
 *
 * @param file MPX file
 */
private static void listTaskNotes(ProjectFile file)
{
   for (Task task : file.getTasks())
   {
      String notes = task.getNotes();

      if (notes.length() != 0)
      {
         System.out.println("Notes for " + task.getName() + ": " + notes);
      }
   }

   System.out.println();
}
 
Example 9
Source File: MpxjQuery.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * List the slack values for each task.
 *
 * @param file ProjectFile instance
 */
private static void listSlack(ProjectFile file)
{
   for (Task task : file.getTasks())
   {
      System.out.println(task.getName() + " Total Slack=" + task.getTotalSlack() + " Start Slack=" + task.getStartSlack() + " Finish Slack=" + task.getFinishSlack());
   }
}
 
Example 10
Source File: MpxjFilter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Apply a filter to the list of all tasks, and show the results.
 *
 * @param project project file
 * @param filter filter
 */
private static void processTaskFilter(ProjectFile project, Filter filter)
{
   for (Task task : project.getTasks())
   {
      if (filter.evaluate(task, null))
      {
         System.out.println(task.getID() + "," + task.getUniqueID() + "," + task.getName());
      }
   }
}
 
Example 11
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read an MPP file where the structure was not being correctly
 * set up to reflect the outline level.
 */
@Test public void testBug3() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/bug3.mpp"));
   ProjectFile mpp = new MPPReader().read(in);

   for (Task task : mpp.getTasks())
   {
      assertEquals("Outline levels do not match", task.getOutlineLevel().intValue(), calculateOutlineLevel(task));
   }
}
 
Example 12
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 13
Source File: MppGraphIndTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Common graphical indicator tests.
 *
 * @param project project to test
 */
private void testGraphicalIndicators(ProjectFile project)
{
   List<Task> taskList = project.getTasks();
   Task[] tasks = taskList.toArray(new Task[taskList.size()]);

   testIndicator(project, TaskField.COST1, tasks, COST1_RESULTS);
   testIndicator(project, TaskField.COST2, tasks, COST2_RESULTS);
   testIndicator(project, TaskField.COST3, tasks, COST3_RESULTS);
   testIndicator(project, TaskField.COST4, tasks, COST4_RESULTS);

   testIndicator(project, TaskField.DATE1, tasks, DATE1_RESULTS);
   testIndicator(project, TaskField.DATE2, tasks, DATE2_RESULTS);
   testIndicator(project, TaskField.DATE3, tasks, DATE3_RESULTS);
   testIndicator(project, TaskField.DATE4, tasks, DATE4_RESULTS);
   testIndicator(project, TaskField.DATE5, tasks, DATE5_RESULTS);

   testIndicator(project, TaskField.DURATION1, tasks, DURATION1_RESULTS);
   testIndicator(project, TaskField.DURATION2, tasks, DURATION2_RESULTS);
   testIndicator(project, TaskField.DURATION3, tasks, DURATION3_RESULTS);
   testIndicator(project, TaskField.DURATION4, tasks, DURATION4_RESULTS);

   testIndicator(project, TaskField.FLAG1, tasks, FLAG_RESULTS);
   testIndicator(project, TaskField.FLAG2, tasks, FLAG_RESULTS);
   testIndicator(project, TaskField.FLAG3, tasks, FLAG_RESULTS);

   testIndicator(project, TaskField.NUMBER1, tasks, NUMBER1_RESULTS);
   testIndicator(project, TaskField.NUMBER2, tasks, NUMBER2_RESULTS);
   testIndicator(project, TaskField.NUMBER3, tasks, NUMBER3_RESULTS);
   testIndicator(project, TaskField.NUMBER4, tasks, NUMBER4_RESULTS);

   testIndicator(project, TaskField.TEXT1, tasks, TEXT1_RESULTS);
   testIndicator(project, TaskField.TEXT2, tasks, TEXT2_RESULTS);
   testIndicator(project, TaskField.TEXT3, tasks, TEXT3_RESULTS);
   testIndicator(project, TaskField.TEXT4, tasks, TEXT4_RESULTS);
   testIndicator(project, TaskField.TEXT5, tasks, TEXT5_RESULTS);
   testIndicator(project, TaskField.TEXT6, tasks, TEXT6_RESULTS);
   testIndicator(project, TaskField.TEXT7, tasks, TEXT7_RESULTS);
}
 
Example 14
Source File: MppFilterLogicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Common filter logic tests.
 *
 * @param mpp project file
 * @throws Exception
 */
private void testFilterLogic(ProjectFile mpp)
{
   List<Task> listAllTasks = mpp.getTasks();
   Task ac1 = listAllTasks.get(1);
   assertEquals("ac1", ac1.getName());

   Task ac2 = listAllTasks.get(2);
   assertEquals("ac2", ac2.getName());

   /*
    * InBlockAnd use:
    *    name equals ac1
    *    AND name equals ac1
    *    OR name equals ac2
    *
    * MSP evaluates this to includes both ac1 and ac2
    */
   Filter inBlockAndFilter = mpp.getFilters().getFilterByName("InBlockAnd");

   assertTrue(inBlockAndFilter.evaluate(ac1, null));
   assertTrue(inBlockAndFilter.evaluate(ac2, null));

   /*
    * BetweenBlockAnd use:
    *    name equals ac1
    *
    *    AND
    *
    *    name equals ac1
    *    OR name equals ac2
    *
    * MSP evaluates this to only include ac1
    */
   Filter betweenBlockAndFilter = mpp.getFilters().getFilterByName("BetweenBlockAnd");
   assertTrue(betweenBlockAndFilter.evaluate(ac1, null));
   assertFalse(betweenBlockAndFilter.evaluate(ac2, null));
}
 
Example 15
Source File: MppTaskTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * 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());
}
 
Example 16
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 MPP8 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 testMPP8Flags1() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/mpp8flags1.mpp"));
   ProjectFile mpp = new MPPReader().read(in);
   List<Task> tasks = mpp.getTasks();
   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));
   }
}