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

The following examples show how to use net.sf.mpxj.Duration#getDuration() . 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: 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 2
Source File: MSPDIReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test to determine if this is a split task.
 *
 * @param calendar current calendar
 * @param list timephased resource assignment list
 * @return boolean flag
 */
private boolean isSplit(ProjectCalendar calendar, List<TimephasedWork> list)
{
   boolean result = false;
   for (TimephasedWork assignment : list)
   {
      if (calendar != null && assignment.getTotalAmount().getDuration() == 0)
      {
         Duration calendarWork = calendar.getWork(assignment.getStart(), assignment.getFinish(), TimeUnit.MINUTES);
         if (calendarWork.getDuration() != 0)
         {
            result = true;
            break;
         }
      }
   }
   return result;
}
 
Example 3
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Print duration in thousandths of minutes.
 *
 * @param duration Duration instance
 * @return duration in thousandths of minutes
 */
public static final BigInteger printDurationInIntegerThousandthsOfMinutes(Duration duration)
{
   BigInteger result = null;
   if (duration != null && duration.getDuration() != 0)
   {
      result = BigInteger.valueOf((long) printDurationFractionsOfMinutes(duration, 1000));
   }
   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 5 votes vote down vote up
/**
 * Retrieve a duration in the form required by Phoenix.
 *
 * @param duration Duration instance
 * @return formatted duration
 */
public static final String printDuration(Duration duration)
{
   String result = null;
   if (duration != null)
   {
      result = duration.getDuration() + " " + printTimeUnits(duration.getUnits());
   }
   return result;
}
 
Example 6
Source File: MPXWriter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method is called to format a relation.
 *
 * @param relation relation instance
 * @return formatted relation instance
 */
private String formatRelation(Relation relation)
{
   String result = null;

   if (relation != null)
   {
      StringBuilder sb = new StringBuilder(relation.getTargetTask().getID().toString());

      Duration duration = relation.getLag();
      RelationType type = relation.getType();
      double durationValue = duration.getDuration();

      if ((durationValue != 0) || (type != RelationType.FINISH_START))
      {
         String[] typeNames = LocaleData.getStringArray(m_locale, LocaleData.RELATION_TYPES);
         sb.append(typeNames[type.getValue()]);
      }

      if (durationValue != 0)
      {
         if (durationValue > 0)
         {
            sb.append('+');
         }

         sb.append(formatDuration(duration));
      }

      result = sb.toString();
   }

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

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

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

   return (link);
}
 
Example 8
Source File: MpxjQuery.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Internal utility to dump relationship lists in a structured format
 * that can easily be compared with the tabular data in MS Project.
 *
 * @param relations relation list
 */
private static void dumpRelationList(List<Relation> relations)
{
   if (relations != null && relations.isEmpty() == false)
   {
      if (relations.size() > 1)
      {
         System.out.print('"');
      }
      boolean first = true;
      for (Relation relation : relations)
      {
         if (!first)
         {
            System.out.print(',');
         }
         first = false;
         System.out.print(relation.getTargetTask().getID());
         Duration lag = relation.getLag();
         if (relation.getType() != RelationType.FINISH_START || lag.getDuration() != 0)
         {
            System.out.print(relation.getType());
         }

         if (lag.getDuration() != 0)
         {
            if (lag.getDuration() > 0)
            {
               System.out.print("+");
            }
            System.out.print(lag);
         }
      }
      if (relations.size() > 1)
      {
         System.out.print('"');
      }
   }
}
 
Example 9
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Print duration in tenths of minutes.
 *
 * @param duration Duration instance
 * @return duration in tenths of minutes
 */
public static final BigInteger printDurationInIntegerTenthsOfMinutes(Duration duration)
{
   BigInteger result = null;

   if (duration != null && duration.getDuration() != 0)
   {
      result = BigInteger.valueOf((long) printDurationFractionsOfMinutes(duration, 10));
   }

   return result;
}
 
Example 10
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Print duration in thousandths of minutes.
 *
 * @param duration Duration instance
 * @return duration in thousandths of minutes
 */
public static final BigDecimal printDurationInDecimalThousandthsOfMinutes(Duration duration)
{
   BigDecimal result = null;
   if (duration != null && duration.getDuration() != 0)
   {
      result = BigDecimal.valueOf(printDurationFractionsOfMinutes(duration, 1000));
   }
   return result;
}
 
Example 11
Source File: MSPDIWriter.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Writes resource baseline data.
 *
 * @param xmlResource MSPDI resource
 * @param mpxjResource MPXJ resource
 */
private void writeResourceBaselines(Project.Resources.Resource xmlResource, Resource mpxjResource)
{
   Project.Resources.Resource.Baseline baseline = m_factory.createProjectResourcesResourceBaseline();
   boolean populated = false;

   Number cost = mpxjResource.getBaselineCost();
   if (cost != null && cost.intValue() != 0)
   {
      populated = true;
      baseline.setCost(DatatypeConverter.printCurrency(cost));
   }

   Duration work = mpxjResource.getBaselineWork();
   if (work != null && work.getDuration() != 0)
   {
      populated = true;
      baseline.setWork(DatatypeConverter.printDuration(this, work));
   }

   if (populated)
   {
      xmlResource.getBaseline().add(baseline);
      baseline.setNumber(BigInteger.ZERO);
   }

   for (int loop = 1; loop <= 10; loop++)
   {
      baseline = m_factory.createProjectResourcesResourceBaseline();
      populated = false;

      cost = mpxjResource.getBaselineCost(loop);
      if (cost != null && cost.intValue() != 0)
      {
         populated = true;
         baseline.setCost(DatatypeConverter.printCurrency(cost));
      }

      work = mpxjResource.getBaselineWork(loop);
      if (work != null && work.getDuration() != 0)
      {
         populated = true;
         baseline.setWork(DatatypeConverter.printDuration(this, work));
      }

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

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

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

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

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

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

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

   config.setAutoAssignmentUniqueID(autoUniqueID);
}
 
Example 13
Source File: AbstractTimephasedWorkNormaliser.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Merges individual days together into time spans where the
 * same work is undertaken each day.
 *
 * @param list assignment data
 */
protected void mergeSameWork(List<TimephasedWork> list)
{
   List<TimephasedWork> result = new ArrayList<>();

   TimephasedWork previousAssignment = null;
   for (TimephasedWork assignment : list)
   {
      if (previousAssignment == null)
      {
         assignment.setAmountPerDay(assignment.getTotalAmount());
         result.add(assignment);
      }
      else
      {
         Duration previousAssignmentWork = previousAssignment.getAmountPerDay();
         Duration assignmentWork = assignment.getTotalAmount();

         if (NumberHelper.equals(previousAssignmentWork.getDuration(), assignmentWork.getDuration(), 0.01))
         {
            Date assignmentStart = previousAssignment.getStart();
            Date assignmentFinish = assignment.getFinish();
            double total = previousAssignment.getTotalAmount().getDuration();
            total += assignmentWork.getDuration();
            Duration totalWork = Duration.getInstance(total, TimeUnit.MINUTES);

            TimephasedWork merged = new TimephasedWork();
            merged.setStart(assignmentStart);
            merged.setFinish(assignmentFinish);
            merged.setAmountPerDay(assignmentWork);
            merged.setTotalAmount(totalWork);

            result.remove(result.size() - 1);
            assignment = merged;
         }
         else
         {
            assignment.setAmountPerDay(assignment.getTotalAmount());
         }
         result.add(assignment);
      }

      previousAssignment = assignment;
   }

   list.clear();
   list.addAll(result);
}
 
Example 14
Source File: XsdDuration.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This constructor allows an xsd:duration to be created from
 * an MPX duration.
 *
 * @param duration An MPX duration.
 */
XsdDuration(Duration duration)
{
   if (duration != null)
   {
      double amount = duration.getDuration();

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

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

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

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

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

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

            default:
            {
               break;
            }
         }
      }
   }
}
 
