From abd2d81f02e2d9874d57096e7b0f1035342cca0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Tue, 6 Oct 2009 18:01:49 +0200 Subject: [PATCH] ItEr29S06CUAsignacionGrupoRecursosAPlanificacionItEr28S06: doAllocation returns a result grouping two result items --- .../web/planner/allocation/FormBinder.java | 3 +- .../allocation/ResourceAllocationModel.java | 4 +-- .../ResourceAllocationsBeingEdited.java | 30 +++++++++++++++++-- 3 files changed, 32 insertions(+), 5 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 4e1ddb15b..53de982fd 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 @@ -162,7 +162,8 @@ class FormBinder { } private void doApply() { - aggregate = resourceAllocationsBeingEdited.doAllocation(); + aggregate = resourceAllocationsBeingEdited.doAllocation() + .getAggregate(); reloadValues(); } 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 6ccab7da7..0f04866c6 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 @@ -119,8 +119,8 @@ public class ResourceAllocationModel implements IResourceAllocationModel { private void doTheAllocation() { ResourceAllocationsBeingEdited allocator = resourceAllocationsBeingEdited .taskModifying(); - allocator.doAllocation(); - Integer newDaysDuration = allocator.getDaysDuration(); + AllocationResult allocationResult = allocator.doAllocation(); + Integer newDaysDuration = allocationResult.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 e431edab4..8ba7dc019 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 @@ -28,6 +28,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.commons.lang.Validate; import org.joda.time.Days; import org.joda.time.LocalDate; import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations; @@ -185,7 +186,7 @@ public class ResourceAllocationsBeingEdited { && getGenericAllocation().isEmptyResourcesPerDay(); } - public AggregateOfResourceAllocations doAllocation() { + public AllocationResult doAllocation() { checkInvalidValues(); List allocations = asResourceAllocations(); switch (calculatedValue) { @@ -203,7 +204,8 @@ public class ResourceAllocationsBeingEdited { default: throw new RuntimeException("cant handle: " + calculatedValue); } - return new AggregateOfResourceAllocations(stripResourcesPerDay(allocations)); + return new AllocationResult(new AggregateOfResourceAllocations( + stripResourcesPerDay(allocations)), daysDuration); } private Integer from(Date startDate, LocalDate end) { @@ -301,3 +303,27 @@ public class ResourceAllocationsBeingEdited { } } + +class AllocationResult { + + private final AggregateOfResourceAllocations aggregate; + + private final Integer daysDuration; + + AllocationResult(AggregateOfResourceAllocations aggregate, + Integer daysDuration) { + Validate.notNull(daysDuration); + Validate.notNull(daysDuration); + this.aggregate = aggregate; + this.daysDuration = daysDuration; + } + + public AggregateOfResourceAllocations getAggregate() { + return aggregate; + } + + public Integer getDaysDuration() { + return daysDuration; + } + +}