It avoids exception when doing a reassignation and there is an
unsatisfied generic allocation. Now in that case new resources mathing
the criterions are queried.

FEA: ItEr66S04BugFixing
This commit is contained in:
Óscar González Fernández 2010-12-29 18:53:54 +01:00
parent cfc3551e31
commit 3ca8b84b8d
4 changed files with 49 additions and 14 deletions

View file

@ -408,6 +408,13 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
private static abstract class AllocationModificationStrategy {
protected final IResourceDAO resourceDAO;
public AllocationModificationStrategy(IResourceDAO resourceDAO) {
Validate.notNull(resourceDAO);
this.resourceDAO = resourceDAO;
}
public abstract List<ResourcesPerDayModification> getResourcesPerDayModified(
List<ResourceAllocation<?>> allocations);
@ -419,26 +426,30 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
private static class WithTheSameHoursAndResourcesPerDay extends
AllocationModificationStrategy {
public WithTheSameHoursAndResourcesPerDay(IResourceDAO resourceDAO) {
super(resourceDAO);
}
@Override
public List<HoursModification> getHoursModified(
List<ResourceAllocation<?>> allocations) {
return HoursModification.fromExistent(allocations);
return HoursModification.fromExistent(allocations, resourceDAO);
}
@Override
public List<ResourcesPerDayModification> getResourcesPerDayModified(
List<ResourceAllocation<?>> allocations) {
return ResourcesPerDayModification.fromExistent(allocations);
return ResourcesPerDayModification.fromExistent(allocations,
resourceDAO);
}
}
private static class WithAnotherResources extends
AllocationModificationStrategy {
private final IResourceDAO resourceDAO;
WithAnotherResources(IResourceDAO resourceDAO) {
this.resourceDAO = resourceDAO;
public WithAnotherResources(IResourceDAO resourceDAO) {
super(resourceDAO);
}
@Override
@ -479,7 +490,7 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
private void doReassignment(Direction direction) {
reassign(scenario, direction,
new WithTheSameHoursAndResourcesPerDay());
new WithTheSameHoursAndResourcesPerDay(resourceDAO));
}
@Override

View file

@ -42,6 +42,25 @@ public abstract class AllocationModification {
return result;
}
/**
* It ensures that the provided allocations have at least one associated
* resource. A {@link AllocationModification} doesn't have associated
* resources when creating an {@link AllocationModification} from a
* unsatisfied generic allocation.
*/
protected static <T extends AllocationModification> List<T> ensureNoOneWithoutAssociatedResources(
Collection<? extends T> modifications, IResourceDAO resourceDAO) {
List<T> result = new ArrayList<T>();
for (T each : modifications) {
if (each.hasNoResources()) {
each.withNewResources(resourceDAO);
}
assert !each.hasNoResources();
result.add(each);
}
return result;
}
private final ResourceAllocation<?> beingModified;
private List<Resource> resourcesOnWhichApplyAllocation;
@ -52,6 +71,10 @@ public abstract class AllocationModification {
.unmodifiableList(new ArrayList<Resource>(resources));
}
private boolean hasNoResources() {
return resourcesOnWhichApplyAllocation.isEmpty();
}
protected void withNewResources(IResourceDAO resourceDAO) {
resourcesOnWhichApplyAllocation = beingModified
.querySuitableResources(resourceDAO);

View file

@ -99,17 +99,18 @@ public abstract class HoursModification extends AllocationModification {
}
public static List<HoursModification> fromExistent(
Collection<? extends ResourceAllocation<?>> allocations) {
Collection<? extends ResourceAllocation<?>> allocations,
IResourceDAO resourceDAO) {
List<HoursModification> result = new ArrayList<HoursModification>();
for (ResourceAllocation<?> resourceAllocation : allocations) {
result.add(resourceAllocation.asHoursModification());
}
return result;
return ensureNoOneWithoutAssociatedResources(result, resourceDAO);
}
public static List<HoursModification> withNewResources(
List<ResourceAllocation<?>> allocations, IResourceDAO resourceDAO) {
List<HoursModification> result = fromExistent(allocations);
List<HoursModification> result = fromExistent(allocations, resourceDAO);
for (HoursModification each : result) {
each.withNewResources(resourceDAO);
}

View file

@ -27,7 +27,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.joda.time.LocalDate;
import org.navalplanner.business.calendars.entities.AvailabilityTimeLine;
import org.navalplanner.business.calendars.entities.CombinedWorkHours;
@ -59,7 +58,6 @@ public abstract class ResourcesPerDayModification extends
ResourcesPerDay resourcesPerDay,
Collection<? extends Resource> resources) {
super(resourceAllocation, resourcesPerDay, resources);
Validate.isTrue(!resources.isEmpty());
this.genericAllocation = resourceAllocation;
}
@ -196,7 +194,8 @@ public abstract class ResourcesPerDayModification extends
public static List<ResourcesPerDayModification> withNewResources(
List<ResourceAllocation<?>> allocations, IResourceDAO resourceDAO) {
List<ResourcesPerDayModification> result = fromExistent(allocations);
List<ResourcesPerDayModification> result = fromExistent(allocations,
resourceDAO);
for (ResourcesPerDayModification each : result) {
each.withNewResources(resourceDAO);
}
@ -212,12 +211,13 @@ public abstract class ResourcesPerDayModification extends
}
public static List<ResourcesPerDayModification> fromExistent(
Collection<? extends ResourceAllocation<?>> allocations) {
Collection<? extends ResourceAllocation<?>> allocations,
IResourceDAO resourcesDAO) {
List<ResourcesPerDayModification> result = new ArrayList<ResourcesPerDayModification>();
for (ResourceAllocation<?> resourceAllocation : allocations) {
result.add(resourceAllocation.asResourcesPerDayModification());
}
return result;
return ensureNoOneWithoutAssociatedResources(result, resourcesDAO);
}
protected static ICalendar calendarFor(Resource associatedResource) {