Java Code Examples for net.sf.mpxj.Duration#getUnits()

The following examples show how to use net.sf.mpxj.Duration#getUnits() . 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: RecurrenceUtility.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Convert an MPXJ Duration instance into an integer duration in minutes
 * ready to be written to an MPX file.
 *
 * @param properties project properties, used for duration units conversion
 * @param duration Duration instance
 * @return integer duration in minutes
 */
public static Integer getDurationValue(ProjectProperties properties, Duration duration)
{
   Integer result;
   if (duration == null)
   {
      result = null;
   }
   else
   {
      if (duration.getUnits() != TimeUnit.MINUTES)
      {
         duration = duration.convertUnits(TimeUnit.MINUTES, properties);
      }
      result = Integer.valueOf((int) duration.getDuration());
   }
   return (result);
}
 
Example 2
Source File: MppXmlCompare.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Duration equality assertion.
 *
 * @param expected expected value
 * @param actual actual value
 * @throws Exception
 */
private void assertEquals(Duration expected, Duration actual) throws Exception
{
   if (expected != null || actual != null)
   {
      if (expected != null && actual != null)
      {
         if (expected.getDuration() != 0 || actual.getDuration() != 0)
         {
            if (expected.getUnits() != actual.getUnits())
            {
               actual = actual.convertUnits(expected.getUnits(), m_mpp.getProjectProperties());
            }

            assertEquals(expected.getDuration(), actual.getDuration(), 0.99);
         }
      }
      else
      {
         if ((actual == null && expected != null && expected.getDuration() != 0) || (actual != null && actual.getDuration() != 0 && expected == null))
         {
            assertEquals((Object) expected, (Object) actual);
         }
      }
   }
}
 
Example 3
Source File: PrimaveraPMFileWriter.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Retrieve a duration in the form required by Primavera.
 *
 * @param duration Duration instance
 * @return formatted duration
 */
private Double getDuration(Duration duration)
{
   Double result;
   if (duration == null)
   {
      result = null;
   }
   else
   {
      if (duration.getUnits() != TimeUnit.HOURS)
      {
         duration = duration.convertUnits(TimeUnit.HOURS, m_projectFile.getProjectProperties());
      }

      result = Double.valueOf(duration.getDuration());
   }
   return result;
}
 
Example 4
Source File: MerlinReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Extract a duration amount from the assignment, converting a percentage
 * into an actual duration.
 *
 * @param task parent task
 * @param work duration from assignment
 * @return Duration instance
 */
private Duration assignmentDuration(Task task, Duration work)
{
   Duration result = work;

   if (result != null)
   {
      if (result.getUnits() == TimeUnit.PERCENT)
      {
         Duration taskWork = task.getWork();
         if (taskWork != null)
         {
            result = Duration.getInstance(taskWork.getDuration() * result.getDuration(), taskWork.getUnits());
         }
      }
   }
   return result;
}
 
Example 5
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Print duration.
 *
 * Note that Microsoft's xsd:duration parser implementation does not
 * appear to recognise durations other than those expressed in hours.
 * We use the compatibility flag to determine whether the output
 * is adjusted for the benefit of Microsoft Project.
 *
 * @param writer parent MSPDIWriter instance
 * @param duration Duration value
 * @return xsd:duration value
 */
public static final String printDurationMandatory(MSPDIWriter writer, Duration duration)
{
   String result;

   if (duration == null)
   {
      // SF-329: null default required to keep Powerproject happy when importing MSPDI files
      result = "PT0H0M0S";
   }
   else
   {
      TimeUnit durationType = duration.getUnits();

      if (durationType != TimeUnit.HOURS && durationType != TimeUnit.ELAPSED_HOURS)
      {
         duration = duration.convertUnits(TimeUnit.HOURS, writer.getProjectFile().getProjectProperties());
      }
      result = new XsdDuration(duration).print(writer.getMicrosoftProjectCompatibleOutput());
   }

   return (result);
}
 
