Java Code Examples for net.sf.mpxj.TimeUnit

The following examples show how to use net.sf.mpxj.TimeUnit. These examples are extracted from open source projects. 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
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
private void exportResource(HumanResource hr, Map<Integer, Resource> id2mpxjResource,
    Map<CustomPropertyDefinition, FieldType> customProperty_fieldType) throws MPXJException {
  final Resource mpxjResource = myOutputProject.addResource();
  mpxjResource.setUniqueID(hr.getId()  + 1);
  mpxjResource.setID(id2mpxjResource.size() + 1);
  mpxjResource.setName(hr.getName());
  mpxjResource.setEmailAddress(hr.getMail());
  mpxjResource.setType(ResourceType.WORK);
  mpxjResource.setCanLevel(false);
  if (hr.getStandardPayRate() != BigDecimal.ZERO) {
    mpxjResource.setStandardRate(new Rate(hr.getStandardPayRate(), TimeUnit.DAYS));
  }

  exportDaysOff(hr, mpxjResource);
  exportCustomProperties
      (hr, customProperty_fieldType, new CustomPropertySetter() {
    @Override
    public void set(FieldType ft, Object value) {
      mpxjResource.set(ft, value);
    }
  });
  id2mpxjResource.put(hr.getId(), mpxjResource);
}
 
Example 3
/**
 * 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 4
Source Project: mpxj   Source File: MSPDIReader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Reads baseline values for the current resource.
 *
 * @param xmlResource MSPDI resource instance
 * @param mpxjResource MPXJ resource instance
 */
private void readResourceBaselines(Project.Resources.Resource xmlResource, Resource mpxjResource)
{
   for (Project.Resources.Resource.Baseline baseline : xmlResource.getBaseline())
   {
      int number = NumberHelper.getInt(baseline.getNumber());

      Double cost = DatatypeConverter.parseCurrency(baseline.getCost());
      Duration work = DatatypeConverter.parseDuration(m_projectFile, TimeUnit.HOURS, baseline.getWork());

      if (number == 0)
      {
         mpxjResource.setBaselineCost(cost);
         mpxjResource.setBaselineWork(work);
      }
      else
      {
         mpxjResource.setBaselineCost(number, cost);
         mpxjResource.setBaselineWork(number, work);
      }
   }
}
 
Example 5
Source Project: mpxj   Source File: FieldMap.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Retrieve custom field value.
 *
 * @param varData var data block
 * @param id item ID
 * @param type item type
 * @param units duration units
 * @return item value
 */
private Object getCustomFieldDurationValue(Var2Data varData, Integer id, Integer type, TimeUnit units)
{
   Object result = null;

   byte[] data = varData.getByteArray(id, type);

   if (data != null)
   {
      if (data.length == 512)
      {
         result = MPPUtility.getUnicodeString(data, 0);
      }
      else
      {
         if (data.length >= 4)
         {
            int duration = MPPUtility.getInt(data, 0);
            result = MPPUtility.getAdjustedDuration(getProjectProperties(), duration, units);
         }
      }
   }

   return result;
}
 
Example 6
Source Project: mpxj   Source File: MPXWriter.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method formats a time unit.
 *
 * @param timeUnit time unit instance
 * @return formatted time unit instance
 */
private String formatTimeUnit(TimeUnit timeUnit)
{
   int units = timeUnit.getValue();
   String result;
   String[][] unitNames = LocaleData.getStringArrays(m_locale, LocaleData.TIME_UNITS_ARRAY);

   if (units < 0 || units >= unitNames.length)
   {
      result = "";
   }
   else
   {
      result = unitNames[units][0];
   }

   return (result);
}
 
Example 7
/**
 * 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 8
Source Project: mpxj   Source File: PrimaveraReader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Process resources.
 *
 * @param rows resource data
 */
