}
@Override
@Transactional
public void transfer(Order order) throws ValidationException {
Scenario sourceScenario = getSourceScenario();
Scenario destinationScenario = getDestinationScenario();
if (sourceScenario == null) {
throw new ValidationException(
_("Please select a source scenario"));
}
if (destinationScenario == null) {
throw new ValidationException(
_("Please, select a destination scenario"));
}
if (sourceScenario.getId().equals(destinationScenario.getId())) {
throw new ValidationException(
_("Source and destination scenarios should be different"));
}
orderDAO.save(order);
OrderVersion sourceOrderVersion = order
.getOrderVersionFor(sourceScenario);
if (sourceOrderVersion == null) {
throw new RuntimeException(
"Project version must not be null for source scenario");
}
OrderVersion destinationOrderVersion = order
.getOrderVersionFor(destinationScenario);
if ((destinationOrderVersion != null)
&& (sourceOrderVersion.getId().equals(destinationOrderVersion
.getId()))) {
throw new ValidationException(
_("Project version is the same in source and destination scenarios"));
}
order.useSchedulingDataFor(sourceOrderVersion);
OrderVersion newOrderVersion = OrderVersion
.createInitialVersion(destinationScenario);
order.setOrderVersion(destinationScenario, newOrderVersion);
order
.writeSchedulingDataChangesTo(destinationScenario,
newOrderVersion);
scenarioDAO.updateDerivedScenariosWithNewVersion(
destinationOrderVersion, order, destinationScenario,
newOrderVersion);
List<TaskSource> taskSourcesFromBottomToTop = order
.getTaskSourcesFromBottomToTop();
for (TaskSource taskSource : taskSourcesFromBottomToTop) {
taskSourceDAO.save(taskSource);
}
try {
setDestinationScenario(scenarioDAO
.find(destinationScenario.getId()));
} catch (InstanceNotFoundException e) {
throw new RuntimeException(e);
}
}