diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/limitingresources/LimitingResourceQueueModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/limitingresources/LimitingResourceQueueModel.java index 87aa01364..375a7b383 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/limitingresources/LimitingResourceQueueModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/limitingresources/LimitingResourceQueueModel.java @@ -433,10 +433,33 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { .getPotentiallyAffectedByInsertion(externalQueueElement), requirements.getElement(), allocation); result.addAll(moved); + result.addAll(scheduleUnscheduledElementsIfNeeded(allocation)); + + return result; + } + + private Collection scheduleUnscheduledElementsIfNeeded( + AllocationSpec allocation) { + + List result = new ArrayList(); - // Return all moved tasks (including the allocated one) if (allocation.isAppropriative()) { - result.addAll(scheduleElements(allocation.getUnscheduledElements())); + checkAllocationIsAppropriative(false); + + // Assign all unscheduled elements + List unscheduled = allocation.getUnscheduledElements(); + for (LimitingResourceQueueElement each: unscheduled) { + result.addAll(assignLimitingResourceQueueElement(each)); + } + + // Only for those originally unscheduled elements, unschedule and + // schedule them again to force dependencies are satisfied + for (LimitingResourceQueueElement each: unscheduled) { + unschedule(each); + assignLimitingResourceQueueElement(each); + } + + checkAllocationIsAppropriative(true); } return result; } @@ -780,24 +803,8 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { queuesState.getPotentiallyAffectedByInsertion(element), requirements.getElement(), allocation); result.addAll(moved); + result.addAll(scheduleUnscheduledElementsIfNeeded(allocation)); - // Return all moved tasks (including the allocated one) - if (allocation.isAppropriative()) { - result.addAll(scheduleElements(allocation.getUnscheduledElements())); - } - return result; - } - - private List scheduleElements( - List unscheduled) { - - List result = new ArrayList(); - - checkAllocationIsAppropriative(false); - for (LimitingResourceQueueElement each: unscheduled) { - result.addAll(assignLimitingResourceQueueElement(each)); - } - checkAllocationIsAppropriative(true); return result; }