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

The following examples show how to use net.sf.mpxj.TimeUnit#HOURS . 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: 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 2
Source File: PhoenixReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method extracts data for a single resource from a Phoenix file.
 *
 * @param phoenixResource resource data
 * @return Resource instance
 */
private Resource readResource(net.sf.mpxj.phoenix.schema.Project.Storepoints.Storepoint.Resources.Resource phoenixResource)
{
   Resource mpxjResource = m_projectFile.addResource();

   TimeUnit rateUnits = phoenixResource.getMonetarybase();
   if (rateUnits == null)
   {
      rateUnits = TimeUnit.HOURS;
   }

   // phoenixResource.getMaximum()
   mpxjResource.setCostPerUse(phoenixResource.getMonetarycostperuse());
   mpxjResource.setStandardRate(new Rate(phoenixResource.getMonetaryrate(), rateUnits));
   mpxjResource.setStandardRateUnits(rateUnits);
   mpxjResource.setName(phoenixResource.getName());
   mpxjResource.setType(phoenixResource.getType());
   mpxjResource.setMaterialLabel(phoenixResource.getUnitslabel());
   //phoenixResource.getUnitsperbase()
   mpxjResource.setGUID(phoenixResource.getUuid());

   m_eventManager.fireResourceReadEvent(mpxjResource);

   return mpxjResource;
}
 
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: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Parse rate.
 *
 * @param value rate value
 * @return Rate instance
 */
public static final Rate parseRate(BigDecimal value)
{
   Rate result = null;

   if (value != null)
   {
      result = new Rate(value, TimeUnit.HOURS);
   }

   return (result);
}
 
Example 5
Source File: Record.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Accessor method used to retrieve an Rate 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
 * @throws MPXJException normally thrown when parsing fails
 */
public Rate getRate(int field) throws MPXJException
{
   Rate result;

   if ((field < m_fields.length) && (m_fields[field].length() != 0))
   {
      try
      {
         String rate = m_fields[field];
         int index = rate.indexOf('/');
         double amount;
         TimeUnit units;

         if (index == -1)
         {
            amount = m_formats.getCurrencyFormat().parse(rate).doubleValue();
            units = TimeUnit.HOURS;
         }
         else
         {
            amount = m_formats.getCurrencyFormat().parse(rate.substring(0, index)).doubleValue();
            units = TimeUnitUtility.getInstance(rate.substring(index + 1), m_locale);
         }

         result = new Rate(amount, units);
      }

      catch (ParseException ex)
      {
         throw new MPXJException("Failed to parse rate", ex);
      }
   }
   else
   {
      result = null;
   }

   return (result);
}
 
Example 6
Source File: CostRateTableFactory.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Converts an integer into a time format.
 *
 * @param format integer format value
 * @return TimeUnit instance
 */
private TimeUnit getFormat(int format)
{
   TimeUnit result;
   if (format == 0xFFFF)
   {
      result = TimeUnit.HOURS;
   }
   else
   {
      result = MPPUtility.getWorkTimeUnits(format);
   }
   return result;
}
 
Example 7
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 8
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Print work units.
 *
 * @param value TimeUnit instance
 * @return work units value
 */
