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

The following examples show how to use net.sf.mpxj.Task#addPredecessor() . 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: P3DatabaseReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read task relationships.
 */
private void readRelationships()
{
   for (MapRow row : m_tables.get("REL"))
   {
      Task predecessor = m_activityMap.get(row.getString("PREDECESSOR_ACTIVITY_ID"));
      Task successor = m_activityMap.get(row.getString("SUCCESSOR_ACTIVITY_ID"));
      if (predecessor != null && successor != null)
      {
         Duration lag = row.getDuration("LAG_VALUE");
         RelationType type = row.getRelationType("LAG_TYPE");

         successor.addPredecessor(predecessor, type, lag);
      }
   }
}
 
Example 2
Source File: SureTrakDatabaseReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read task relationships.
 */
private void readRelationships()
{
   for (MapRow row : m_tables.get("REL"))
   {
      Task predecessor = m_activityMap.get(row.getString("PREDECESSOR_ACTIVITY_ID"));
      Task successor = m_activityMap.get(row.getString("SUCCESSOR_ACTIVITY_ID"));
      if (predecessor != null && successor != null)
      {
         Duration lag = row.getDuration("LAG");
         RelationType type = row.getRelationType("TYPE");

         successor.addPredecessor(predecessor, type, lag);
      }
   }
}
 
Example 3
Source File: PrimaveraPMFileReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Process predecessors.
 *
 * @param project xml container
 */
private void processPredecessors(ProjectType project)
{
   for (RelationshipType row : project.getRelationship())
   {

      Task currentTask = m_projectFile.getTaskByUniqueID(mapTaskID(row.getSuccessorActivityObjectId()));
      Task predecessorTask = m_projectFile.getTaskByUniqueID(mapTaskID(row.getPredecessorActivityObjectId()));
      if (currentTask != null && predecessorTask != null)
      {
         RelationType type = RELATION_TYPE_MAP.get(row.getType());
         Duration lag = getDuration(row.getLag());
         Relation relation = currentTask.addPredecessor(predecessorTask, type, lag);
         relation.setUniqueID(row.getObjectId());
         m_eventManager.fireRelationReadEvent(relation);
      }
   }
}
 
Example 4
Source File: TurboProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 5
Source File: SageReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Process an individual predecessor.
 *
 * @param line predecessor record
 */
private void processPredecessor(String line)
{
   String[] columns = line.split("\t");

   Task task = m_taskMap.get(parseID(columns, 0));
   if (task == null)
   {
      return;
   }

   Task predecessor = m_taskMap.get(parseID(columns, 1));
   if (predecessor == null)
   {
      return;
   }

   RelationType type = parseRelationType(columns, 2);
   Duration lag = parseDuration(columns, 3);
   // columns[4] - job
   // columns[5] - predecessor name
   // columns[6] - unknown
   // columns[7] - unknown

   task.addPredecessor(predecessor, type, lag);
}
 
Example 6
Source File: GanttDesignerReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read predecessors from a Gantt Designer file.
 *
 * @param gantt Gantt Designer file
 */
private void processPredecessors(Gantt gantt)
{
   for (Gantt.Tasks.Task ganttTask : gantt.getTasks().getTask())
   {
      String predecessors = ganttTask.getP();
      if (predecessors != null && !predecessors.isEmpty())
      {
         String wbs = ganttTask.getID();
         Task task = m_taskMap.get(wbs);
         for (String predecessor : predecessors.split(";"))
         {
            Task predecessorTask = m_projectFile.getTaskByID(Integer.valueOf(predecessor));
            task.addPredecessor(predecessorTask, RelationType.FINISH_START, ganttTask.getL());
         }
      }
   }
}
 
Example 7
Source File: ProjectCommanderReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Read any relationships for a single task.
 *
 * @param task parent task
 * @param block relationship data
 */
private void readRelationships(Task task, Block block)
{
   byte[] data = block.getData();
   int successorTaskUniqueID = DatatypeConverter.getShort(data, 0);
   Task successor = m_projectFile.getTaskByUniqueID(Integer.valueOf(successorTaskUniqueID));

   if (successor == null || task.isSucessor(successor) || task.isPredecessor(successor) || data.length == 14)
   {
      return;
   }

   Duration lag = DatatypeConverter.getDuration(data, 6);
   RelationType type = DatatypeConverter.getRelationType(data, 2);

   successor.addPredecessor(task, type, lag);
}
 
Example 8
Source File: MerlinReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read relation data.
 */
