* @param parentTask parent task
* @param plannerTask Task data
*/
private void readTask(Task parentTask, net.sf.mpxj.planner.schema.Task plannerTask) throws MPXJException
{
Task mpxjTask;
if (parentTask == null)
{
mpxjTask = m_projectFile.addTask();
mpxjTask.setOutlineLevel(Integer.valueOf(1));
}
else
{
mpxjTask = parentTask.addTask();
mpxjTask.setOutlineLevel(Integer.valueOf(parentTask.getOutlineLevel().intValue() + 1));
}
//
// Read task attributes from Planner
//
Integer percentComplete = getInteger(plannerTask.getPercentComplete());
//plannerTask.getDuration(); calculate from end - start, not in file?
//plannerTask.getEffort(); not set?
mpxjTask.setFinish(getDateTime(plannerTask.getEnd()));
mpxjTask.setUniqueID(getInteger(plannerTask.getId()));
mpxjTask.setName(plannerTask.getName());
mpxjTask.setNotes(plannerTask.getNote());
mpxjTask.setPercentageComplete(percentComplete);
mpxjTask.setPercentageWorkComplete(percentComplete);
mpxjTask.setPriority(Priority.getInstance(getInt(plannerTask.getPriority()) / 10));
mpxjTask.setType(getTaskType(plannerTask.getScheduling()));
//plannerTask.getStart(); // Start day, time is always 00:00?
mpxjTask.setMilestone(plannerTask.getType().equals("milestone"));
mpxjTask.setWork(getDuration(plannerTask.getWork()));
mpxjTask.setStart(getDateTime(plannerTask.getWorkStart()));
//
// Read constraint
//
ConstraintType mpxjConstraintType = ConstraintType.AS_SOON_AS_POSSIBLE;
Constraint constraint = plannerTask.getConstraint();
if (constraint != null)
{
if (constraint.getType().equals("start-no-earlier-than"))
{
mpxjConstraintType = ConstraintType.START_NO_EARLIER_THAN;
}
else
{
if (constraint.getType().equals("must-start-on"))
{
mpxjConstraintType = ConstraintType.MUST_START_ON;
}
}
mpxjTask.setConstraintDate(getDateTime(constraint.getTime()));
}
mpxjTask.setConstraintType(mpxjConstraintType);
//
// Calculate missing attributes
//
ProjectCalendar calendar = m_projectFile.getCalendar();
if (calendar != null)
{
Duration duration = calendar.getWork(mpxjTask.getStart(), mpxjTask.getFinish(), TimeUnit.HOURS);
double durationDays = duration.getDuration() / 8;
if (durationDays > 0)
{
duration = Duration.getInstance(durationDays, TimeUnit.DAYS);
}
mpxjTask.setDuration(duration);
if (percentComplete.intValue() != 0)
{
mpxjTask.setActualStart(mpxjTask.getStart());
if (percentComplete.intValue() == 100)
{
mpxjTask.setActualFinish(mpxjTask.getFinish());
mpxjTask.setActualDuration(duration);
mpxjTask.setActualWork(mpxjTask.getWork());
mpxjTask.setRemainingWork(Duration.getInstance(0, TimeUnit.HOURS));
}
else
{
Duration work = mpxjTask.getWork();
Duration actualWork = Duration.getInstance((work.getDuration() * percentComplete.doubleValue()) / 100.0d, work.getUnits());
mpxjTask.setActualDuration(Duration.getInstance((duration.getDuration() * percentComplete.doubleValue()) / 100.0d, duration.getUnits()));
mpxjTask.setActualWork(actualWork);
mpxjTask.setRemainingWork(Duration.getInstance(work.getDuration() - actualWork.getDuration(), work.getUnits()));
}
}
}
mpxjTask.setEffortDriven(true);
m_projectFile.fireTaskReadEvent(mpxjTask);
//
// Process child tasks