public static final BigInteger printWorkUnits(TimeUnit value)
{
   int result;

   if (value == null)
   {
      value = TimeUnit.HOURS;
   }

   switch (value)
   {
      case MINUTES:
      {
         result = 1;
         break;
      }

      case DAYS:
      {
         result = 3;
         break;
      }

      case WEEKS:
      {
         result = 4;
         break;
      }

      case MONTHS:
      {
         result = 5;
         break;
      }

      case YEARS:
      {
         result = 7;
         break;
      }

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

   return (BigInteger.valueOf(result));
}
 
Example 9
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Print duration time units.
 *
 * Note that we don't differentiate between confirmed and unconfirmed
 * durations. Unrecognised duration types are default to hours.
 *
 * @param value Duration units
 * @param estimated is this an estimated duration
 * @return BigInteger value
 */
public static final BigInteger printDurationTimeUnits(TimeUnit value, boolean estimated)
{
   int result;

   if (value == null)
   {
      value = TimeUnit.HOURS;
   }

   switch (value)
   {
      case MINUTES:
      {
         result = (estimated ? 35 : 3);
         break;
      }

      case ELAPSED_MINUTES:
      {
         result = (estimated ? 36 : 4);
         break;
      }

      case ELAPSED_HOURS:
      {
         result = (estimated ? 38 : 6);
         break;
      }

      case DAYS:
      {
         result = (estimated ? 39 : 7);
         break;
      }

      case ELAPSED_DAYS:
      {
         result = (estimated ? 40 : 8);
         break;
      }

      case WEEKS:
      {
         result = (estimated ? 41 : 9);
         break;
      }

      case ELAPSED_WEEKS:
      {
         result = (estimated ? 42 : 10);
         break;
      }

      case MONTHS:
      {
         result = (estimated ? 43 : 11);
         break;
      }

      case ELAPSED_MONTHS:
      {
         result = (estimated ? 44 : 12);
         break;
      }

      case PERCENT:
      {
         result = (estimated ? 51 : 19);
         break;
      }

      case ELAPSED_PERCENT:
      {
         result = (estimated ? 52 : 20);
         break;
      }

      default:
      case HOURS:
      {
         result = (estimated ? 37 : 5);
         break;
      }
   }

   return (BigInteger.valueOf(result));
}
 
Example 10
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 11
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 12
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 13
Source File: PrimaveraReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Process resource rates.
 *
 * @param rows resource rate data
 */
public void processResourceRates(List<Row> rows)
{
   // Primavera defines resource cost tables by start dates so sort and define end by next
   Collections.sort(rows, new Comparator<Row>()
   {
      @Override public int compare(Row r1, Row r2)
      {
         Integer id1 = r1.getInteger("rsrc_id");
         Integer id2 = r2.getInteger("rsrc_id");
         int cmp = NumberHelper.compare(id1, id2);
         if (cmp != 0)
         {
            return cmp;
         }
         Date d1 = r1.getDate("start_date");
         Date d2 = r2.getDate("start_date");
         return DateHelper.compare(d1, d2);
      }
   });

   for (int i = 0; i < rows.size(); ++i)
   {
      Row row = rows.get(i);

      Integer resourceID = row.getInteger("rsrc_id");
      Rate standardRate = new Rate(row.getDouble("cost_per_qty"), TimeUnit.HOURS);
      TimeUnit standardRateFormat = TimeUnit.HOURS;
      Rate overtimeRate = new Rate(0, TimeUnit.HOURS); // does this exist in Primavera?
      TimeUnit overtimeRateFormat = TimeUnit.HOURS;
      Double costPerUse = NumberHelper.getDouble(0.0);
      Double maxUnits = NumberHelper.getDouble(NumberHelper.getDouble(row.getDouble("max_qty_per_hr")) * 100); // adjust to be % as in MS Project
      Date startDate = row.getDate("start_date");
      Date endDate = DateHelper.LAST_DATE;

      if (i + 1 < rows.size())
      {
         Row nextRow = rows.get(i + 1);
         int nextResourceID = nextRow.getInt("rsrc_id");
         if (resourceID.intValue() == nextResourceID)
         {
            endDate = nextRow.getDate("start_date");
         }
      }

      Resource resource = m_project.getResourceByUniqueID(resourceID);
      if (resource != null)
      {
         CostRateTable costRateTable = resource.getCostRateTable(0);
         if (costRateTable == null)
         {
            costRateTable = new CostRateTable();
            resource.setCostRateTable(0, costRateTable);
         }
         CostRateTableEntry entry = new CostRateTableEntry(standardRate, standardRateFormat, overtimeRate, overtimeRateFormat, costPerUse, endDate);
         costRateTable.add(entry);

         AvailabilityTable availabilityTable = resource.getAvailability();
         Availability newAvailability = new Availability(startDate, endDate, maxUnits);
         availabilityTable.add(newAvailability);
      }
   }
}
 
Example 14
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 15
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 work in this FastTrack file.
 *
 * @return TimeUnit instance
 */
TimeUnit getWorkTimeUnit()
{
   return m_workTimeUnit == null ? TimeUnit.HOURS : m_workTimeUnit;
}