OrderVersion orderVersion = OrderVersion.createInitialVersion(current);
Validate.notNull(orderVersion);
OrderElement orderElement;
orderElement = Order.createUnvalidated(code);
orderElement.setCodeAutogenerated(true);
((Order) orderElement).setVersionForScenario(current, orderVersion);
((Order) orderElement).setDependenciesConstraintsHavePriority(true);
BaseCalendar calendar = configurationDAO.getConfiguration()
.getDefaultCalendar();
if (importCalendar & project.calendarName != null) {
((Order) orderElement).setCalendar(findBaseCalendar(
project.calendarName));
} else {
((Order) orderElement).setCalendar(calendar);
}
orderElement.useSchedulingDataFor(orderVersion);
List<OrderElement> children = new ArrayList<OrderElement>();
for (OrderElementDTO task : project.tasks) {
children.add(convertImportTaskToOrderElement(orderVersion, task));
}
for (OrderElement child : children) {
((OrderLineGroup) orderElement).add(child);
}
orderElement.setName(project.name + ": " + project.hashCode());
orderElement.setCode(code);
orderElement.setInitDate(project.startDate);
orderElement.setDeadline(project.deadline);
((Order) orderElement).calculateAndSetTotalHours();
project.order = (Order) orderElement;