From 0a51bbdca0109456e1a2c677aaffa8583dce91a2 Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Thu, 3 May 2012 11:45:39 +0200 Subject: [PATCH] Bug #1428: Possible fix Attaching day assignments to resources and detaching them later once the allocation is done as they will be attached in a different method again. FEA: ItEr76S04BugFixing --- .../planner/entities/ResourceAllocation.java | 2 +- .../UntilFillingHoursAllocator.java | 32 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/ResourceAllocation.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/ResourceAllocation.java index 5c2eab504..e9c9fc501 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/ResourceAllocation.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/ResourceAllocation.java @@ -2123,7 +2123,7 @@ public abstract class ResourceAllocation extends getDayAssignmentsState().detachAssignments(); } - void associateAssignmentsToResource() { + public void associateAssignmentsToResource() { for (DayAssignment dayAssignment : getAssignments()) { dayAssignment.associateToResource(); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/allocationalgorithms/UntilFillingHoursAllocator.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/allocationalgorithms/UntilFillingHoursAllocator.java index f94c10808..e1010240a 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/allocationalgorithms/UntilFillingHoursAllocator.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/allocationalgorithms/UntilFillingHoursAllocator.java @@ -29,7 +29,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import org.apache.commons.lang.Validate; import org.joda.time.LocalDate; @@ -89,8 +88,19 @@ public abstract class UntilFillingHoursAllocator { IntraDayDate candidate = untilAllocating(dateFromWhichToAllocate, each.allocation, each.duration); currentResult = pickCurrentOrCandidate(currentResult, candidate); + setNewDataForAllocation(each.allocation, currentResult); + + // This is done in order that new assignments are taken into account + // for the next allocations in the same task + each.allocation.getResourceAllocation() + .associateAssignmentsToResource(); } - setAssignmentsForEachAllocation(currentResult); + // Then we detach the day assignments as they are going to be associated + // again later + for (EffortPerAllocation each : effortPerAllocation) { + each.allocation.getResourceAllocation().detach(); + } + return currentResult; } @@ -228,22 +238,16 @@ public abstract class UntilFillingHoursAllocator { } } - private void setAssignmentsForEachAllocation(IntraDayDate resultDate) { - for (Entry> entry : resultAssignments - .entrySet()) { - setNewDataForAllocation(entry, resultDate); - } - } - private void setNewDataForAllocation( - Entry> entry, + ResourcesPerDayModification resourcesPerDayModification, IntraDayDate resultDate) { @SuppressWarnings("unchecked") - ResourceAllocation allocation = (ResourceAllocation) entry - .getKey().getBeingModified(); - ResourcesPerDay resourcesPerDay = entry.getKey().getGoal(); + ResourceAllocation allocation = (ResourceAllocation) resourcesPerDayModification + .getBeingModified(); + ResourcesPerDay resourcesPerDay = resourcesPerDayModification.getGoal(); @SuppressWarnings("unchecked") - List value = (List) entry.getValue(); + List value = (List) resultAssignments + .get(resourcesPerDayModification); setNewDataForAllocation(allocation, resultDate, resourcesPerDay, value); }