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

The following examples show how to use net.sf.mpxj.Task#addTask() . 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: MerlinReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read all child tasks for a given parent.
 *
 * @param parentTask parent task
 */
private void processChildTasks(Task parentTask) throws SQLException
{
   List<Row> rows = getRows("select * from zscheduleitem where zparentactivity_=? and z_ent=? order by zorderinparentactivity", parentTask.getUniqueID(), m_entityMap.get("Activity"));
   for (Row row : rows)
   {
      Task task = parentTask.addTask();
      populateTask(row, task);
      processChildTasks(task);
   }
}
 
Example 3
Source File: TaskContainerTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test fix for SourceForge issue 277.
 */
@Test public void testSynchronizeTaskIDToHierarchy() throws Exception
{
   ProjectFile file = new ProjectFile();
   file.getProjectConfig().setAutoTaskID(false);

   Task task1 = file.addTask();
   Task task2 = file.addTask();
   Task task3 = task2.addTask();
   Task task4 = task3.addTask();

   assertEquals(null, task1.getID());
   assertEquals(null, task2.getID());
   assertEquals(null, task3.getID());
   assertEquals(null, task4.getID());

   assertEquals(4, file.getTasks().size());

   file.getTasks().synchronizeTaskIDToHierarchy();

   assertEquals(4, file.getTasks().size());

   assertEquals(Integer.valueOf(1), task1.getID());
   assertEquals(Integer.valueOf(2), task2.getID());
   assertEquals(Integer.valueOf(3), task3.getID());
   assertEquals(Integer.valueOf(4), task4.getID());

   assertEquals(task1, file.getChildTasks().get(0));
   assertEquals(task2, file.getChildTasks().get(1));
   assertEquals(task3, task2.getChildTasks().get(0));
   assertEquals(task4, task3.getChildTasks().get(0));
}
 
Example 4
Source File: ExportMSProject.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
private static void addTask(final ProjectFile file, final Map<Serializable, Task> taskMap, final Task parentTask,
    final GanttTask ganttTask)
{
  final Task task;
  if (parentTask == null) {
    task = file.addTask();
  } else {
    task = parentTask.addTask();
  }
  taskMap.put(ganttTask.getId(), task);
  task.setName(ganttTask.getTitle());
  if (ganttTask.getStartDate() != null) {
    task.setStart(ganttTask.getStartDate());
  }
  if (ganttTask.getEndDate() != null) {
    task.setFinish(ganttTask.getEndDate());
  }
  final BigDecimal duration = ganttTask.getDuration();
  final double value;
  if (duration == null) {
    value = 0.0;
  } else {
    value = duration.doubleValue();
  }
  task.setDuration(Duration.getInstance(value, TimeUnit.DAYS));
  if (ganttTask.getProgress() != null) {
    task.setPercentageComplete(ganttTask.getProgress());
  }
  // task2.setActualStart(df.parse("01/01/2003"));
  // milestone1.setDuration(Duration.getInstance(0, TimeUnit.DAYS));

  final List<GanttTask> children = ganttTask.getChildren();
  if (children == null) {
    return;
  }
  for (final GanttTask child : children) {
    addTask(file, taskMap, task, child);
  }
}
 
Example 5
Source File: ConceptDrawProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Read a task from a ConceptDraw PROJECT file.
 *
 * @param projectIdentifier parent project identifier
 * @param map outline number to task map
 * @param task ConceptDraw PROJECT task
 */
private void readTask(String projectIdentifier, Map<String, Task> map, Document.Projects.Project.Task task)
{
   Task parentTask = map.get(getParentOutlineNumber(task.getOutlineNumber()));
   Task mpxjTask = parentTask.addTask();

   TimeUnit units = task.getBaseDurationTimeUnit();

   mpxjTask.setCost(task.getActualCost());
   mpxjTask.setDuration(getDuration(units, task.getActualDuration()));
   mpxjTask.setFinish(task.getActualFinishDate());
   mpxjTask.setStart(task.getActualStartDate());
   mpxjTask.setBaselineDuration(getDuration(units, task.getBaseDuration()));
   mpxjTask.setBaselineFinish(task.getBaseFinishDate());
   mpxjTask.setBaselineCost(task.getBaselineCost());
   //      task.getBaselineFinishDate()
   //      task.getBaselineFinishTemplateOffset()
   //      task.getBaselineStartDate()
   //      task.getBaselineStartTemplateOffset()
   mpxjTask.setBaselineStart(task.getBaseStartDate());
   //      task.getCallouts()
   mpxjTask.setPercentageComplete(task.getComplete());
   mpxjTask.setDeadline(task.getDeadlineDate());
   //      task.getDeadlineTemplateOffset()
   //      task.getHyperlinks()
   //      task.getMarkerID()
   mpxjTask.setName(task.getName());
   mpxjTask.setNotes(task.getNote());
   mpxjTask.setPriority(task.getPriority());
   //      task.getRecalcBase1()
   //      task.getRecalcBase2()
   mpxjTask.setType(task.getSchedulingType());
   //      task.getStyleProject()
   //      task.getTemplateOffset()
   //      task.getValidatedByProject()

   if (task.isIsMilestone())
   {
      mpxjTask.setMilestone(true);
      mpxjTask.setDuration(Duration.getInstance(0, TimeUnit.HOURS));
      mpxjTask.setBaselineDuration(Duration.getInstance(0, TimeUnit.HOURS));
   }

   String taskIdentifier = projectIdentifier + "." + task.getID();
   m_taskIdMap.put(task.getID(), mpxjTask);
   mpxjTask.setGUID(UUID.nameUUIDFromBytes(taskIdentifier.getBytes()));

   map.put(task.getOutlineNumber(), mpxjTask);

   for (Document.Projects.Project.Task.ResourceAssignments.ResourceAssignment assignment : task.getResourceAssignments().getResourceAssignment())
   {
      readResourceAssignment(mpxjTask, assignment);
   }
}
 