Example 6
Source File: RecurrenceUtility.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Convert the integer representation of a duration value and duration units
 * into an MPXJ Duration instance.
 *
 * @param properties project properties, used for duration units conversion
 * @param durationValue integer duration value
 * @param unitsValue integer units value
 * @return Duration instance
 */
public static Duration getDuration(ProjectProperties properties, Integer durationValue, Integer unitsValue)
{
   Duration result;
   if (durationValue == null)
   {
      result = null;
   }
   else
   {
      result = Duration.getInstance(durationValue.intValue(), TimeUnit.MINUTES);
      TimeUnit units = getDurationUnits(unitsValue);
      if (result.getUnits() != units)
      {
         result = result.convertUnits(units, properties);
      }
   }
   return (result);
}
 
Example 7
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Parse duration represented as an arbitrary fraction of minutes.
 *
 * @param properties project properties
 * @param value duration value
 * @param targetTimeUnit required output time units
 * @param factor required fraction of a minute
 * @return Duration instance
 */
private static final Duration parseDurationInFractionsOfMinutes(ProjectProperties properties, Number value, TimeUnit targetTimeUnit, int factor)
{
   Duration result = null;

   if (value != null)
   {
      result = Duration.getInstance(value.intValue() / factor, TimeUnit.MINUTES);
      if (targetTimeUnit != result.getUnits())
      {
         result = result.convertUnits(targetTimeUnit, properties);
      }
   }

   return (result);
}
 
Example 8
Source File: MSPDIWriter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method writes a single predecessor link to the MSPDI file.
 *
 * @param taskID The task UID
 * @param type The predecessor type
 * @param lag The lag duration
 * @return A new link to be added to the MSPDI file
 */
private Project.Tasks.Task.PredecessorLink writePredecessor(Integer taskID, RelationType type, Duration lag)
{
   Project.Tasks.Task.PredecessorLink link = m_factory.createProjectTasksTaskPredecessorLink();

   link.setPredecessorUID(NumberHelper.getBigInteger(taskID));
   link.setType(BigInteger.valueOf(type.getValue()));
   link.setCrossProject(Boolean.FALSE); // SF-300: required to keep P6 happy when importing MSPDI files

   if (lag != null && lag.getDuration() != 0)
   {
      double linkLag = lag.getDuration();
      if (lag.getUnits() != TimeUnit.PERCENT && lag.getUnits() != TimeUnit.ELAPSED_PERCENT)
      {
         linkLag = 10.0 * Duration.convertUnits(linkLag, lag.getUnits(), TimeUnit.MINUTES, m_projectFile.getProjectProperties()).getDuration();
      }
      link.setLinkLag(BigInteger.valueOf((long) linkLag));
      link.setLagFormat(DatatypeConverter.printDurationTimeUnits(lag.getUnits(), false));
   }
   else
   {
      // SF-329: default required to keep Powerproject happy when importing MSPDI files
      link.setLinkLag(BIGINTEGER_ZERO);
      link.setLagFormat(DatatypeConverter.printDurationTimeUnits(m_projectFile.getProjectProperties().getDefaultDurationUnits(), false));
   }

   return (link);
}
 
Example 9
Source File: SDEFWriter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Write each predecessor for a task.
 *
 * @param record Task instance
 */
private void writeTaskPredecessors(Task record)
{
   m_buffer.setLength(0);
   //
   // Write the task predecessor
   //
   if (!record.getSummary() && !record.getPredecessors().isEmpty())
   { // I don't use summary tasks for SDEF
      m_buffer.append("PRED ");
      List<Relation> predecessors = record.getPredecessors();

      for (Relation pred : predecessors)
      {
         m_buffer.append(SDEFmethods.rset(pred.getSourceTask().getUniqueID().toString(), 10) + " ");
         m_buffer.append(SDEFmethods.rset(pred.getTargetTask().getUniqueID().toString(), 10) + " ");
         String type = "C"; // default finish-to-start
         if (!pred.getType().toString().equals("FS"))
         {
            type = pred.getType().toString().substring(0, 1);
         }
         m_buffer.append(type + " ");

         Duration dd = pred.getLag();
         double duration = dd.getDuration();
         if (dd.getUnits() != TimeUnit.DAYS)
         {
            dd = Duration.convertUnits(duration, dd.getUnits(), TimeUnit.DAYS, m_minutesPerDay, m_minutesPerWeek, m_daysPerMonth);
         }
         Double days = Double.valueOf(dd.getDuration() + 0.5); // Add 0.5 so half day rounds up upon truncation
         Integer est = Integer.valueOf(days.intValue());
         m_buffer.append(SDEFmethods.rset(est.toString(), 4) + " "); // task duration in days required by USACE
      }
      m_writer.println(m_buffer.toString());
   }
}
 
