net.sf.mpxj.TimeUnit Java Examples

The following examples show how to use net.sf.mpxj.TimeUnit. 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: MPXWriter.java    From mpxj with 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 #2
Source File: MSPDIReader.java    From mpxj with 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 #3
Source File: JsonWriter.java    From mpxj with 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 #4
Source File: TaskLinksTest.java    From mpxj with 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 #5
Source File: FieldMap.java    From mpxj with 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 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 #7
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 #8
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 #9
Source File: TableA5TAB.java    From mpxj with 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 #10
Source File: MPPAbstractTimephasedWorkNormaliser.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 #11
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 #12
Source File: PrimaveraReader.java    From mpxj with 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 #13
Source File: ProjectFileExporter.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
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 #14
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 #15
Source File: DefaultDurationFormatTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Ensure that where the duration format is listed as "21" in the MSPDI file, we use the default duration format,
 * as defined in the project properties.
 */
@Test public void testDefaultDateFormat() throws Exception
{
   ProjectFile file = new MSPDIReader().read(MpxjTestData.filePath("project/default-duration-format/DefaultDurationFormat.xml"));
   Task task = file.getTaskByID(Integer.valueOf(1));
   assertDurationEquals(2, TimeUnit.WEEKS, task.getDuration());
}
 
Example #16
Source File: TimephasedTest.java    From mpxj with 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 #17
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Convert a duration in seconds to a Duration instance.
 *
 * @param durationInSeconds duration in seconds
 * @return Duration instance
 */
private static final Duration getDurationFromSeconds(int durationInSeconds)
{
   if (durationInSeconds == NULL_SECONDS)
   {
      return null;
   }
   double durationInHours = durationInSeconds;
   durationInHours /= (60 * 60);
   return Duration.getInstance(durationInHours, TimeUnit.HOURS);
}
 
Example #18
Source File: ExportMSProject.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
private static void addTask(final ProjectFile file, final Map<Serializable, Task> taskMap, final Task parentTask,
    final GanttTask ganttTask)
{
  final Task task;
  if (parentTask == null) {
    task = file.addTask();
  } else {
    task = parentTask.addTask();
  }
  taskMap.put(ganttTask.getId(), task);
  task.setName(ganttTask.getTitle());
  if (ganttTask.getStartDate() != null) {
    task.setStart(ganttTask.getStartDate());
  }
  if (ganttTask.getEndDate() != null) {
    task.setFinish(ganttTask.getEndDate());
  }
  final BigDecimal duration = ganttTask.getDuration();
  final double value;
  if (duration == null) {
    value = 0.0;
  } else {
    value = duration.doubleValue();
  }
  task.setDuration(Duration.getInstance(value, TimeUnit.DAYS));
  if (ganttTask.getProgress() != null) {
    task.setPercentageComplete(ganttTask.getProgress());
  }
  // task2.setActualStart(df.parse("01/01/2003"));
  // milestone1.setDuration(Duration.getInstance(0, TimeUnit.DAYS));

  final List<GanttTask> children = ganttTask.getChildren();
  if (children == null) {
    return;
  }
  for (final GanttTask child : children) {
    addTask(file, taskMap, task, child);
  }
}
 
Example #19
Source File: ProjectFileImporter.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
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 #20
Source File: PlannerReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method extracts predecessor data from a Planner file.
 *
 * @param plannerTask Task data
 */
private void readPredecessors(net.sf.mpxj.planner.schema.Task plannerTask)
{
   Task mpxjTask = m_projectFile.getTaskByUniqueID(getInteger(plannerTask.getId()));

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

   //
   // Process child tasks
   //
   List<net.sf.mpxj.planner.schema.Task> childTasks = plannerTask.getTask();
   for (net.sf.mpxj.planner.schema.Task childTask : childTasks)
   {
      readPredecessors(childTask);
   }
}
 
Example #21
Source File: MPD9AbstractReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Process a relationship between two tasks.
 *
 * @param row relationship data
 */
protected void processLink(Row row)
{
   Task predecessorTask = m_project.getTaskByUniqueID(row.getInteger("LINK_PRED_UID"));
   Task successorTask = m_project.getTaskByUniqueID(row.getInteger("LINK_SUCC_UID"));
   if (predecessorTask != null && successorTask != null)
   {
      RelationType type = RelationType.getInstance(row.getInt("LINK_TYPE"));
      TimeUnit durationUnits = MPDUtility.getDurationTimeUnits(row.getInt("LINK_LAG_FMT"));
      Duration duration = MPDUtility.getDuration(row.getDouble("LINK_LAG").doubleValue(), durationUnits);
      Relation relation = successorTask.addPredecessor(predecessorTask, type, duration);
      relation.setUniqueID(row.getInteger("LINK_UID"));
      m_eventManager.fireRelationReadEvent(relation);
   }
}
 
Example #22
Source File: MSPDIReader.java    From mpxj with 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 #23
Source File: GanttProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read the relationships for an individual GanttProject task.
 *
 * @param gpTask GanttProject task
 */
private void readRelationships(net.sf.mpxj.ganttproject.schema.Task gpTask)
{
   for (Depend depend : gpTask.getDepend())
   {
      Task task1 = m_projectFile.getTaskByUniqueID(Integer.valueOf(NumberHelper.getInt(gpTask.getId()) + 1));
      Task task2 = m_projectFile.getTaskByUniqueID(Integer.valueOf(NumberHelper.getInt(depend.getId()) + 1));
      if (task1 != null && task2 != null)
      {
         Duration lag = Duration.getInstance(NumberHelper.getInt(depend.getDifference()), TimeUnit.DAYS);
         Relation relation = task2.addPredecessor(task1, getRelationType(depend.getType()), lag);
         m_eventManager.fireRelationReadEvent(relation);
      }
   }
}
 
Example #24
Source File: MSPDIReader.java    From mpxj with 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 #25
Source File: GanttProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 #26
Source File: TableCONTAB.java    From mpxj with 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 #27
Source File: BasicTest.java    From mpxj with 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 #28
Source File: TimephasedUtility.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 #29
Source File: ConceptDrawProjectReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 #30
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;
}