Java Code Examples for net.sf.mpxj.TimeUnit#DAYS

The following examples show how to use net.sf.mpxj.TimeUnit#DAYS . 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: ProjectFileImporter.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
private void importResources(ProjectFile pf, Map<Integer, HumanResource> foreignId2humanResource) {
  myResourceCustomPropertyMapping = new HashMap<ResourceField, CustomPropertyDefinition>();
  for (Resource r : pf.getAllResources()) {
    HumanResource nativeResource = myNativeProject.getHumanResourceManager().newHumanResource();
    nativeResource.setId(r.getUniqueID());
    nativeResource.setName(r.getName());
    nativeResource.setMail(r.getEmailAddress());
    Rate standardRate = r.getStandardRate();
    if (standardRate != null && standardRate.getAmount() != 0.0 && r.getStandardRateUnits() == TimeUnit.DAYS) {
      nativeResource.setStandardPayRate(new BigDecimal(standardRate.getAmount()));
    }
    myNativeProject.getHumanResourceManager().add(nativeResource);
    importDaysOff(r, nativeResource);
    importCustomProperties(r, nativeResource);
    foreignId2humanResource.put(r.getUniqueID(), nativeResource);
  }
}
 
Example 2
Source File: RecurrenceUtility.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Maps a duration unit value from a recurring task record in an MPX file
 * to a TimeUnit instance. Defaults to days if any problems are encountered.
 *
 * @param value integer duration units value
 * @return TimeUnit instance
 */
private static TimeUnit getDurationUnits(Integer value)
{
   TimeUnit result = null;

   if (value != null)
   {
      int index = value.intValue();
      if (index >= 0 && index < DURATION_UNITS.length)
      {
         result = DURATION_UNITS[index];
      }
   }

   if (result == null)
   {
      result = TimeUnit.DAYS;
   }

   return (result);
}
 
Example 3
Source File: Record.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Accessor method used to retrieve an Integer object representing the
 * contents of an individual field. If the field does not exist in the
 * record, null is returned.
 *
 * @param field the index number of the field to be retrieved
 * @return the value of the required field
 */
public TimeUnit getTimeUnit(int field)
{
   TimeUnit result;

   if ((field < m_fields.length) && (m_fields[field].length() != 0))
   {
      result = TimeUnit.getInstance(Integer.parseInt(m_fields[field]));
   }
   else
   {
      result = TimeUnit.DAYS;
   }

   return (result);
}
 
Example 4
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 5
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Parse work units.
 *
 * @param value work units value
 * @return TimeUnit instance
 */
public static final TimeUnit parseWorkUnits(BigInteger value)
{
   TimeUnit result = TimeUnit.HOURS;

   if (value != null)
   {
      switch (value.intValue())
      {
         case 1:
         {
            result = TimeUnit.MINUTES;
            break;
         }

         case 3:
         {
            result = TimeUnit.DAYS;
            break;
         }

         case 4:
         {
            result = TimeUnit.WEEKS;
            break;
         }

         case 5:
         {
            result = TimeUnit.MONTHS;
            break;
         }

         case 7:
         {
            result = TimeUnit.YEARS;
            break;
         }

         default:
         case 2:
         {
            result = TimeUnit.HOURS;
            break;
         }
      }
   }

   return (result);
}
 
Example 6
Source File: DurationUtility.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Retrieve an Duration instance. Use shared objects to
 * represent common values for memory efficiency.
 *
 * @param dur duration formatted as a string
 * @param format number format
 * @param locale target locale
 * @return Duration instance
 * @throws MPXJException
 */
public static Duration getInstance(String dur, NumberFormat format, Locale locale) throws MPXJException
{
   try
   {
      int lastIndex = dur.length() - 1;
      int index = lastIndex;
      double duration;
      TimeUnit units;

      while ((index > 0) && (Character.isDigit(dur.charAt(index)) == false))
      {
         --index;
      }

      //
      // If we have no units suffix, assume days to allow for MPX3
      //
      if (index == lastIndex)
      {
         duration = format.parse(dur).doubleValue();
         units = TimeUnit.DAYS;
      }
      else
      {
         ++index;
         duration = format.parse(dur.substring(0, index)).doubleValue();
         while ((index < lastIndex) && (Character.isWhitespace(dur.charAt(index))))
         {
            ++index;
         }
         units = TimeUnitUtility.getInstance(dur.substring(index), locale);
      }

      return (Duration.getInstance(duration, units));
   }

   catch (ParseException ex)
   {
      throw new MPXJException("Failed to parse duration", ex);
   }
}
 