Example 10
Source File: XsdDuration.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This constructor allows an xsd:duration to be created from
 * an MPX duration.
 *
 * @param duration An MPX duration.
 */
XsdDuration(Duration duration)
{
   if (duration != null)
   {
      double amount = duration.getDuration();

      if (amount != 0)
      {
         switch (duration.getUnits())
         {
            case MINUTES:
            case ELAPSED_MINUTES:
            {
               m_minutes = (int) amount;
               m_seconds = (amount * 60) - (m_minutes * 60);
               break;
            }

            case HOURS:
            case ELAPSED_HOURS:
            {
               m_hours = (int) amount;
               amount = (amount * 60) - (m_hours * 60);
               m_minutes = (int) amount;
               m_seconds = (amount * 60) - (m_minutes * 60);
               break;
            }

            case DAYS:
            case ELAPSED_DAYS:
            {
               m_days = (int) amount;
               amount = (amount * 24) - (m_days * 24);
               m_hours = (int) amount;
               amount = (amount * 60) - (m_hours * 60);
               m_minutes = (int) amount;
               m_seconds = (amount * 60) - (m_minutes * 60);
               break;
            }

            case WEEKS:
            case ELAPSED_WEEKS:
            {
               amount *= 7;
               m_days = (int) amount;
               amount = (amount * 24) - (m_days * 24);
               m_hours = (int) amount;
               amount = (amount * 60) - (m_hours * 60);
               m_minutes = (int) amount;
               m_seconds = (amount * 60) - (m_minutes * 60);
               break;
            }

            case MONTHS:
            case ELAPSED_MONTHS:
            {
               m_months = (int) amount;
               amount = (amount * 28) - (m_months * 28);
               m_days = (int) amount;
               amount = (amount * 24) - (m_days * 24);
               m_hours = (int) amount;
               amount = (amount * 60) - (m_hours * 60);
               m_minutes = (int) amount;
               m_seconds = (amount * 60) - (m_minutes * 60);
               break;
            }

            case YEARS:
            case ELAPSED_YEARS:
            {
               m_years = (int) amount;
               amount = (amount * 12) - (m_years * 12);
               m_months = (int) amount;
               amount = (amount * 28) - (m_months * 28);
               m_days = (int) amount;
               amount = (amount * 24) - (m_days * 24);
               m_hours = (int) amount;
               amount = (amount * 60) - (m_hours * 60);
               m_minutes = (int) amount;
               m_seconds = (amount * 60) - (m_minutes * 60);
               break;
            }

            default:
            {
               break;
            }
         }
      }
   }
}
 
Example 11
Source File: MSPDIWriter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method writes assignment data to an MSPDI file.
 *
 * @param project Root node of the MSPDI file
 */