public void processResources(List<Row> rows)
{
   for (Row row : rows)
   {
      Resource resource = m_project.addResource();
      processFields(m_resourceFields, row, resource);
      resource.setResourceCalendar(getResourceCalendar(row.getInteger("clndr_id")));

      // Even though we're not filling in a rate, filling in a time unit can still be useful
      // so that we know what rate time unit was originally used in Primavera.
      TimeUnit timeUnit = TIME_UNIT_MAP.get(row.getString("cost_qty_type"));
      resource.setStandardRateUnits(timeUnit);
      resource.setOvertimeRateUnits(timeUnit);

      // Add User Defined Fields
      populateUserDefinedFieldValues("RSRC", FieldTypeClass.RESOURCE, resource, resource.getUniqueID());

      m_eventManager.fireResourceReadEvent(resource);
   }
}
 
Example 9
/**
 * Retrieves the pro-rata work carried out on a given day.
 *
 * @param calendar current calendar
 * @param assignment current assignment.
 * @return assignment work duration
 */
private Duration getAssignmentWork(ProjectCalendar calendar, TimephasedWork assignment)
{
   Date assignmentStart = assignment.getStart();

   Date splitStart = assignmentStart;
   Date splitFinishTime = calendar.getFinishTime(splitStart);
   Date splitFinish = DateHelper.setTime(splitStart, splitFinishTime);

   Duration calendarSplitWork = calendar.getWork(splitStart, splitFinish, TimeUnit.MINUTES);
   Duration assignmentWorkPerDay = assignment.getAmountPerDay();
   Duration splitWork;

   double splitMinutes = assignmentWorkPerDay.getDuration();
   splitMinutes *= calendarSplitWork.getDuration();
   splitMinutes /= (8 * 60); // this appears to be a fixed value
   splitWork = Duration.getInstance(splitMinutes, TimeUnit.MINUTES);
   return splitWork;
}
 
Example 10
Source Project: mpxj   Source File: TableA5TAB.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override protected void readRow(int uniqueID, byte[] data)
{
   Map<String, Object> map = new HashMap<>();
   map.put("UNIQUE_ID", Integer.valueOf(uniqueID));

   int originalDuration = PEPUtility.getShort(data, 22);
   int remainingDuration = PEPUtility.getShort(data, 24);
   int percentComplete = 0;

   if (originalDuration != 0)
   {
      percentComplete = ((originalDuration - remainingDuration) * 100) / originalDuration;
   }

   map.put("ORIGINAL_DURATION", Duration.getInstance(originalDuration, TimeUnit.DAYS));
   map.put("REMAINING_DURATION", Duration.getInstance(remainingDuration, TimeUnit.DAYS));
   map.put("PERCENT_COMPLETE", Integer.valueOf(percentComplete));
   map.put("TARGET_START", PEPUtility.getStartDate(data, 4));
   map.put("TARGET_FINISH", PEPUtility.getFinishDate(data, 6));
   map.put("ACTUAL_START", PEPUtility.getStartDate(data, 16));
   map.put("ACTUAL_FINISH", PEPUtility.getFinishDate(data, 18));

   addRow(uniqueID, map);
}
 
Example 11
/**
 * 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 12
Source Project: mpxj   Source File: JsonWriter.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Write a duration field to the JSON file.
 *
 * @param fieldName field name
 * @param value field value
 */
private void writeDurationField(String fieldName, Object value) throws IOException
{
   if (value != null)
   {
      if (value instanceof String)
      {
         m_writer.writeNameValuePair(fieldName + "_text", (String) value);
      }
      else
      {
         Duration val = (Duration) value;
         if (val.getDuration() != 0)
         {
            Duration minutes = val.convertUnits(TimeUnit.MINUTES, m_projectFile.getProjectProperties());
            long seconds = (long) (minutes.getDuration() * 60.0);
            m_writer.writeNameValuePair(fieldName, seconds);
         }
      }
   }
}
 