private void processDependencies() throws SQLException
{
   List<Row> rows = getRows("select * from zdependency where zproject=?", m_projectID);
   for (Row row : rows)
   {
      Task nextTask = m_project.getTaskByUniqueID(row.getInteger("ZNEXTACTIVITY_"));
      Task prevTask = m_project.getTaskByUniqueID(row.getInteger("ZPREVIOUSACTIVITY_"));
      Duration lag = row.getDuration("ZLAG_");
      RelationType type = row.getRelationType("ZTYPE");
      Relation relation = nextTask.addPredecessor(prevTask, type, lag);
      relation.setUniqueID(row.getInteger("Z_PK"));
   }
}
 
Example 9
Source File: MPD9AbstractReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Process a relationship between two tasks.
 *
 * @param row relationship data
 */
protected void processLink(Row row)
{
   Task predecessorTask = m_project.getTaskByUniqueID(row.getInteger("LINK_PRED_UID"));
   Task successorTask = m_project.getTaskByUniqueID(row.getInteger("LINK_SUCC_UID"));
   if (predecessorTask != null && successorTask != null)
   {
      RelationType type = RelationType.getInstance(row.getInt("LINK_TYPE"));
      TimeUnit durationUnits = MPDUtility.getDurationTimeUnits(row.getInt("LINK_LAG_FMT"));
      Duration duration = MPDUtility.getDuration(row.getDouble("LINK_LAG").doubleValue(), durationUnits);
      Relation relation = successorTask.addPredecessor(predecessorTask, type, duration);
      relation.setUniqueID(row.getInteger("LINK_UID"));
      m_eventManager.fireRelationReadEvent(relation);
   }
}
 
Example 10
Source File: PrecedenceRecord.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override public void process(Context context)
{
   Task currentTask = context.getTask(getString(0));
   Task previousTask = context.getTask(getString(1));
   if (currentTask != null && previousTask != null)
   {
      Relation relation = currentTask.addPredecessor(previousTask, getRelationType(2), getDuration(3));
      context.getEventManager().fireRelationReadEvent(relation);
   }
}
 
Example 11
Source File: PhoenixReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 12
Source File: PlannerReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method extracts predecessor data from a Planner file.
 *
 * @param plannerTask Task data
 */
private void readPredecessors(net.sf.mpxj.planner.schema.Task plannerTask)
{
   Task mpxjTask = m_projectFile.getTaskByUniqueID(getInteger(plannerTask.getId()));

   Predecessors predecessors = plannerTask.getPredecessors();
   if (predecessors != null)
   {
      List<Predecessor> predecessorList = predecessors.getPredecessor();
      for (Predecessor predecessor : predecessorList)
      {
         Integer predecessorID = getInteger(predecessor.getPredecessorId());
         Task predecessorTask = m_projectFile.getTaskByUniqueID(predecessorID);
         if (predecessorTask != null)
         {
            Duration lag = getDuration(predecessor.getLag());
            if (lag == null)
            {
               lag = Duration.getInstance(0, TimeUnit.HOURS);
            }
            Relation relation = mpxjTask.addPredecessor(predecessorTask, RELATIONSHIP_TYPES.get(predecessor.getType()), lag);
            m_eventManager.fireRelationReadEvent(relation);
         }
      }
   }

   //
   // Process child tasks
   //
   List<net.sf.mpxj.planner.schema.Task> childTasks = plannerTask.getTask();
   for (net.sf.mpxj.planner.schema.Task childTask : childTasks)
   {
      readPredecessors(childTask);
   }
}
 
Example 13
Source File: GanttProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read the relationships for an individual GanttProject task.
 *
 * @param gpTask GanttProject task
 */
private void readRelationships(net.sf.mpxj.ganttproject.schema.Task gpTask)
{
   for (Depend depend : gpTask.getDepend())
   {
      Task task1 = m_projectFile.getTaskByUniqueID(Integer.valueOf(NumberHelper.getInt(gpTask.getId()) + 1));
      Task task2 = m_projectFile.getTaskByUniqueID(Integer.valueOf(NumberHelper.getInt(depend.getId()) + 1));
      if (task1 != null && task2 != null)
      {
         Duration lag = Duration.getInstance(NumberHelper.getInt(depend.getDifference()), TimeUnit.DAYS);
         Relation relation = task2.addPredecessor(task1, getRelationType(depend.getType()), lag);
         m_eventManager.fireRelationReadEvent(relation);
      }
   }
}
 
Example 14
Source File: SynchroReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Extract data for a single predecessor.
 *
 * @param task parent task
 * @param row Synchro predecessor data
 */
private void processPredecessor(Task task, MapRow row)
{
   Task predecessor = m_taskMap.get(row.getUUID("PREDECESSOR_UUID"));
   if (predecessor != null)
   {
      task.addPredecessor(predecessor, row.getRelationType("RELATION_TYPE"), row.getDuration("LAG"));
   }
}
 
