Improve the stickiness of the parameters specified by the user

After doing an allocation if the task was moved to a place where it
cannot be satisfied the parameters specified by the user were
overriden with zero like values.

Now it keeps the fields originalTotalAssignment and resourcesPerDay so
if the allocation can be satisfied again it uses the original values.

FEA: ItEr66S04BugFixing
This commit is contained in:
Óscar González Fernández 2010-12-28 20:25:21 +01:00
parent 3f5f8b4332
commit 207ba45e5e
6 changed files with 51 additions and 12 deletions

View file

@ -48,6 +48,11 @@ public class AggregateOfResourceAllocations {
ResourceAllocation.getSatisfied(allocations));
}
public static AggregateOfResourceAllocations createFromAll(
Collection<? extends ResourceAllocation<?>> allocations) {
return new AggregateOfResourceAllocations(allocations);
}
private Set<ResourceAllocation<?>> resourceAllocations;
private AggregateOfResourceAllocations(
@ -66,6 +71,14 @@ public class AggregateOfResourceAllocations {
return sum;
}
public int getIntendedHours() {
int sum = 0;
for (ResourceAllocation<?> resourceAllocation : resourceAllocations) {
sum += resourceAllocation.getIntendedHours();
}
return sum;
}
public Map<ResourceAllocation<?>, ResourcesPerDay> getResourcesPerDay() {
HashMap<ResourceAllocation<?>, ResourcesPerDay> result = new HashMap<ResourceAllocation<?>, ResourcesPerDay>();
for (ResourceAllocation<?> r : resourceAllocations) {

View file

@ -324,12 +324,12 @@ public class GenericResourceAllocation extends
@Override
public ResourcesPerDayModification asResourcesPerDayModification() {
return ResourcesPerDayModification.create(this,
getNonConsolidatedResourcePerDay(), getAssociatedResources());
getIntendedResourcesPerDay(), getAssociatedResources());
}
@Override
public HoursModification asHoursModification() {
return HoursModification.create(this, getAssignedHours(),
return HoursModification.create(this, getIntendedHours(),
getAssociatedResources());
}

View file

@ -547,6 +547,9 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
}
private void updateOriginalTotalAssigment() {
if (!isSatisfied()) {
return;
}
if ((task.getConsolidation() == null)
|| (task.getConsolidation().getConsolidatedValues().isEmpty())) {
originalTotalAssignment = getNonConsolidatedHours();
@ -1031,6 +1034,13 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
return DayAssignment.sum(getAssignments()).roundToHours();
}
protected int getIntendedHours() {
if (isUnsatisfied()) {
return originalTotalAssignment;
}
return getAssignedHours();
}
@OnCopy(Strategy.IGNORE)
private DayAssignmentsState assignmentsState;
@ -1390,6 +1400,18 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
return calculateResourcesPerDayFromAssignments(getNonConsolidatedAssignments());
}
/**
* Calculates the intended resources per day for this allocation. If the
* allocation is not satisfied cannot be calculated on the current
* assignment values and must be retrieved from the value in the field.
*/
protected ResourcesPerDay getIntendedResourcesPerDay() {
if (isUnsatisfied()) {
return getResourcesPerDay();
}
return getNonConsolidatedResourcePerDay();
}
public ResourcesPerDay getConsolidatedResourcePerDay() {
return calculateResourcesPerDayFromAssignments(getConsolidatedAssignments());
}
@ -1548,8 +1570,10 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
}
switchToScenario(scenario);
mergeAssignments(modifications);
updateOriginalTotalAssigment();
updateResourcesPerDay();
if (modifications.isSatisfied()) {
updateOriginalTotalAssigment();
updateResourcesPerDay();
}
setWithoutApply(modifications.getAssignmentFunction());
mergeDerivedAllocations(scenario, modifications.getDerivedAllocations());
}

View file

@ -244,12 +244,12 @@ public class SpecificResourceAllocation extends
@Override
public ResourcesPerDayModification asResourcesPerDayModification() {
return ResourcesPerDayModification.create(this,
getNonConsolidatedResourcePerDay());
getIntendedResourcesPerDay());
}
@Override
public HoursModification asHoursModification() {
return HoursModification.create(this, getAssignedHours());
return HoursModification.create(this, getIntendedHours());
}
@Override

View file

@ -100,7 +100,6 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
private Set<ResourceAllocation<?>> resourceAllocations = new HashSet<ResourceAllocation<?>>();
@Valid
@SuppressWarnings("unused")
private Set<ResourceAllocation<?>> getResourceAlloations() {
return new HashSet<ResourceAllocation<?>>(resourceAllocations);
}
@ -157,6 +156,11 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
.getTotalHours();
}
private int getTotalIntendedHours() {
return AggregateOfResourceAllocations
.createFromAll(resourceAllocations).getIntendedHours();
}
public int getTotalHours() {
return (getTaskSource() != null) ? getTaskSource().getTotalHours() : 0;
}
@ -627,7 +631,7 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
return;
}
List<ModifiedAllocation> copied = ModifiedAllocation.copy(onScenario,
getSatisfiedResourceAllocations());
getResourceAlloations());
List<ResourceAllocation<?>> toBeModified = ModifiedAllocation
.modified(copied);
if (toBeModified.isEmpty()) {
@ -653,7 +657,7 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
break;
case END_DATE:
IntraDayDate date = ResourceAllocation.allocating(allocations)
.untilAllocating(direction, getAssignedHours());
.untilAllocating(direction, getTotalIntendedHours());
if (direction == Direction.FORWARD) {
setIntraDayEndDate(date);
} else {

View file

@ -215,9 +215,7 @@ public abstract class ResourcesPerDayModification extends
Collection<? extends ResourceAllocation<?>> allocations) {
List<ResourcesPerDayModification> result = new ArrayList<ResourcesPerDayModification>();
for (ResourceAllocation<?> resourceAllocation : allocations) {
Validate.isTrue(resourceAllocation.hasAssignments());
ResourcesPerDay perDay = resourceAllocation
.getResourcesPerDay();
ResourcesPerDay perDay = resourceAllocation.getResourcesPerDay();
Validate.notNull(perDay);
result.add(resourceAllocation.asResourcesPerDayModification());
}