}
return iterationLevelTask;
}
private void exportUserStory(Task iterationLevelTask, UserStory userStory, ResourceRegistry resources) throws MPXException {
Task storyLevelTask = iterationLevelTask.addTask();
storyLevelTask.setName(userStory.getName());
if (StringUtils.isNotEmpty(userStory.getDescription())) {
storyLevelTask.addTaskNotes(filterString(userStory.getDescription()));
}
long earliestTaskStartTime = Long.MAX_VALUE;
Collection storyTasks = userStory.getTasks();
if (storyTasks.size() > 0) {
for (Iterator iterator = storyTasks.iterator(); iterator.hasNext();) {
org.nxplanner.domain.Task task = (org.nxplanner.domain.Task) iterator.next();
Task taskLevelTask = storyLevelTask.addTask();
taskLevelTask.setName(task.getName());
taskLevelTask.setDuration(new MPXDuration(task.getEstimatedHours(), TimeUnit.HOURS));
if (StringUtils.isNotEmpty(task.getDescription())) {
taskLevelTask.addTaskNotes(filterString(task.getDescription()));
}
if (task.getAcceptorId() != 0) {
taskLevelTask.addResourceAssignment(resources.getResource(task.getAcceptorId()));
}
if (task.getActualHours() != 0) {
taskLevelTask.setActualWork(new MPXDuration(task.getActualHours(), TimeUnit.HOURS));
Date startTime = getStartTime(iterationLevelTask, task);
if (startTime != null) {
taskLevelTask.setActualStart(startTime);
}
}
if (task.getTimeEntries().size() > 0) {
long startTime = Long.MAX_VALUE;
for (Iterator timeItr = task.getTimeEntries().iterator(); timeItr.hasNext();) {
TimeEntry timeEntry = (TimeEntry) timeItr.next();
if (timeEntry.getStartTime() != null && timeEntry.getStartTime().getTime() < startTime) {
startTime = timeEntry.getStartTime().getTime();
}
}
if (startTime < Long.MAX_VALUE) {
taskLevelTask.setActualStart(new Date(startTime));
if (startTime < earliestTaskStartTime) {
earliestTaskStartTime = startTime;
}
}
} else {
taskLevelTask.setActualStart(iterationLevelTask.getActualStart());
}
}
if (earliestTaskStartTime == Long.MAX_VALUE) {
earliestTaskStartTime = iterationLevelTask.getStart().getTime();
}
List tasks = storyLevelTask.getChildTasks();
for (int i = 0; i < tasks.size(); i++) {
Task task = (Task) tasks.get(i);
if (task.getActualStart() == null) {
task.setActualStart(new Date(earliestTaskStartTime));
}
}
} else {
storyLevelTask.setActualStart(iterationLevelTask.getStart());
storyLevelTask.setDuration(new MPXDuration(0, TimeUnit.DAYS));