From 1810d92ae2d2b08ac70b7a43f0ee3509c568b76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Wed, 23 Sep 2009 01:34:38 +0200 Subject: [PATCH] ItEr27S06CUAsignacionGrupoRecursosAPlanificacionItEr26S07: When accepting the allocation ResourceAllocationsBeingEdited do the computation --- .../web/planner/allocation/FormBinder.java | 6 ++++- .../allocation/ResourceAllocationModel.java | 23 +++++++------------ .../ResourceAllocationsBeingEdited.java | 6 ++++- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/FormBinder.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/FormBinder.java index 2034af23a..cf3539437 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/FormBinder.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/FormBinder.java @@ -154,7 +154,11 @@ class FormBinder { } public int getAssignedHours() { - return assignedHoursComponent.getValue(); + Integer result = assignedHoursComponent.getValue(); + if (result == null) { + throw new RuntimeException("assignedHoursComponent returns null"); + } + return result; } public void setDeleteButtonFor(SpecificAllocationDTO data, diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java index f999c8ef9..45bb64d81 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java @@ -5,7 +5,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.joda.time.LocalDate; import org.navalplanner.business.orders.daos.IHoursGroupDAO; import org.navalplanner.business.orders.entities.HoursGroup; import org.navalplanner.business.planner.daos.IResourceAllocationDAO; @@ -13,7 +12,6 @@ import org.navalplanner.business.planner.daos.ITaskElementDAO; import org.navalplanner.business.planner.entities.ResourceAllocation; import org.navalplanner.business.planner.entities.SpecificResourceAllocation; import org.navalplanner.business.planner.entities.Task; -import org.navalplanner.business.planner.entities.allocationalgorithms.ResourceAllocationWithDesiredResourcesPerDay; import org.navalplanner.business.resources.daos.IResourceDAO; import org.navalplanner.business.resources.entities.Criterion; import org.navalplanner.business.resources.entities.CriterionSatisfaction; @@ -83,7 +81,7 @@ public class ResourceAllocationModel implements IResourceAllocationModel { public void save() { planningState.reassociateResourcesWithSession(resourceDAO); removeDeletedAllocations(); - mergeDTOsToTask(); + doTheAllocation(); } private void removeDeletedAllocations() { @@ -94,19 +92,14 @@ public class ResourceAllocationModel implements IResourceAllocationModel { } } - private void mergeDTOsToTask() { - ResourceAllocationsBeingEdited taskModifying = resourceAllocationsBeingEdited + private void doTheAllocation() { + ResourceAllocationsBeingEdited allocator = resourceAllocationsBeingEdited .taskModifying(); - List resourceAllocations = taskModifying - .asResourceAllocations(); - if (task.isFixedDuration()) { - ResourceAllocation.allocating(resourceAllocations).withResources( - getResourcesMatchingCriterions()).allocateOnTaskLength(); - } else { - LocalDate end = ResourceAllocation.allocating(resourceAllocations) - .withResources(getResourcesMatchingCriterions()) - .untilAllocating(task.getHoursSpecifiedAtOrder()); - ganttTask.setEndDate(end.toDateTimeAtStartOfDay().toDate()); + allocator.doAllocation(); + Integer newDaysDuration = allocator.getDaysDuration(); + if (task.getDaysDuration() != newDaysDuration) { + task.setDaysDuration(newDaysDuration); + ganttTask.setEndDate(task.getEndDate()); } } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationsBeingEdited.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationsBeingEdited.java index c6f945869..23c65f3f5 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationsBeingEdited.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationsBeingEdited.java @@ -118,6 +118,7 @@ public class ResourceAllocationsBeingEdited { case NUMBER_OF_HOURS: ResourceAllocation.allocating(allocations).withResources( resourcesMatchingCriterions).allocateOnTaskLength(); + daysDuration = task.getDaysDuration(); break; case END_DATE: LocalDate end = ResourceAllocation.allocating(allocations) @@ -188,8 +189,11 @@ public class ResourceAllocationsBeingEdited { } public ResourceAllocationsBeingEdited taskModifying() { - return new ResourceAllocationsBeingEdited(task, currentAllocations, + ResourceAllocationsBeingEdited result = new ResourceAllocationsBeingEdited( + task, currentAllocations, resourceDAO, resourcesMatchingCriterions, true); + result.formBinder = this.formBinder; + return result; } public FormBinder createFormBinder() {