Example 15
Source File: ConceptDrawProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read a task relationship.
 *
 * @param link ConceptDraw PROJECT task link
 */
private void readRelationship(Link link)
{
   Task sourceTask = m_taskIdMap.get(link.getSourceTaskID());
   Task destinationTask = m_taskIdMap.get(link.getDestinationTaskID());
   if (sourceTask != null && destinationTask != null)
   {
      Duration lag = getDuration(link.getLagUnit(), link.getLag());
      RelationType type = link.getType();
      Relation relation = destinationTask.addPredecessor(sourceTask, type, lag);
      relation.setUniqueID(link.getID());
   }
}
 
Example 16
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 17
Source File: MSPDIReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method extracts data for a single predecessor from an MSPDI file.
 *
 * @param currTask Current task object
 * @param link Predecessor data
 */
private void readPredecessor(Task currTask, Project.Tasks.Task.PredecessorLink link)
{
   BigInteger uid = link.getPredecessorUID();
   if (uid != null)
   {
      Task prevTask = m_projectFile.getTaskByUniqueID(Integer.valueOf(uid.intValue()));
      if (prevTask != null)
      {
         RelationType type;
         if (link.getType() != null)
         {
            type = RelationType.getInstance(link.getType().intValue());
         }
         else
         {
            type = RelationType.FINISH_START;
         }

         TimeUnit lagUnits = DatatypeConverter.parseDurationTimeUnits(link.getLagFormat());

         Duration lagDuration;
         int lag = NumberHelper.getInt(link.getLinkLag());
         if (lag == 0)
         {
            lagDuration = Duration.getInstance(0, lagUnits);
         }
         else
         {
            if (lagUnits == TimeUnit.PERCENT || lagUnits == TimeUnit.ELAPSED_PERCENT)
            {
               lagDuration = Duration.getInstance(lag, lagUnits);
            }
            else
            {
               lagDuration = Duration.convertUnits(lag / 10.0, TimeUnit.MINUTES, lagUnits, m_projectFile.getProjectProperties());
            }
         }

         Relation relation = currTask.addPredecessor(prevTask, type, lagDuration);
         m_eventManager.fireRelationReadEvent(relation);
      }
   }
}
 
Example 18
Source File: FastTrackReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Process task dependencies.
 */
private void processDependencies()
{
   Set<Task> tasksWithBars = new HashSet<>();
   FastTrackTable table = m_data.getTable(FastTrackTableType.ACTBARS);
   for (MapRow row : table)
   {
      Task task = m_project.getTaskByUniqueID(row.getInteger(ActBarField._ACTIVITY));
      if (task == null || tasksWithBars.contains(task))
      {
         continue;
      }
      tasksWithBars.add(task);

      String predecessors = row.getString(ActBarField.PREDECESSORS);
      if (predecessors == null || predecessors.isEmpty())
      {
         continue;
      }

      for (String predecessor : predecessors.split(", "))
      {
         Matcher matcher = RELATION_REGEX.matcher(predecessor);
         matcher.matches();

         Integer id = Integer.valueOf(matcher.group(1));
         RelationType type = RELATION_TYPE_MAP.getOrDefault(matcher.group(3), RelationType.FINISH_START);

         String sign = matcher.group(4);
         double lag = NumberHelper.getDouble(matcher.group(5));
         if ("-".equals(sign))
         {
            lag = -lag;
         }

         Task targetTask = m_project.getTaskByID(id);
         if (targetTask != null)
         {
            Duration lagDuration = Duration.getInstance(lag, m_data.getDurationTimeUnit());
            Relation relation = task.addPredecessor(targetTask, type, lagDuration);
            m_eventManager.fireRelationReadEvent(relation);
         }
      }
   }
}
 
Example 19
Source File: AstaReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Processes predecessor data.
 *
 * @param rows predecessor data
 * @param completedSections completed section data
 */