Example 13
Source Project: mpxj   Source File: TaskLinksTest.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test a relationship between two tasks.
 *
 * @param project parent project
 * @param taskID1 first task
 * @param taskID2 second task
 * @param name1 expected task name 1
 * @param name2 expected task name 1
 * @param type expected relation type
 * @param lagDuration expected lag duration
 * @param lagUnits expected lag units
 */
private void testTaskLinks(ProjectFile project, int taskID1, int taskID2, String name1, String name2, RelationType type, double lagDuration, TimeUnit lagUnits)
{
   Task task1 = project.getTaskByID(Integer.valueOf(taskID1));
   Task task2 = project.getTaskByID(Integer.valueOf(taskID2));

   assertEquals(name1, task1.getName());
   assertEquals(name2, task2.getName());

   List<Relation> relations = task2.getPredecessors();
   assertEquals(1, relations.size());
   Relation relation = relations.get(0);
   assertEquals(task2, relation.getSourceTask());
   assertEquals(task1, relation.getTargetTask());
   assertEquals(type, relation.getType());
   assertEquals(lagUnits, relation.getLag().getUnits());
   assertTrue(NumberHelper.equals(lagDuration, relation.getLag().getDuration(), 0.0001));
}
 
Example 14
Source Project: mpxj   Source File: MerlinReader.java    License: 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 15
private void importDependencies(ProjectFile pf, Map<Integer, GanttTask> foreignId2nativeTask) {
  getTaskManager().getAlgorithmCollection().getScheduler().setEnabled(false);
  try {
    for (Task t : pf.getAllTasks()) {
      if (t.getPredecessors() == null) {
        continue;
      }
      for (Relation r : t.getPredecessors()) {
        GanttTask dependant = foreignId2nativeTask.get(foreignId(r.getSourceTask()));
        GanttTask dependee = foreignId2nativeTask.get(foreignId(r.getTargetTask()));
        if (dependant == null) {
          myErrors.add(Pair.create(Level.SEVERE, String.format(
              "Failed to import relation=%s because source task=%s was not found", r, foreignId(r.getSourceTask()))));
          continue;
        }
        if (dependee == null) {
          myErrors.add(Pair.create(Level.SEVERE, String.format(
              "Failed to import relation=%s because target task=%s", t, foreignId(r.getTargetTask()))));
          continue;
        }
        try {
          TaskDependency dependency = getTaskManager().getDependencyCollection().createDependency(dependant, dependee);
          dependency.setConstraint(convertConstraint(r));
          if (r.getLag().getDuration() != 0.0) {
            // TODO(dbarashev): get rid of days
            dependency.setDifference((int) r.getLag().convertUnits(TimeUnit.DAYS, pf.getProjectProperties()).getDuration());
          }
          dependency.setHardness(TaskDependency.Hardness.parse(getTaskManager().getDependencyHardnessOption().getValue()));
        } catch (TaskDependencyException e) {
          GPLogger.getLogger("MSProject").log(Level.SEVERE, "Failed to import relation=" + r, e);
          myErrors.add(Pair.create(Level.SEVERE, String.format("Failed to import relation=%s: %s", r, e.getMessage())));
        }
      }
    }
  } finally {
    getTaskManager().getAlgorithmCollection().getScheduler().setEnabled(true);
  }
}
 
Example 16
private static Duration[] getActualAndRemainingDuration(net.sf.mpxj.Task mpxjTask, double load) {
  TimeUnit durationUnits = mpxjTask.getDuration().getUnits();
  double actualWork = (mpxjTask.getDuration().getDuration() * mpxjTask.getPercentageComplete().doubleValue() * load) / 100;
  double remainingWork = mpxjTask.getDuration().getDuration() - actualWork;

  return new Duration[] { Duration.getInstance(actualWork, durationUnits),
      Duration.getInstance(remainingWork, durationUnits) };
}
 
Example 17
Source Project: mpxj   Source File: BasicTest.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Common tests for MSPDI fileExtended Attribute values.
 *
 * @param xml MSPDI file
 */