private void writeAssignments(Project project)
{
   Project.Assignments assignments = m_factory.createProjectAssignments();
   project.setAssignments(assignments);
   List<Project.Assignments.Assignment> list = assignments.getAssignment();

   for (ResourceAssignment assignment : m_projectFile.getResourceAssignments())
   {
      list.add(writeAssignment(assignment));
   }

   //
   // Check to see if we have any tasks that have a percent complete value
   // but do not have resource assignments. If any exist, then we must
   // write a dummy resource assignment record to ensure that the MSPDI
   // file shows the correct percent complete amount for the task.
   //
   ProjectConfig config = m_projectFile.getProjectConfig();
   boolean autoUniqueID = config.getAutoAssignmentUniqueID();
   if (!autoUniqueID)
   {
      config.setAutoAssignmentUniqueID(true);
   }

   for (Task task : m_projectFile.getTasks())
   {
      double percentComplete = NumberHelper.getDouble(task.getPercentageComplete());
      if (percentComplete != 0 && task.getResourceAssignments().isEmpty() == true)
      {
         ResourceAssignment dummy = new ResourceAssignment(m_projectFile, task);
         Duration duration = task.getDuration();
         if (duration == null)
         {
            duration = Duration.getInstance(0, TimeUnit.HOURS);
         }
         double durationValue = duration.getDuration();
         TimeUnit durationUnits = duration.getUnits();
         double actualWork = (durationValue * percentComplete) / 100;
         double remainingWork = durationValue - actualWork;

         dummy.setResourceUniqueID(NULL_RESOURCE_ID);
         dummy.setWork(duration);
         dummy.setActualWork(Duration.getInstance(actualWork, durationUnits));
         dummy.setRemainingWork(Duration.getInstance(remainingWork, durationUnits));

         // Without this, MS Project will mark a 100% complete milestone as 99% complete
         if (percentComplete == 100 && duration.getDuration() == 0)
         {
            dummy.setActualFinish(task.getActualStart());
         }

         list.add(writeAssignment(dummy));
      }
   }

   config.setAutoAssignmentUniqueID(autoUniqueID);
}
 
Example 12
Source File: MPXReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Populate a resource assignment.
 *
 * @param record MPX record
 * @param assignment resource assignment
 * @throws MPXJException
 */
private void populateResourceAssignment(Record record, ResourceAssignment assignment) throws MPXJException
{
   //
   // Handle malformed MPX files - ensure that we can locate the resource
   // using either the Unique ID attribute or the ID attribute.
   //
   Resource resource = m_projectFile.getResourceByUniqueID(record.getInteger(12));
   if (resource == null)
   {
      resource = m_projectFile.getResourceByID(record.getInteger(0));
   }

   assignment.setUnits(record.getUnits(1));
   assignment.setWork(record.getDuration(2));
   assignment.setBaselineWork(record.getDuration(3));
   assignment.setActualWork(record.getDuration(4));
   assignment.setOvertimeWork(record.getDuration(5));
   assignment.setCost(record.getCurrency(6));
   assignment.setBaselineCost(record.getCurrency(7));
   assignment.setActualCost(record.getCurrency(8));
   assignment.setStart(record.getDateTime(9));
   assignment.setFinish(record.getDateTime(10));
   assignment.setDelay(record.getDuration(11));

   //
   // Calculate the remaining work
   //
   Duration work = assignment.getWork();
   Duration actualWork = assignment.getActualWork();
   if (work != null && actualWork != null)
   {
      if (work.getUnits() != actualWork.getUnits())
      {
         actualWork = actualWork.convertUnits(work.getUnits(), m_projectFile.getProjectProperties());
      }

      assignment.setRemainingWork(Duration.getInstance(work.getDuration() - actualWork.getDuration(), work.getUnits()));
   }

   if (resource != null)
   {
      assignment.setResourceUniqueID(resource.getUniqueID());
      resource.addResourceAssignment(assignment);
   }

   m_eventManager.fireAssignmentReadEvent(assignment);
}
 
Example 13
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Print a duration represented by an arbitrary fraction of minutes.
 *
 * @param duration Duration instance
 * @param factor required factor
 * @return duration represented as an arbitrary fraction of minutes
 */
