[Bug #943] Avoid to reassign allocations with zero resources per day
FEA: ItEr73S04BugFixing
This commit is contained in:
parent
c4d85187ec
commit
ee2af5828f
5 changed files with 30 additions and 16 deletions
|
|
@ -284,12 +284,6 @@ public class GenericResourceAllocation extends
|
|||
return allocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourcesPerDayModification asResourcesPerDayModification() {
|
||||
return ResourcesPerDayModification.create(this,
|
||||
getIntendedResourcesPerDay(), getAssociatedResources());
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoursModification asHoursModification() {
|
||||
return HoursModification.create(this, getIntendedHours(),
|
||||
|
|
|
|||
|
|
@ -594,7 +594,21 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
public abstract ResourcesPerDayModification withDesiredResourcesPerDay(
|
||||
ResourcesPerDay resourcesPerDay);
|
||||
|
||||
public abstract ResourcesPerDayModification asResourcesPerDayModification();
|
||||
public final ResourcesPerDayModification asResourcesPerDayModification() {
|
||||
if (getIntendedResourcesPerDay().isZero()) {
|
||||
return null;
|
||||
}
|
||||
if (this instanceof GenericResourceAllocation) {
|
||||
GenericResourceAllocation generic = (GenericResourceAllocation) this;
|
||||
return ResourcesPerDayModification.create(generic,
|
||||
getIntendedResourcesPerDay(), getAssociatedResources());
|
||||
} else if (this instanceof SpecificResourceAllocation) {
|
||||
SpecificResourceAllocation specific = (SpecificResourceAllocation) this;
|
||||
return ResourcesPerDayModification.create(specific,
|
||||
getIntendedResourcesPerDay());
|
||||
}
|
||||
throw new RuntimeException("can't handle: " + this.getClass());
|
||||
}
|
||||
|
||||
public abstract HoursModification asHoursModification();
|
||||
|
||||
|
|
|
|||
|
|
@ -243,12 +243,6 @@ public class SpecificResourceAllocation extends
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourcesPerDayModification asResourcesPerDayModification() {
|
||||
return ResourcesPerDayModification.create(this,
|
||||
getIntendedResourcesPerDay());
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoursModification asHoursModification() {
|
||||
return HoursModification.create(this, getIntendedHours());
|
||||
|
|
|
|||
|
|
@ -723,6 +723,11 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
|||
Direction direction, List<ResourceAllocation<?>> toBeModified) {
|
||||
List<ResourcesPerDayModification> allocations = strategy
|
||||
.getResourcesPerDayModified(toBeModified);
|
||||
if (allocations.isEmpty()) {
|
||||
LOG.warn("all allocations for task " + this
|
||||
+ " have no valid data that could be used");
|
||||
return;
|
||||
}
|
||||
switch (calculatedValue) {
|
||||
case NUMBER_OF_HOURS:
|
||||
ResourceAllocation.allocating(allocations).allocateOnTaskLength();
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ 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;
|
||||
|
|
@ -198,8 +199,9 @@ public abstract class ResourcesPerDayModification extends
|
|||
public static ResourcesPerDayModification create(
|
||||
GenericResourceAllocation resourceAllocation,
|
||||
ResourcesPerDay resourcesPerDay, List<? extends Resource> resources) {
|
||||
return new OnGenericAllocation(resourceAllocation,
|
||||
resourcesPerDay, resources);
|
||||
Validate.isTrue(!resourcesPerDay.isZero());
|
||||
return new OnGenericAllocation(resourceAllocation, resourcesPerDay,
|
||||
resources);
|
||||
}
|
||||
|
||||
public static List<ResourcesPerDayModification> withNewResources(
|
||||
|
|
@ -215,6 +217,7 @@ public abstract class ResourcesPerDayModification extends
|
|||
public static ResourcesPerDayModification create(
|
||||
SpecificResourceAllocation resourceAllocation,
|
||||
ResourcesPerDay resourcesPerDay) {
|
||||
Validate.isTrue(!resourcesPerDay.isZero());
|
||||
return new OnSpecificAllocation(resourceAllocation,
|
||||
resourcesPerDay, Collections.singletonList(resourceAllocation
|
||||
.getResource()));
|
||||
|
|
@ -225,7 +228,11 @@ public abstract class ResourcesPerDayModification extends
|
|||
IResourceDAO resourcesDAO) {
|
||||
List<ResourcesPerDayModification> result = new ArrayList<ResourcesPerDayModification>();
|
||||
for (ResourceAllocation<?> resourceAllocation : allocations) {
|
||||
result.add(resourceAllocation.asResourcesPerDayModification());
|
||||
ResourcesPerDayModification modification = resourceAllocation
|
||||
.asResourcesPerDayModification();
|
||||
if (modification != null) {
|
||||
result.add(modification);
|
||||
}
|
||||
}
|
||||
return ensureNoOneWithoutAssociatedResources(result, resourcesDAO);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue