From 0b97acc372dcbabac2f0d4d981c5d2b9f0342bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Mon, 16 May 2011 17:55:37 +0200 Subject: [PATCH] Calls to reassign wipe out the previous not consolidated assignments This allows to delete the calls to reassign with zero effort. FEA: ItEr74S04BugFixing --- .../planner/entities/IAllocatable.java | 17 ++++++++++ .../planner/entities/ResourceAllocation.java | 17 +++++----- .../entities/SpecificResourceAllocation.java | 33 ++++++++---------- .../SpecificResourceAllocationTest.java | 9 ++--- .../AdvanceConsolidationModel.java | 34 +++++-------------- 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocatable.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocatable.java index 796d38824..4d8493d76 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocatable.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocatable.java @@ -78,8 +78,25 @@ public interface IAllocatable extends IAllocateResourcesPerDay { public IAllocateEffortOnInterval onInterval(IntraDayDate start, IntraDayDate end); + /** + * It allocates the effort specified on the interval from the start, i.e. + * first day not consolidated to the specified end. All previous assignments + * are removed, but the consolidated ones. + * + * @param endExclusive + * @return + */ public IAllocateEffortOnInterval fromStartUntil(LocalDate endExclusive); + /** + * It allocates the effort specified on the interval from the end until the + * start. Being the start the maximum of the provided start and the first + * not consolidated day. All previous assignments are removed, but the + * consolidated ones. + * + * @param endExclusive + * @return + */ public IAllocateEffortOnInterval fromEndUntil(LocalDate start); } \ No newline at end of file diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java index 46bf4bc84..0c166db6b 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java @@ -920,14 +920,8 @@ public abstract class ResourceAllocation extends EffortDuration durationToAssign) { List assignmentsCreated = createAssignments(interval, durationToAssign); - allocateTheWholeAllocation(interval, assignmentsCreated); - } - - private void allocateTheWholeAllocation(AllocationInterval interval, - List assignments) { - resetAllAllocationAssignmentsTo(assignments, - interval.getStartInclusive(), interval.getEndExclusive()); - updateResourcesPerDay(); + ResourceAllocation.this.allocateTheWholeAllocation(interval, + assignmentsCreated); } protected abstract AvailabilityTimeLine getResourcesAvailability(); @@ -1059,6 +1053,13 @@ public abstract class ResourceAllocation extends task.getIntraDayEndDate()); } + protected void allocateTheWholeAllocation(AllocationInterval interval, + List assignments) { + resetAllAllocationAssignmentsTo(assignments, + interval.getStartInclusive(), interval.getEndExclusive()); + updateResourcesPerDay(); + } + protected void resetAllAllocationAssignmentsTo(List assignments, IntraDayDate intraDayStart, IntraDayDate intraDayEnd) { diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java index 072ae7296..d13ba5274 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java @@ -309,21 +309,18 @@ public class SpecificResourceAllocation extends } } - public void allocateKeepingProportions(LocalDate start, - LocalDate endExclusive, EffortDuration effortForInterval) { - AllocationIntervalInsideTask interval = new AllocationIntervalInsideTask( - start, endExclusive); - - EffortDuration sumConsolidated = DayAssignment - .sum(interval - .getConsolidatedAssignmentsOnInterval()); - - if (sumConsolidated.compareTo(effortForInterval) >= 0) { - return; - } - - EffortDuration pendingToReassign = effortForInterval - .minus(sumConsolidated); + /** + * It does an allocation using the provided {@link EffortDuration} in the + * not consolidated part in interval from the first day not consolidated to + * the end provided. All previous not consolidated assignments are removed. + * + * @param effortForNotConsolidatedPart + * @param endExclusive + */ + public void allocateWholeAllocationKeepingProportions( + EffortDuration effortForNotConsolidatedPart, IntraDayDate end) { + AllocationInterval interval = new AllocationInterval( + getIntraDayStartDate(), end); List nonConsolidatedAssignments = interval .getNoConsolidatedAssignmentsOnInterval(); @@ -331,9 +328,9 @@ public class SpecificResourceAllocation extends .create(asSeconds(nonConsolidatedAssignments)); EffortDuration[] effortsPerDay = asEfforts(distributor - .distribute(pendingToReassign.getSeconds())); - - resetAssigmentsForInterval(interval, + .distribute(effortForNotConsolidatedPart.getSeconds())); + allocateTheWholeAllocation( + interval, assignmentsForEfforts(nonConsolidatedAssignments, effortsPerDay)); } diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/SpecificResourceAllocationTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/SpecificResourceAllocationTest.java index 20027393b..c58dd8084 100644 --- a/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/SpecificResourceAllocationTest.java +++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/SpecificResourceAllocationTest.java @@ -782,11 +782,12 @@ public class SpecificResourceAllocationTest { assertThat(specificResourceAllocation.getAssignments(), haveHours(2, 4, 8, 6)); - specificResourceAllocation.allocateKeepingProportions(start, - start.plusDays(2), EffortDuration.hours(9)); + specificResourceAllocation.allocateWholeAllocationKeepingProportions( + EffortDuration.hours(18), + IntraDayDate.startOfDay(start.plusDays(2))); - assertThat(specificResourceAllocation.getAssignments(), haveHours(3, 6, - 8, 6)); + assertThat(specificResourceAllocation.getAssignments(), + haveHours(6, 12)); } @Test diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/consolidations/AdvanceConsolidationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/consolidations/AdvanceConsolidationModel.java index 536d4fe82..fd58064e2 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/consolidations/AdvanceConsolidationModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/consolidations/AdvanceConsolidationModel.java @@ -232,22 +232,20 @@ public class AdvanceConsolidationModel implements IAdvanceConsolidationModel { task.setIntraDayEndDate(date.nextDayAtStart()); } } else { - reassign(resourceAllocation, task.getFirstDayNotConsolidated() - .getDate(), endExclusive, pendingEffort); + reassign(resourceAllocation, endExclusive, pendingEffort); } } } private void reassign(ResourceAllocation resourceAllocation, - LocalDate startInclusive, LocalDate endExclusive, - EffortDuration pendingEffort) { + LocalDate endExclusive, EffortDuration pendingEffort) { if (resourceAllocation instanceof SpecificResourceAllocation) { ((SpecificResourceAllocation) resourceAllocation) - .allocateKeepingProportions(startInclusive, endExclusive, - pendingEffort); + .allocateWholeAllocationKeepingProportions(pendingEffort, + IntraDayDate.startOfDay(endExclusive)); } else { resourceAllocation.withPreviousAssociatedResources() - .onIntervalWithinTask(startInclusive, endExclusive) + .fromStartUntil(endExclusive) .allocate(pendingEffort); } } @@ -281,11 +279,11 @@ public class AdvanceConsolidationModel implements IAdvanceConsolidationModel { return; } - LocalDate taskEndDate = LocalDate.fromDateFields(task.getEndDate()); - LocalDate endExclusive = taskEndDate; if (!consolidation.getConsolidatedValues().isEmpty()) { - endExclusive = consolidation.getConsolidatedValues().last() + LocalDate endExclusive = consolidation.getConsolidatedValues() + .last() .getTaskEndDate(); + task.setEndDate(endExclusive.toDateTimeAtStartOfDay().toDate()); } if (!consolidation.isCalculated()) { ((NonCalculatedConsolidation) consolidation) @@ -301,9 +299,6 @@ public class AdvanceConsolidationModel implements IAdvanceConsolidationModel { task.updateAssignmentsConsolidatedValues(); - LocalDate firstDayNotConsolidated = task.getFirstDayNotConsolidated() - .getDate(); - Set> allResourceAllocations = task .getAllResourceAllocations(); for (ResourceAllocation resourceAllocation : allResourceAllocations) { @@ -312,18 +307,7 @@ public class AdvanceConsolidationModel implements IAdvanceConsolidationModel { EffortDuration pendingEffort = task.getConsolidation() .getNotConsolidated( resourceAllocation.getIntendedTotalAssigment()); - if (!taskEndDate.equals(endExclusive)) { - if ((taskEndDate != null) && (endExclusive != null) - && (taskEndDate.compareTo(endExclusive) <= 0)) { - reassign(resourceAllocation, taskEndDate, endExclusive, - EffortDuration.zero()); - } else { - reassign(resourceAllocation, endExclusive, taskEndDate, - EffortDuration.zero()); - } - task.setEndDate(endExclusive.toDateTimeAtStartOfDay().toDate()); - } - reassign(resourceAllocation, firstDayNotConsolidated, endExclusive, + reassign(resourceAllocation, task.getEndAsLocalDate(), pendingEffort); } }