private static final double printDurationFractionsOfMinutes(Duration duration, int factor)
{
   double result = 0;

   if (duration != null)
   {
      result = duration.getDuration();

      switch (duration.getUnits())
      {
         case HOURS:
         case ELAPSED_HOURS:
         {
            result *= 60;
            break;
         }

         case DAYS:
         {
            result *= (60 * 8);
            break;
         }

         case ELAPSED_DAYS:
         {
            result *= (60 * 24);
            break;
         }

         case WEEKS:
         {
            result *= (60 * 8 * 5);
            break;
         }

         case ELAPSED_WEEKS:
         {
            result *= (60 * 24 * 7);
            break;
         }

         case MONTHS:
         {
            result *= (60 * 8 * 5 * 4);
            break;
         }

         case ELAPSED_MONTHS:
         {
            result *= (60 * 24 * 30);
            break;
         }

         case YEARS:
         {
            result *= (60 * 8 * 5 * 52);
            break;
         }

         case ELAPSED_YEARS:
         {
            result *= (60 * 24 * 365);
            break;
         }

         default:
         {
            break;
         }
      }
   }

   result *= factor;

   return (result);
}
 
Example 14
Source File: SDEFWriter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Write a task.
 *
 * @param record task instance
 * @throws IOException
 */
private void writeTask(Task record) throws IOException
{
   m_buffer.setLength(0);
   if (!record.getSummary())
   {
      m_buffer.append("ACTV ");
      m_buffer.append(SDEFmethods.rset(record.getUniqueID().toString(), 10) + " ");
      m_buffer.append(SDEFmethods.lset(record.getName(), 30) + " ");

      // Following just makes certain we have days for duration, as per USACE spec.
      Duration dd = record.getDuration();
      double duration = dd.getDuration();
      if (dd.getUnits() != TimeUnit.DAYS)
      {
         dd = Duration.convertUnits(duration, dd.getUnits(), TimeUnit.DAYS, m_minutesPerDay, m_minutesPerWeek, m_daysPerMonth);
      }
      Double days = Double.valueOf(dd.getDuration() + 0.5); // Add 0.5 so half day rounds up upon truncation
      Integer est = Integer.valueOf(days.intValue());
      m_buffer.append(SDEFmethods.rset(est.toString(), 3) + " "); // task duration in days required by USACE

      String conType = "ES "; // assume early start
      Date conDate = record.getEarlyStart();
      int test = record.getConstraintType().getValue(); // test for other types
      if (test == 1 || test == 3 || test == 6 || test == 7 || test == 9)
      {
         conType = "LF "; // see ConstraintType enum for definitions
         conDate = record.getLateFinish();
      }
      m_buffer.append(m_formatter.format(conDate).toUpperCase() + " "); // Constraint Date
      m_buffer.append(conType); // Constraint Type
      if (record.getCalendar() == null)
      {
         m_buffer.append("1 ");
      }
      else
      {
         m_buffer.append(SDEFmethods.lset(record.getCalendar().getUniqueID().toString(), 1) + " ");
      }
      // skipping hammock code in here
      // use of text fields for extra USACE data is suggested at my web site: www.geocomputer.com
      // not documented on how to do this here, so I need to comment out at present
      //	      m_buffer.append(SDEFmethods.Lset(record.getText1(), 3) + " ");
      //	      m_buffer.append(SDEFmethods.Lset(record.getText2(), 4) + " ");
      //	      m_buffer.append(SDEFmethods.Lset(record.getText3(), 4) + " ");
      //	      m_buffer.append(SDEFmethods.Lset(record.getText4(), 6) + " ");
      //	      m_buffer.append(SDEFmethods.Lset(record.getText5(), 6) + " ");
      //	      m_buffer.append(SDEFmethods.Lset(record.getText6(), 2) + " ");
      //	      m_buffer.append(SDEFmethods.Lset(record.getText7(), 1) + " ");
      //	      m_buffer.append(SDEFmethods.Lset(record.getText8(), 30) + " ");
      m_writer.println(m_buffer.toString());
      m_eventManager.fireTaskWrittenEvent(record);
   }
}
 
Example 15
Source File: SDEFWriter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Writes a progress line to the SDEF file.
 *
 * Progress lines in SDEF are a little tricky, you need to assume a percent complete
 * this could be physical or temporal, I don't know what you're using???
 * So in this version of SDEFwriter, I just put in 0.00 for cost progress to date, see *** below
 *
 * @param record Task instance
 */
