ItEr46S12CUVisualizacionResponsabilidadesTRaballoNaPlanificacion: Fixing infinite loop problem when calculating end date.

Using IWorkHours#thereAreAvailableHoursFrom is checked if there are
enough hours to complete the task. This avoids infinite loop
problem. The ResourceAllocation is marked as invalid.
This commit is contained in:
Óscar González Fernández 2010-02-03 16:31:03 +01:00
parent 4c3c072d4f
commit 16b2104ca6
2 changed files with 32 additions and 0 deletions

View file

@ -200,6 +200,24 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
allocation.setResourcesPerDay(resourcesPerDay);
allocation.resetGenericAssignmentsTo(dayAssignments);
}
@Override
protected boolean thereAreAvailableHoursFrom(
LocalDate start,
ResourcesPerDayModification resourcesPerDayModification,
int hoursToAllocate) {
IWorkHours workHoursPerDay = resourcesPerDayModification
.getBeingModified().getWorkHoursPerDay();
ResourcesPerDay resourcesPerDay = resourcesPerDayModification
.getGoal();
return workHoursPerDay.thereAreAvailableHoursFrom(start,
resourcesPerDay, hoursToAllocate);
}
@Override
protected void markUnsatisfied(ResourceAllocation<?> allocation) {
allocation.markAsUnsatisfied();
}
};
return allocator.untilAllocating(hoursToAllocate);
}
@ -530,6 +548,9 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
@Override
public boolean thereAreAvailableHoursFrom(LocalDate date,
ResourcesPerDay resourcesPerDay, int hours) {
if (getTaskCalendar() == null) {
return true;
}
return getTaskCalendar().thereAreAvailableHoursFrom(date,
resourcesPerDay, hours);
}

View file

@ -75,6 +75,11 @@ public abstract class AllocatorForSpecifiedResourcesPerDayAndHours {
Integer hoursToAllocate) {
int hoursRemaining = hoursToAllocate;
LocalDate start = new LocalDate(task.getStartDate().getTime());
if (!thereAreAvailableHoursFrom(start, resourcesPerDayModification,
hoursToAllocate)) {
markUnsatisfied(resourcesPerDayModification.getBeingModified());
return 0;
}
int day = 0;
while (hoursRemaining > 0) {
LocalDate current = start.plusDays(day);
@ -105,6 +110,12 @@ public abstract class AllocatorForSpecifiedResourcesPerDayAndHours {
protected abstract List<DayAssignment> createAssignmentsAtDay(
ResourcesPerDayModification allocation, LocalDate day, Integer limit);
protected abstract boolean thereAreAvailableHoursFrom(LocalDate start,
ResourcesPerDayModification resourcesPerDayModification,
int hoursToAllocate);
protected abstract void markUnsatisfied(ResourceAllocation<?> beingModified);
private int assignForDay(
ResourcesPerDayModification resourcesPerDayModification,
LocalDate day, int remaining) {