Example 7
Source File: FastTrackUtility.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Convert an integer value into a TimeUnit instance.
 *
 * @param value time unit value
 * @return TimeUnit instance
 */
public static final TimeUnit getTimeUnit(int value)
{
   TimeUnit result = null;

   switch (value)
   {
      case 1:
      {
         // Appears to mean "use the document format"
         result = TimeUnit.ELAPSED_DAYS;
         break;
      }

      case 2:
      {
         result = TimeUnit.HOURS;
         break;
      }

      case 4:
      {
         result = TimeUnit.DAYS;
         break;
      }

      case 6:
      {
         result = TimeUnit.WEEKS;
         break;
      }

      case 8:
      case 10:
      {
         result = TimeUnit.MONTHS;
         break;
      }

      case 12:
      {
         result = TimeUnit.YEARS;
         break;
      }

      default:
      {
         break;
      }
   }

   return result;
}
 
Example 8
Source File: MapRow.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Convert the string representation of a duration to a Duration instance.
 *
 * @param value string representation of a duration
 * @return Duration instance
 */
private Duration parseDuration(String value)
{
   //
   // Let's assume that we always receive well-formed values.
   //
   int unitsLength = 1;
   char unitsChar = value.charAt(value.length() - unitsLength);

   //
   // Handle an estimated duration
   //
   if (unitsChar == '?')
   {
      unitsLength = 2;
      unitsChar = value.charAt(value.length() - unitsLength);
   }

   double durationValue = Double.parseDouble(value.substring(0, value.length() - unitsLength));

   //
   // Note that we don't handle 'u' the material type here
   //
   TimeUnit durationUnits;
   switch (unitsChar)
   {
      case 's':
      {
         durationUnits = TimeUnit.MINUTES;
         durationValue /= 60;
         break;
      }

      case 'm':
      {
         durationUnits = TimeUnit.MINUTES;
         break;
      }

      case 'h':
      {
         durationUnits = TimeUnit.HOURS;
         break;
      }

      case 'w':
      {
         durationUnits = TimeUnit.WEEKS;
         break;
      }

      case 'M':
      {
         durationUnits = TimeUnit.MONTHS;
         break;
      }

      case 'q':
      {
         durationUnits = TimeUnit.MONTHS;
         durationValue *= 3;
         break;
      }

      case 'y':
      {
         durationUnits = TimeUnit.YEARS;
         break;
      }

      case 'f':
      {
         durationUnits = TimeUnit.PERCENT;
         break;
      }

      case 'd':
      default:
      {
         durationUnits = TimeUnit.DAYS;
         break;
      }
   }

   return Duration.getInstance(durationValue, durationUnits);
}
 
Example 9
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 10
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 11
Source File: MPDUtility.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method converts between the duration units representation
 * used in the MPP file, and the standard MPX duration units.
 * If the supplied units are unrecognised, the units default to days.
 *
 * @param type MPP units
 * @return MPX units
 */
public static final TimeUnit getDurationTimeUnits(int type)
{
   TimeUnit units;

   switch (type & DURATION_UNITS_MASK)
   {
      case 3:
      {
         units = TimeUnit.MINUTES;
         break;
      }

      case 4:
      {
         units = TimeUnit.ELAPSED_MINUTES;
         break;
      }

      case 5:
      {
         units = TimeUnit.HOURS;
         break;
      }

      case 6:
      {
         units = TimeUnit.ELAPSED_HOURS;
         break;
      }

      case 8:
      {
         units = TimeUnit.ELAPSED_DAYS;
         break;
      }

      case 9:
      {
         units = TimeUnit.WEEKS;
         break;
      }

      case 10:
      {
         units = TimeUnit.ELAPSED_WEEKS;
         break;
      }

      case 11:
      {
         units = TimeUnit.MONTHS;
         break;
      }

      case 12:
      {
         units = TimeUnit.ELAPSED_MONTHS;
         break;
      }

      default:
      case 7:
      {
         units = TimeUnit.DAYS;
         break;
      }
   }

   return (units);
}
 
Example 12
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 13
Source File: FastTrackData.java    From mpxj with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Retrieve the time units used for durations in this FastTrack file.
 *
 * @return TimeUnit instance
 */
TimeUnit getDurationTimeUnit()
{
   return m_durationTimeUnit == null ? TimeUnit.DAYS : m_durationTimeUnit;
}