Example 6
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This test exercises the automatic generation of WBS and outline levels.
 */
@Test public void testAutomaticGeneration() throws Exception
{
   ProjectFile file = new ProjectFile();

   Resource resource1 = file.addResource();
   resource1.setName("R1");
   assertEquals(1, resource1.getUniqueID().intValue());
   assertEquals(1, resource1.getID().intValue());

   Resource resource2 = file.addResource();
   resource2.setName("R2");
   assertEquals(2, resource2.getUniqueID().intValue());
   assertEquals(2, resource2.getID().intValue());

   Task task1 = file.addTask();
   task1.setName("1.0");
   assertEquals("1", task1.getWBS());
   assertEquals(1, task1.getOutlineLevel().intValue());
   assertEquals("1", task1.getOutlineNumber());
   assertEquals(1, task1.getID().intValue());
   assertEquals(1, task1.getUniqueID().intValue());
   assertFalse(task1.getSummary());

   task1 = file.addTask();
   task1.setName("2.0");
   assertEquals("2", task1.getWBS());
   assertEquals(1, task1.getOutlineLevel().intValue());
   assertEquals("2", task1.getOutlineNumber());
   assertEquals(2, task1.getID().intValue());
   assertEquals(2, task1.getUniqueID().intValue());
   assertFalse(task1.getSummary());

   task1 = file.addTask();
   task1.setName("3.0");
   assertEquals("3", task1.getWBS());
   assertEquals(1, task1.getOutlineLevel().intValue());
   assertEquals("3", task1.getOutlineNumber());
   assertEquals(3, task1.getID().intValue());
   assertEquals(3, task1.getUniqueID().intValue());
   assertFalse(task1.getSummary());

   Task task2 = task1.addTask();
   task2.setName("3.1");
   assertEquals("3.1", task2.getWBS());
   assertEquals(2, task2.getOutlineLevel().intValue());
   assertEquals("3.1", task2.getOutlineNumber());
   assertEquals(4, task2.getID().intValue());
   assertEquals(4, task2.getUniqueID().intValue());
   assertTrue(task1.getSummary());
   assertFalse(task2.getSummary());

   task2 = task1.addTask();
   task2.setName("3.2");
   assertEquals("3.2", task2.getWBS());
   assertEquals(2, task2.getOutlineLevel().intValue());
   assertEquals("3.2", task2.getOutlineNumber());
   assertEquals(5, task2.getID().intValue());
   assertEquals(5, task2.getUniqueID().intValue());
   assertTrue(task1.getSummary());
   assertFalse(task2.getSummary());

   Task task3 = task2.addTask();
   task3.setName("3.2.1");
   assertEquals("3.2.1", task3.getWBS());
   assertEquals(3, task3.getOutlineLevel().intValue());
   assertEquals("3.2.1", task3.getOutlineNumber());
   assertEquals(6, task3.getID().intValue());
   assertEquals(6, task3.getUniqueID().intValue());
   assertTrue(task1.getSummary());
   assertTrue(task2.getSummary());
   assertFalse(task3.getSummary());

   task3 = task2.addTask();
   task3.setName("3.2.2");
   assertEquals("3.2.2", task3.getWBS());
   assertEquals(3, task3.getOutlineLevel().intValue());
   assertEquals("3.2.2", task3.getOutlineNumber());
   assertEquals(7, task3.getID().intValue());
   assertEquals(7, task3.getUniqueID().intValue());
   assertTrue(task1.getSummary());
   assertTrue(task2.getSummary());
   assertFalse(task3.getSummary());
}