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
This commit is contained in:
Óscar González Fernández 2012-11-08 19:28:06 +01:00 committed by Manuel Rego Casasnovas
parent af5d2b2776
commit d27fabbbeb
6 changed files with 42 additions and 17 deletions

View file

@ -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);
}

View file

@ -486,20 +486,20 @@ public abstract class ResourceAllocation<T extends DayAssignment> 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<T extends DayAssignment> 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

View file

@ -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<SpecificDayAssignment> createEffortDistributor() {

View file

@ -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);

View file

@ -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 <ogonzalez@igalia.com>
@ -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() {

View file

@ -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;
}