diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/Task.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/Task.java index 2ba3993ba..37ca4ec9b 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/Task.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/Task.java @@ -465,56 +465,15 @@ public class Task extends TaskElement implements ITaskPositionConstrained { } - private static abstract class AllocationModificationStrategy { + private static class WithPotentiallyNewResources { protected final IResourcesSearcher searcher; - public AllocationModificationStrategy(IResourcesSearcher searcher) { + public WithPotentiallyNewResources(IResourcesSearcher searcher) { Validate.notNull(searcher); this.searcher = searcher; } - public abstract ModificationsResult getResourcesPerDayModified( - List> allocations); - - public abstract ModificationsResult getHoursModified( - List> allocations); - - } - - private static class WithTheSameHoursAndResourcesPerDay extends - AllocationModificationStrategy { - - public WithTheSameHoursAndResourcesPerDay(IResourcesSearcher searcher) { - super(searcher); - } - - @Override - public ModificationsResult getHoursModified( - List> allocations) { - List canBeModified = EffortModification - .fromExistent(allocations, searcher); - return ModificationsResult.create(allocations, canBeModified); - } - - @Override - public ModificationsResult getResourcesPerDayModified( - List> allocations) { - List canBeModified = ResourcesPerDayModification - .fromExistent(allocations, searcher); - return ModificationsResult.create(allocations, canBeModified); - } - - } - - private static class WithAnotherResources extends - AllocationModificationStrategy { - - public WithAnotherResources(IResourcesSearcher searcher) { - super(searcher); - } - - @Override public ModificationsResult getHoursModified( List> allocations) { List canBeModified = EffortModification @@ -522,13 +481,13 @@ public class Task extends TaskElement implements ITaskPositionConstrained { return ModificationsResult.create(allocations, canBeModified); } - @Override public ModificationsResult getResourcesPerDayModified( List> allocations) { List canBeModified = ResourcesPerDayModification .withNewResources(allocations, searcher); return ModificationsResult.create(allocations, canBeModified); } + } public void copyAssignmentsFromOneScenarioToAnother(Scenario from, Scenario to) { @@ -554,8 +513,8 @@ public class Task extends TaskElement implements ITaskPositionConstrained { } private void doReassignment(Direction direction) { - reassign(scenario, direction, - new WithTheSameHoursAndResourcesPerDay(searcher)); + reassign(scenario, direction, new WithPotentiallyNewResources( + searcher)); } @Override @@ -753,12 +712,12 @@ public class Task extends TaskElement implements ITaskPositionConstrained { public void reassignAllocationsWithNewResources(Scenario scenario, IResourcesSearcher searcher) { - reassign(scenario, getAllocationDirection(), new WithAnotherResources( - searcher)); + reassign(scenario, getAllocationDirection(), + new WithPotentiallyNewResources(searcher)); } private void reassign(Scenario onScenario, Direction direction, - AllocationModificationStrategy strategy) { + WithPotentiallyNewResources strategy) { try { this.lastAllocationDirection = direction; if (isLimiting()) { @@ -784,7 +743,7 @@ public class Task extends TaskElement implements ITaskPositionConstrained { } } - private void doAllocation(AllocationModificationStrategy strategy, + private void doAllocation(WithPotentiallyNewResources strategy, Direction direction, List> toBeModified) { ModificationsResult modificationsResult = strategy .getResourcesPerDayModified(toBeModified); diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/TaskElementAdapter.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/TaskElementAdapter.java index 20d8880f9..e2031a111 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/TaskElementAdapter.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/TaskElementAdapter.java @@ -86,6 +86,7 @@ import org.libreplan.business.workingday.EffortDuration; import org.libreplan.business.workingday.EffortDuration.IEffortFrom; import org.libreplan.business.workingday.IntraDayDate; import org.libreplan.business.workingday.IntraDayDate.PartialDay; +import org.libreplan.web.planner.order.PlanningStateCreator.PlanningState; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; @@ -211,8 +212,8 @@ public class TaskElementAdapter { } public IAdapterToTaskFundamentalProperties createForOrder( - Scenario currentScenario, Order order) { - Adapter result = new Adapter(); + Scenario currentScenario, Order order, PlanningState planningState) { + Adapter result = new Adapter(planningState); result.useScenario(currentScenario); result.setInitDate(asLocalDate(order.getInitDate())); result.setDeadline(asLocalDate(order.getDeadline())); @@ -362,6 +363,8 @@ public class TaskElementAdapter { private boolean preventCalculateResourcesText = false; + private final PlanningState planningState; + private void useScenario(Scenario scenario) { this.scenario = scenario; } @@ -384,8 +387,12 @@ public class TaskElementAdapter { } public Adapter() { + this(null); } + public Adapter(PlanningState planningState) { + this.planningState = planningState; + } private class TaskElementWrapper implements ITaskFundamentalProperties { @@ -493,6 +500,10 @@ public class TaskElementAdapter { @Override public Void execute() { + if (planningState != null) { + planningState + .reassociateResourcesWithSession(); + } modifications.doIt(position); return null; } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/order/PlanningStateCreator.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/order/PlanningStateCreator.java index 5e3382e36..c9a8f997d 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/order/PlanningStateCreator.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/order/PlanningStateCreator.java @@ -785,7 +785,7 @@ public class PlanningStateCreator { } IAdapterToTaskFundamentalProperties adapter; adapter = taskElementAdapterCreator.createForOrder( - getScenarioInfo().getCurrentScenario(), order); + getScenarioInfo().getCurrentScenario(), order, this); PlannerConfiguration result = new PlannerConfiguration( adapter, new TaskElementNavigator(), getInitial());