private void commonMspdiExtendedAttributeTests(ProjectFile xml)
{
   List<Task> tasks = xml.getTasks();
   assertEquals(2, tasks.size());
   SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");

   Task task = tasks.get(1);
   assertEquals("Task Text One", task.getText(1));
   assertEquals("01/01/2004", df.format(task.getStart(1)));
   assertEquals("31/12/2004", df.format(task.getFinish(1)));
   assertEquals(99.95, task.getCost(1).doubleValue(), 0.0);
   assertEquals("18/07/2004", df.format(task.getDate(1)));
   assertTrue(task.getFlag(1));
   assertEquals(55.56, task.getNumber(1).doubleValue(), 0.0);
   assertEquals(13.0, task.getDuration(1).getDuration(), 0.0);
   assertEquals(TimeUnit.DAYS, task.getDuration(1).getUnits());

   List<Resource> resources = xml.getResources();
   assertEquals(2, resources.size());

   Resource resource = resources.get(1);
   assertEquals("Resource Text One", resource.getText(1));
   assertEquals("01/01/2003", df.format(resource.getStart(1)));
   assertEquals("31/12/2003", df.format(resource.getFinish(1)));
   assertEquals(29.99, resource.getCost(1).doubleValue(), 0.0);
   assertEquals("18/07/2003", df.format(resource.getDate(1)));
   assertTrue(resource.getFlag(1));
   assertEquals(5.99, resource.getNumber(1).doubleValue(), 0.0);
   assertEquals(22.0, resource.getDuration(1).getDuration(), 0.0);
   assertEquals(TimeUnit.DAYS, resource.getDuration(1).getUnits());
}
 
Example 18
Source Project: mpxj   Source File: TimephasedTest.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Utility method to test the attributes of a timephased resource
 * assignment.
 *
 * @param assignment TimephasedWork instance to test
 * @param start start date for this assignment
 * @param finish finish date for this assignment
 * @param totalWork total work for this assignment
 * @param workPerDay work per day for this assignment
 */
private void testTimephased(TimephasedWork assignment, String start, String finish, double totalWork, double workPerDay)
{
   assertEquals(start, m_df.format(assignment.getStart()));
   assertEquals(finish, m_df.format(assignment.getFinish()));
   assertEquals(totalWork, assignment.getTotalAmount().getDuration(), 0.02);
   assertEquals(TimeUnit.HOURS, assignment.getTotalAmount().getUnits());
   if (workPerDay != -1)
   {
      assertEquals(workPerDay, assignment.getAmountPerDay().getDuration(), 0.02);
      assertEquals(TimeUnit.HOURS, assignment.getAmountPerDay().getUnits());
   }
}
 
Example 19
Source Project: mpxj   Source File: DurationTest.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Validates duration values.
 *
 * @param mpp project file
 */
private void testDurations(ProjectFile mpp)
{
   Task task = mpp.getTaskByID(Integer.valueOf(1));
   assertEquals(Duration.getInstance(1, TimeUnit.MINUTES), task.getDuration());

   task = mpp.getTaskByID(Integer.valueOf(2));
   assertEquals(Duration.getInstance(1, TimeUnit.HOURS), task.getDuration());

   task = mpp.getTaskByID(Integer.valueOf(3));
   assertEquals(Duration.getInstance(1, TimeUnit.DAYS), task.getDuration());

   task = mpp.getTaskByID(Integer.valueOf(4));
   assertEquals(Duration.getInstance(1, TimeUnit.WEEKS), task.getDuration());

   task = mpp.getTaskByID(Integer.valueOf(5));
   assertEquals(Duration.getInstance(1, TimeUnit.MONTHS), task.getDuration());

   task = mpp.getTaskByID(Integer.valueOf(6));
   assertEquals(Duration.getInstance(1, TimeUnit.ELAPSED_MINUTES), task.getDuration());

   task = mpp.getTaskByID(Integer.valueOf(7));
   assertEquals(Duration.getInstance(1, TimeUnit.ELAPSED_HOURS), task.getDuration());

   task = mpp.getTaskByID(Integer.valueOf(8));
   assertEquals(Duration.getInstance(1, TimeUnit.ELAPSED_DAYS), task.getDuration());

   task = mpp.getTaskByID(Integer.valueOf(9));
   assertEquals(Duration.getInstance(1, TimeUnit.ELAPSED_WEEKS), task.getDuration());

   task = mpp.getTaskByID(Integer.valueOf(10));
   assertEquals(Duration.getInstance(1, TimeUnit.ELAPSED_MONTHS), task.getDuration());
}
 