Example 15
Source File: MPPAbstractTimephasedWorkNormaliser.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method breaks down spans of time into individual days.
 *
 * @param calendar current project calendar
 * @param list list of assignment data
 */
private void splitDays(ProjectCalendar calendar, List<TimephasedWork> list)
{
   List<TimephasedWork> result = new ArrayList<>();
   boolean remainderInserted = false;

   for (TimephasedWork assignment : list)
   {
      if (remainderInserted)
      {
         assignment.setStart(DateHelper.addDays(assignment.getStart(), 1));
         remainderInserted = false;
      }

      while (assignment != null)
      {
         Date startDay = DateHelper.getDayStartDate(assignment.getStart());
         Date finishDay = DateHelper.getDayStartDate(assignment.getFinish());

         // special case - when the finishday time is midnight, it's really the previous day...
         if (assignment.getFinish().getTime() == finishDay.getTime())
         {
            finishDay = DateHelper.addDays(finishDay, -1);
         }

         if (startDay.getTime() == finishDay.getTime())
         {
            Duration totalWork = assignment.getTotalAmount();
            Duration assignmentWork = getAssignmentWork(calendar, assignment);
            if ((totalWork.getDuration() - assignmentWork.getDuration()) > EQUALITY_DELTA)
            {
               assignment.setTotalAmount(assignmentWork);
               result.add(assignment);
               Duration remainingWork = Duration.getInstance(totalWork.getDuration() - assignmentWork.getDuration(), TimeUnit.MINUTES);

               Date remainderStart = DateHelper.addDays(finishDay, 1);
               Date remainderFinish = DateHelper.addDays(remainderStart, 1);

               TimephasedWork remainder = new TimephasedWork();
               remainder.setStart(remainderStart);
               remainder.setFinish(remainderFinish);
               remainder.setTotalAmount(remainingWork);
               result.add(remainder);

               remainderInserted = true;
            }
            else
            {
               result.add(assignment);
            }
            break;
         }

         TimephasedWork[] split = splitFirstDay(calendar, assignment);
         if (split[0] != null)
         {
            result.add(split[0]);
         }

         if (assignment.equals(split[1]))
         {
            break;
         }

         assignment = split[1];
      }
   }

   list.clear();
   list.addAll(result);
}
 