public void processPredecessors(List<Row> rows, List<Row> completedSections)
{
   Map<Integer, Integer> completedSectionMap = new HashMap<>();
   for (Row section : completedSections)
   {
      completedSectionMap.put(section.getInteger("TASK_COMPLETED_SECTIONID"), section.getInteger("TASK"));
   }

   for (Row row : rows)
   {
      Integer startTaskID = row.getInteger("START_TASK");
      Task startTask = m_project.getTaskByUniqueID(startTaskID);
      if (startTask == null)
      {
         startTaskID = completedSectionMap.get(startTaskID);
         if (startTaskID != null)
         {
            startTask = m_project.getTaskByUniqueID(startTaskID);
         }
      }

      Integer endTaskID = row.getInteger("END_TASK");
      Task endTask = m_project.getTaskByUniqueID(endTaskID);
      if (endTask == null)
      {
         endTaskID = completedSectionMap.get(endTaskID);
         if (endTaskID != null)
         {
            endTask = m_project.getTaskByUniqueID(endTaskID);
         }
      }

      if (startTask != null && endTask != null)
      {
         RelationType type = getRelationType(row.getInt("TYPI"));

         double startLag = row.getDuration("START_LAG_TIMEHOURS").getDuration();
         double endLag = row.getDuration("END_LAG_TIMEHOURS").getDuration();
         double totalLag = startLag - endLag;

         Relation relation = endTask.addPredecessor(startTask, type, Duration.getInstance(totalLag, TimeUnit.HOURS));
         relation.setUniqueID(row.getInteger("LINKID"));
      }

      //PROJID
      //LINKID
      //START_LAG_TIMETYPF
      //START_LAG_TIMEELA_MONTHS
      //START_LAG_TIMEHOURS
      //END_LAG_TIMETYPF
      //END_LAG_TIMEELA_MONTHS
      //END_LAG_TIMEHOURS
      //MAXIMUM_LAGTYPF
      //MAXIMUM_LAGELA_MONTHS
      //MAXIMUM_LAGHOURS
      //STARV_DATE
      //ENF_DATE
      //CURVATURE_PERCENTAGE
      //START_LAG_PERCENT_FLOAT
      //END_LAG_PERCENT_FLOAT
      //COMMENTS
      //LINK_CATEGORY
      //START_LAG_TIME_UNIT
      //END_LAG_TIME_UNIT
      //MAXIMUM_LAG_TIME_UNIT
      //START_TASK
      //END_TASK
      //TYPI
      //START_LAG_TYPE
      //END_LAG_TYPE
      //MAINTAIN_TASK_OFFSETS
      //UNSCHEDULABLF
      //CRITICAL
      //ON_LOOP
      //MAXIMUM_LAG_MODE
      //ANNOTATE_LEAD_LAG
      //START_REPOSITION_ON_TAS_MOVE
      //END_REPOSITION_ON_TASK_MOVE
      //DRAW_CURVED_IF_VERTICAL
      //AUTOMATIC_CURVED_LI_SETTINGS
      //DRAW_CURVED_LINK_TO_LEFT
      //LOCAL_LINK
      //DRIVING
      //ALT_ID
      //LAST_EDITED_DATE
      //LAST_EDITED_BY
   }
}
 
Example 20
Source File: MPXReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Creates and populates a new task relationship.
 *
 * @param field which task field source of data
 * @param sourceTask relationship source task
 * @param relationship relationship string
 * @throws MPXJException
 */
private void populateRelation(TaskField field, Task sourceTask, String relationship) throws MPXJException
{
   int index = 0;
   int length = relationship.length();

   //
   // Extract the identifier
   //
   while ((index < length) && (Character.isDigit(relationship.charAt(index)) == true))
   {
      ++index;
   }

   Integer taskID;
   try
   {
      taskID = Integer.valueOf(relationship.substring(0, index));
   }

   catch (NumberFormatException ex)
   {
      throw new MPXJException(MPXJException.INVALID_FORMAT + " '" + relationship + "'");
   }

   //
   // Now find the task, so we can extract the unique ID
   //
   Task targetTask;
   if (field == TaskField.PREDECESSORS)
   {
      targetTask = m_projectFile.getTaskByID(taskID);
   }
   else
   {
      targetTask = m_projectFile.getTaskByUniqueID(taskID);
   }

   //
   // If we haven't reached the end, we next expect to find
   // SF, SS, FS, FF
   //
   RelationType type = null;
   Duration lag = null;

   if (index == length)
   {
      type = RelationType.FINISH_START;
      lag = Duration.getInstance(0, TimeUnit.DAYS);
   }
   else
   {
      if ((index + 1) == length)
      {
         throw new MPXJException(MPXJException.INVALID_FORMAT + " '" + relationship + "'");
      }

      type = RelationTypeUtility.getInstance(m_locale, relationship.substring(index, index + 2));

      index += 2;

      if (index == length)
      {
         lag = Duration.getInstance(0, TimeUnit.DAYS);
      }
      else
      {
         if (relationship.charAt(index) == '+')
         {
            ++index;
         }

         lag = DurationUtility.getInstance(relationship.substring(index), m_formats.getDurationDecimalFormat(), m_locale);
      }
   }

   if (type == null)
   {
      throw new MPXJException(MPXJException.INVALID_FORMAT + " '" + relationship + "'");
   }

   // We have seen at least one example MPX file where an invalid task ID
   // is present. We'll ignore this as the schedule is otherwise valid.
   if (targetTask != null)
   {
      Relation relation = sourceTask.addPredecessor(targetTask, type, lag);
      m_eventManager.fireRelationReadEvent(relation);
   }
}