Example 20
/**
 * 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 21
Source Project: mpxj   Source File: MSPDIReader.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method processes any extended attributes associated with a resource.
 *
 * @param xml MSPDI resource instance
 * @param mpx MPX resource instance
 */
private void readResourceExtendedAttributes(Project.Resources.Resource xml, Resource mpx)
{
   for (Project.Resources.Resource.ExtendedAttribute attrib : xml.getExtendedAttribute())
   {
      int xmlFieldID = Integer.parseInt(attrib.getFieldID()) & 0x0000FFFF;
      ResourceField mpxFieldID = MPPResourceField.getInstance(xmlFieldID);
      TimeUnit durationFormat = DatatypeConverter.parseDurationTimeUnits(attrib.getDurationFormat(), null);
      DatatypeConverter.parseExtendedAttribute(m_projectFile, mpx, attrib.getValue(), mpxFieldID, durationFormat);
   }
}
 
Example 22
/**
 * 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 23
Source Project: mpxj   Source File: MSPDIReader.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method processes any extended attributes associated with a
 * resource assignment.
 *
 * @param xml MSPDI resource assignment instance
 * @param mpx MPX task instance
 */
private void readAssignmentExtendedAttributes(Project.Assignments.Assignment xml, ResourceAssignment mpx)
{
   for (Project.Assignments.Assignment.ExtendedAttribute attrib : xml.getExtendedAttribute())
   {
      int xmlFieldID = Integer.parseInt(attrib.getFieldID()) & 0x0000FFFF;
      AssignmentField mpxFieldID = MPPAssignmentField.getInstance(xmlFieldID);
      TimeUnit durationFormat = DatatypeConverter.parseDurationTimeUnits(attrib.getDurationFormat(), null);
      DatatypeConverter.parseExtendedAttribute(m_projectFile, mpx, attrib.getValue(), mpxFieldID, durationFormat);
   }
}
 
Example 24
Source Project: mpxj   Source File: BasicTest.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * The files sample.mpp, sample98.mpp and sample.xml contain identical
 * data produced by MS Project. This method contains validation tests
 * on that data to ensure that the three file formats are being read
 * consistently.
 *
 * @param file ProjectFile instance
 */
private void commonTests(ProjectFile file)
{
   //
   // Test the remaining work attribute
   //
   Task task = file.getTaskByUniqueID(Integer.valueOf(2));
   List<ResourceAssignment> assignments = task.getResourceAssignments();
   assertEquals(2, assignments.size());

   for (ResourceAssignment assignment : assignments)
   {
      switch (NumberHelper.getInt(assignment.getResource().getID()))
      {
         case 1:
         {
            assertEquals(200, (int) assignment.getRemainingWork().getDuration());
            assertEquals(TimeUnit.HOURS, assignment.getRemainingWork().getUnits());
            break;
         }

         case 2:
         {
            assertEquals(300, (int) assignment.getRemainingWork().getDuration());
            assertEquals(TimeUnit.HOURS, assignment.getRemainingWork().getUnits());
            break;
         }

         default:
         {
            assertTrue("Unexpected resource", false);
            break;
         }
      }
   }
}
 