Example 16
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 17
Source File: PhoenixReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Create a Task instance from a Phoenix activity.
 *
 * @param activity Phoenix activity data
 */
private void processActivity(Activity activity)
{
   Task task = getParentTask(activity).addTask();
   task.setText(1, activity.getId());

   task.setActualDuration(activity.getActualDuration());
   task.setActualFinish(activity.getActualFinish());
   task.setActualStart(activity.getActualStart());
   //activity.getBaseunit()
   //activity.getBilled()
   //activity.getCalendar()
   //activity.getCostAccount()
   task.setCreateDate(activity.getCreationTime());
   task.setFinish(activity.getCurrentFinish());
   task.setStart(activity.getCurrentStart());
   task.setName(activity.getDescription());
   task.setDuration(activity.getDurationAtCompletion());
   task.setEarlyFinish(activity.getEarlyFinish());
   task.setEarlyStart(activity.getEarlyStart());
   task.setFreeSlack(activity.getFreeFloat());
   task.setLateFinish(activity.getLateFinish());
   task.setLateStart(activity.getLateStart());
   task.setNotes(activity.getNotes());
   task.setBaselineDuration(activity.getOriginalDuration());
   //activity.getPathFloat()
   task.setPhysicalPercentComplete(activity.getPhysicalPercentComplete());
   task.setRemainingDuration(activity.getRemainingDuration());
   task.setCost(activity.getTotalCost());
   task.setTotalSlack(activity.getTotalFloat());
   task.setMilestone(activityIsMilestone(activity));
   //activity.getUserDefined()
   task.setGUID(activity.getUuid());

   if (task.getMilestone())
   {
      if (activityIsStartMilestone(activity))
      {
         task.setFinish(task.getStart());
      }
      else
      {
         task.setStart(task.getFinish());
      }
   }

   if (task.getDuration().getDuration() == 0)
   {
      // Phoenix normally represents the finish date as the start of the
      // day following the end of the activity. For example a 2 day activity
      // starting on day 1 would be shown in the PPX file as having a finish
      // date of day 3. We subtract one day to make the dates consistent with
      // all other schedule formats MPXJ handles. Occasionally for zero
      // duration tasks (which aren't tagged as milestones) the finish date
      // will be the same as the start date, so applying our "subtract 1" fix
      // gives us a finish date before the start date. The code below
      // deals with this situation.
      if (DateHelper.compare(task.getStart(), task.getFinish()) > 0)
      {
         task.setFinish(task.getStart());
      }

      if (task.getActualStart() != null && task.getActualFinish() != null && DateHelper.compare(task.getActualStart(), task.getActualFinish()) > 0)
      {
         task.setActualFinish(task.getActualStart());
      }
   }

   if (task.getActualStart() == null)
   {
      task.setPercentageComplete(Integer.valueOf(0));
   }
   else
   {
      if (task.getActualFinish() != null)
      {
         task.setPercentageComplete(Integer.valueOf(100));
      }
      else
      {
         Duration remaining = activity.getRemainingDuration();
         Duration total = activity.getDurationAtCompletion();
         if (remaining != null && total != null && total.getDuration() != 0)
         {
            double percentComplete = ((total.getDuration() - remaining.getDuration()) * 100.0) / total.getDuration();
            task.setPercentageComplete(Double.valueOf(percentComplete));
         }
      }
   }

   m_activityMap.put(activity.getId(), task);
}
 
