From d27fabbbebdd87e0ec23ec4002f76c7f184063d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Thu, 8 Nov 2012 19:28:06 +0100 Subject: [PATCH] Bug #1413: Use IntraDayDate when doing allocation When doing the allocation that calculates RESOURCES_PER_DAY use IntraDayDates instead of LocalDate so if the first day of the allocation is partially allocated, the part free is used. FEA: ItEr77S04BugFixing --- .../planner/entities/IAllocatable.java | 11 ++++++++++ .../planner/entities/ResourceAllocation.java | 20 ++++++++++++------- .../entities/SpecificResourceAllocation.java | 6 ++++++ .../business/planner/entities/Task.java | 4 ++-- .../EffortModification.java | 13 ++++++------ .../allocation/AllocationRowsHandler.java | 5 +++-- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/IAllocatable.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/IAllocatable.java index 73ddd754f..1c871c0b7 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/IAllocatable.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/IAllocatable.java @@ -109,4 +109,15 @@ public interface IAllocatable extends IAllocateResourcesPerDay { */ public IAllocateEffortOnInterval fromEndUntil(LocalDate start); + /** + * 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(IntraDayDate start); + } 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 b07c2529d..5a9852d3f 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 @@ -486,20 +486,20 @@ public abstract class ResourceAllocation extends } public void allocate() { - allocateUntil(new LocalDate(task.getEndDate())); + allocateUntil(task.getIntraDayEndDate()); } - public void allocateUntil(LocalDate end) { + public void allocateUntil(IntraDayDate end) { Validate.notNull(end); - checkStartLessOrEqualToEnd(task.getStartAsLocalDate(), end); + checkStartLessOrEqualToEnd(task.getIntraDayStartDate(), end); for (EffortModification each : hoursModifications) { each.allocateUntil(end); } } - public void allocateFromEndUntil(LocalDate start) { + public void allocateFromEndUntil(IntraDayDate start) { Validate.notNull(start); - checkStartLessOrEqualToEnd(start, task.getEndAsLocalDate()); + checkStartLessOrEqualToEnd(start, task.getIntraDayEndDate()); for (EffortModification each : hoursModifications) { each.allocateFromEndUntil(start); } @@ -939,8 +939,14 @@ public abstract class ResourceAllocation extends @Override public IAllocateEffortOnInterval fromEndUntil(final LocalDate start) { - final AllocationInterval interval = new AllocationInterval( - IntraDayDate.startOfDay(start), task.getIntraDayEndDate()); + return fromEndUntil(IntraDayDate.startOfDay(start)); + + } + + @Override + public IAllocateEffortOnInterval fromEndUntil(IntraDayDate start) { + final AllocationInterval interval = new AllocationInterval(start, + task.getIntraDayEndDate()); return new IAllocateEffortOnInterval() { @Override diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/SpecificResourceAllocation.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/SpecificResourceAllocation.java index 16b3cc90b..3df3ed45f 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/SpecificResourceAllocation.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/SpecificResourceAllocation.java @@ -191,6 +191,11 @@ public class SpecificResourceAllocation extends return new SpecificAssignmentsAllocator().fromEndUntil(start); } + @Override + public IAllocateEffortOnInterval fromEndUntil(IntraDayDate start) { + return new SpecificAssignmentsAllocator().fromEndUntil(start); + } + private final class SpecificAssignmentsAllocator extends AssignmentsAllocator { @@ -211,6 +216,7 @@ public class SpecificResourceAllocation extends return day.limitCapacity(getAllocationCalendar() .getCapacityWithOvertime(day.getDate())); } + } public IEffortDistributor createEffortDistributor() { diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/Task.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/Task.java index dd92e8849..506e84b7b 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/Task.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/Task.java @@ -824,8 +824,8 @@ public class Task extends TaskElement implements ITaskPositionConstrained { LOG.warn("all allocations for task " + this + " can't be used"); return; } - ResourceAllocation.allocatingHours(hoursModified) - .allocateUntil(new LocalDate(getEndDate())); + ResourceAllocation.allocatingHours(hoursModified).allocateUntil( + getIntraDayEndDate()); break; default: throw new RuntimeException("cant handle: " + calculatedValue); diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/allocationalgorithms/EffortModification.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/allocationalgorithms/EffortModification.java index c31a4a774..8876d20f6 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/allocationalgorithms/EffortModification.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/allocationalgorithms/EffortModification.java @@ -33,6 +33,7 @@ import org.libreplan.business.planner.entities.SpecificResourceAllocation; import org.libreplan.business.resources.daos.IResourcesSearcher; import org.libreplan.business.resources.entities.Resource; import org.libreplan.business.workingday.EffortDuration; +import org.libreplan.business.workingday.IntraDayDate; /** * @author Óscar González Fernández @@ -51,14 +52,14 @@ public abstract class EffortModification extends AllocationModification { } @Override - public void allocateUntil(LocalDate end) { + public void allocateUntil(IntraDayDate end) { genericAllocation.forResources(getResources()) .fromStartUntil(end) .allocate(getEffort()); } @Override - public void allocateFromEndUntil(LocalDate start) { + public void allocateFromEndUntil(IntraDayDate start) { genericAllocation.forResources(getResources()) .fromEndUntil(start) .allocate(getEffort()); @@ -81,12 +82,12 @@ public abstract class EffortModification extends AllocationModification { } @Override - public void allocateUntil(LocalDate end) { + public void allocateUntil(IntraDayDate end) { specific.fromStartUntil(end).allocate(getEffort()); } @Override - public void allocateFromEndUntil(LocalDate start) { + public void allocateFromEndUntil(IntraDayDate start) { specific.fromEndUntil(start).allocate(getEffort()); } @@ -142,9 +143,9 @@ public abstract class EffortModification extends AllocationModification { return new LocalDate(getBeingModified().getTask().getStartDate()); } - public abstract void allocateUntil(LocalDate end); + public abstract void allocateUntil(IntraDayDate end); - public abstract void allocateFromEndUntil(LocalDate start); + public abstract void allocateFromEndUntil(IntraDayDate start); @Override public boolean satisfiesModificationRequested() { diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/AllocationRowsHandler.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/AllocationRowsHandler.java index a1ce03b4c..5f287a753 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/AllocationRowsHandler.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/AllocationRowsHandler.java @@ -50,6 +50,7 @@ import org.libreplan.business.resources.entities.ResourceEnum; import org.libreplan.business.scenarios.entities.Scenario; import org.libreplan.business.workingday.EffortDuration; import org.libreplan.business.workingday.EffortDuration.IEffortFrom; +import org.libreplan.business.workingday.IntraDayDate; public class AllocationRowsHandler { @@ -342,10 +343,10 @@ public class AllocationRowsHandler { requestedToRemove); if (isForwardsAllocation()) { ResourceAllocation.allocatingHours(hours).allocateUntil( - formBinder.getAllocationEnd()); + IntraDayDate.startOfDay(formBinder.getAllocationEnd())); } else { ResourceAllocation.allocatingHours(hours).allocateFromEndUntil( - formBinder.getAllocationStart()); + IntraDayDate.startOfDay(formBinder.getAllocationStart())); } return hours; }