private void writePROG(Task record)
{
   m_buffer.setLength(0);
   //
   // Write the progress record
   //
   if (!record.getSummary())
   { // I don't use summary tasks for SDEF
      m_buffer.append("PROG ");
      m_buffer.append(SDEFmethods.rset(record.getUniqueID().toString(), 10) + " ");
      Date temp = record.getActualStart();
      if (temp == null)
      {
         m_buffer.append("        "); // SDEf is column sensitive, so the number of blanks here is crucial
      }
      else
      {
         m_buffer.append(m_formatter.format(record.getActualStart()).toUpperCase() + " "); // ACTUAL START DATE
      }
      temp = record.getActualFinish();
      if (temp == null)
      {
         m_buffer.append("        ");
      }
      else
      {
         m_buffer.append(m_formatter.format(record.getActualFinish()).toUpperCase() + " "); // ACTUAL FINISH DATE
      }

      Duration dd = record.getRemainingDuration();
      double duration = dd.getDuration();
      if (dd.getUnits() != TimeUnit.DAYS)
      {
         dd = Duration.convertUnits(duration, dd.getUnits(), TimeUnit.DAYS, m_minutesPerDay, m_minutesPerWeek, m_daysPerMonth);
      }
      Double days = Double.valueOf(dd.getDuration() + 0.5); // Add 0.5 so half day rounds up upon truncation
      Integer est = Integer.valueOf(days.intValue());
      m_buffer.append(SDEFmethods.rset(est.toString(), 3) + " "); // task duration in days required by USACE

      DecimalFormat twoDec = new DecimalFormat("#0.00"); // USACE required currency format
      m_buffer.append(SDEFmethods.rset(twoDec.format(record.getCost().floatValue()), 12) + " ");
      m_buffer.append(SDEFmethods.rset(twoDec.format(0.00), 12) + " "); // *** assume zero progress on cost
      m_buffer.append(SDEFmethods.rset(twoDec.format(0.00), 12) + " "); // *** assume zero progress on cost
      m_buffer.append(m_formatter.format(record.getEarlyStart()).toUpperCase() + " ");
      m_buffer.append(m_formatter.format(record.getEarlyFinish()).toUpperCase() + " ");
      m_buffer.append(m_formatter.format(record.getLateStart()).toUpperCase() + " ");
      m_buffer.append(m_formatter.format(record.getLateFinish()).toUpperCase() + " ");

      dd = record.getTotalSlack();
      duration = dd.getDuration();
      if (dd.getUnits() != TimeUnit.DAYS)
      {
         dd = Duration.convertUnits(duration, dd.getUnits(), TimeUnit.DAYS, m_minutesPerDay, m_minutesPerWeek, m_daysPerMonth);
      }
      days = Double.valueOf(dd.getDuration() + 0.5); // Add 0.5 so half day rounds up upon truncation
      est = Integer.valueOf(days.intValue());
      char slack;
      if (est.intValue() >= 0)
      {
         slack = '+'; // USACE likes positive slack, so they separate the sign from the value
      }
      else
      {
         slack = '-'; // only write a negative when it's negative, i.e. can't be done in project management terms!!!
      }
      m_buffer.append(slack + " ");
      est = Integer.valueOf(Math.abs(days.intValue()));
      m_buffer.append(SDEFmethods.rset(est.toString(), 4)); // task duration in days required by USACE
      m_writer.println(m_buffer.toString());
      m_eventManager.fireTaskWrittenEvent(record);
   }
}
 
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: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Print duration time units.
 *
 * @param duration Duration value
 * @param estimated is this an estimated duration
 * @return time units value
 */
public static final BigInteger printDurationTimeUnits(Duration duration, boolean estimated)
{
   // SF-329: null default required to keep Powerproject happy when importing MSPDI files
   TimeUnit units = duration == null ? PARENT_FILE.get().getProjectProperties().getDefaultDurationUnits() : duration.getUnits();
   return printDurationTimeUnits(units, estimated);
}