Example 25
/**
 * This is the main entry point used to convert the internal representation
 * of timephased work into an external form which can
 * be displayed to the user.
 *
 * @param projectCalendar calendar used by the resource assignment
 * @param work timephased resource assignment data
 * @param rangeUnits timescale units
 * @param dateList timescale date ranges
 * @return list of durations, one per timescale date range
 */
public ArrayList<Duration> segmentWork(ProjectCalendar projectCalendar, List<TimephasedWork> work, TimescaleUnits rangeUnits, List<DateRange> dateList)
{
   ArrayList<Duration> result = new ArrayList<>(dateList.size());
   int lastStartIndex = 0;

   //
   // Iterate through the list of dates range we are interested in.
   // Each date range in this list corresponds to a column
   // shown on the "timescale" view by MS Project
   //
   for (DateRange range : dateList)
   {
      //
      // If the current date range does not intersect with any of the
      // assignment date ranges in the list, then we show a zero
      // duration for this date range.
      //
      int startIndex = lastStartIndex == -1 ? -1 : getStartIndex(range, work, lastStartIndex);
      if (startIndex == -1)
      {
         result.add(Duration.getInstance(0, TimeUnit.HOURS));
      }
      else
      {
         //
         // We have found an assignment which intersects with the current
         // date range, call the method below to determine how
         // much time from this resource assignment can be allocated
         // to the current date range.
         //
         result.add(getRangeDuration(projectCalendar, rangeUnits, range, work, startIndex));
         lastStartIndex = startIndex;
      }
   }

   return result;
}
 
Example 26
/**
 * Read resource assignments.
 *
 * @param task Parent task
 * @param assignment ConceptDraw PROJECT resource assignment
 */
private void readResourceAssignment(Task task, Document.Projects.Project.Task.ResourceAssignments.ResourceAssignment assignment)
{
   Resource resource = m_projectFile.getResourceByUniqueID(assignment.getResourceID());
   if (resource != null)
   {
      ResourceAssignment mpxjAssignment = task.addResourceAssignment(resource);
      mpxjAssignment.setUniqueID(assignment.getID());
      mpxjAssignment.setWork(Duration.getInstance(assignment.getManHour().doubleValue() * m_workHoursPerDay, TimeUnit.HOURS));
      mpxjAssignment.setUnits(assignment.getUse());
   }
}
 
Example 27
/**
 * 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 28
Source Project: mpxj   Source File: TableCONTAB.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override protected void readRow(int uniqueID, byte[] data)
{
   if (data[0] != (byte) 0xFF)
   {
      Map<String, Object> map = new HashMap<>();
      map.put("UNIQUE_ID", Integer.valueOf(uniqueID));
      map.put("TASK_ID_1", Integer.valueOf(PEPUtility.getShort(data, 1)));
      map.put("TASK_ID_2", Integer.valueOf(PEPUtility.getShort(data, 3)));
      map.put("TYPE", getRelationType(PEPUtility.getShort(data, 9)));
      map.put("LAG", Duration.getInstance(PEPUtility.getShort(data, 11), TimeUnit.DAYS));
      addRow(uniqueID, map);
   }
}
 
Example 29
/**
 * This method extracts project properties from a GanttProject file.
 *
 * @param ganttProject GanttProject file
 */
private void readProjectProperties(Project ganttProject)
{
   ProjectProperties mpxjProperties = m_projectFile.getProjectProperties();
   mpxjProperties.setName(ganttProject.getName());
   mpxjProperties.setCompany(ganttProject.getCompany());
   mpxjProperties.setDefaultDurationUnits(TimeUnit.DAYS);

   String locale = ganttProject.getLocale();
   if (locale == null)
   {
      locale = "en_US";
   }
   m_localeDateFormat = DateFormat.getDateInstance(DateFormat.SHORT, new Locale(locale));
}
 
Example 30
/**
 * 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);
      }
   }
}