Example 18
Source File: ProgressRecord.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override public void process(Context context)
{
   Double totalCost = getDouble(4);
   Double costToDate = getDouble(5);
   Double remainingCost = Double.valueOf(NumberHelper.getDouble(totalCost) - NumberHelper.getDouble(costToDate));
   Duration totalFloat = getDuration(12);
   if ("-".equals(getString(11)))
   {
      totalFloat = Duration.getInstance(-totalFloat.getDuration(), TimeUnit.DAYS);
   }

   Task task = context.getTask(getString(0));
   task.setActualStart(getDate(1));
   task.setActualFinish(getDate(2));
   task.setRemainingDuration(getDuration(3));
   task.setCost(getDouble(4));
   task.setRemainingCost(remainingCost);
   task.setCost(1, getDouble(6));
   task.setEarlyStart(getDate(7));
   task.setEarlyFinish(getDate(8));
   task.setLateStart(getDate(9));
   task.setLateFinish(getDate(10));
   task.setTotalSlack(totalFloat);

   Date start = task.getActualStart() == null ? task.getEarlyStart() : task.getActualStart();
   Date finish = task.getActualFinish() == null ? task.getEarlyFinish() : task.getActualFinish();
   double percentComplete = 0;

   if (task.getActualFinish() == null)
   {
      Duration duration = task.getDuration();
      Duration remainingDuration = task.getRemainingDuration();
      if (duration != null && remainingDuration != null)
      {
         double durationValue = duration.getDuration();
         double remainingDurationValue = remainingDuration.getDuration();
         if (durationValue != 0 && remainingDurationValue < durationValue)
         {
            percentComplete = ((durationValue - remainingDurationValue) * 100.0) / durationValue;
         }
      }
   }
   else
   {
      percentComplete = 100.0;
   }

   task.setStart(start);
   task.setFinish(finish);
   task.setPercentageComplete(Double.valueOf(percentComplete));
}
 
Example 19
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 20
Source File: DatatypeConverter.java    From mpxj with GNU Lesser General Public License v2.1 3 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 printDuration(MSPDIWriter writer, Duration duration)
{
   String result = null;

   if (duration != null && duration.getDuration() != 0)
   {
      result = printDurationMandatory(writer, duration);
   }

   return (result);
}