From 27aabfa7bba2dbdba3bcdf48918297fe177306a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Mon, 4 Apr 2011 17:54:26 +0200 Subject: [PATCH] [Bug #943] Fix bug When an allocation can not be satisfied keep the old resources per day and not update them from data. Thus when moving a task back to a place where it's satisfied the resources per day of the last satisfied allocation are used. --- .../planner/entities/ResourceAllocation.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 364794a63..9926093e9 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 @@ -322,6 +322,7 @@ public abstract class ResourceAllocation extends IntraDayDate resultDate, ResourcesPerDay resourcesPerDay, List dayAssignments) { Task task = AllocationsSpecified.this.task; + allocation.setIntendedResourcesPerDay(resourcesPerDay); if (isForwardScheduling()) { allocation.resetAllAllocationAssignmentsTo( dayAssignments, @@ -528,6 +529,9 @@ public abstract class ResourceAllocation extends } protected void updateResourcesPerDay() { + if (!isSatisfied()) { + return; + } ResourcesPerDay resourcesPerDay = calculateResourcesPerDayFromAssignments(getAssignments()); if (resourcesPerDay == null) { this.resourcesPerDay = ResourcesPerDay.amount(0); @@ -540,6 +544,12 @@ public abstract class ResourceAllocation extends this.resourcesPerDay = ResourcesPerDay.amount(amount); } + private void setIntendedResourcesPerDay(ResourcesPerDay resourcesPerDay) { + Validate.notNull(resourcesPerDay); + Validate.isTrue(!resourcesPerDay.isZero()); + this.resourcesPerDay = resourcesPerDay; + } + public ResourceAllocation(Task task) { this(task, null); } @@ -629,6 +639,7 @@ public abstract class ResourceAllocation extends @Override public final void allocate(ResourcesPerDay resourcesPerDay) { Task currentTask = getTask(); + setIntendedResourcesPerDay(resourcesPerDay); List assignmentsCreated = createAssignments(resourcesPerDay, currentTask.getIntraDayStartDate(), currentTask.getIntraDayEndDate()); @@ -645,7 +656,7 @@ public abstract class ResourceAllocation extends assignmentsCreated.addAll(distributeForDay(day.getDate(), durationForDay)); } - return assignmentsCreated; + return onlyNonZeroHours(assignmentsCreated); } @Override