ItEr41S11CUConfiguracionMaquinasItEr40S15: When moving a task the derived allocations are recalculated

This commit is contained in:
Óscar González Fernández 2009-12-28 11:47:31 +01:00
parent f4645d73fd
commit 6db234ea40
2 changed files with 38 additions and 1 deletions

View file

@ -163,10 +163,10 @@ public class DerivedAllocation extends BaseEntity {
public void resetAssignmentsTo(LocalDate startInclusive,
LocalDate endExclusive, List<DerivedDayAssignment> newAssignments) {
checkAreValid(newAssignments);
List<DerivedDayAssignment> toBeRemoved = DayAssignment.getAtInterval(
getAssignments(), startInclusive, endExclusive);
assignments.removeAll(toBeRemoved);
checkAreValid(newAssignments);
assignments.addAll(DayAssignment.getAtInterval(newAssignments,
startInclusive, endExclusive));
}

View file

@ -39,6 +39,7 @@ import org.navalplanner.business.orders.entities.AggregatedHoursGroup;
import org.navalplanner.business.orders.entities.HoursGroup;
import org.navalplanner.business.orders.entities.OrderElement;
import org.navalplanner.business.orders.entities.TaskSource;
import org.navalplanner.business.planner.entities.DerivedAllocationGenerator.IWorkerFinder;
import org.navalplanner.business.planner.entities.allocationalgorithms.HoursModification;
import org.navalplanner.business.planner.entities.allocationalgorithms.ResourcesPerDayModification;
import org.navalplanner.business.resources.entities.Criterion;
@ -337,12 +338,48 @@ public class Task extends TaskElement {
default:
throw new RuntimeException("cant handle: " + calculatedValue);
}
updateDerived(copied);
mergeAllocation(asLocalDate(getStartDate()), asLocalDate(getEndDate()),
calculatedValue, Collections
.<ResourceAllocation<?>> emptyList(), copied,
Collections.<ResourceAllocation<?>> emptyList());
}
private void updateDerived(List<ModifiedAllocation> allocations) {
for (ModifiedAllocation each : allocations) {
ResourceAllocation<?> original = each.getOriginal();
if (!original.getDerivedAllocations().isEmpty()) {
IWorkerFinder workersFinder = createFromExistentDerivedAllocationsFinder(original);
each.getModification().createDerived(workersFinder);
}
}
}
private IWorkerFinder createFromExistentDerivedAllocationsFinder(
ResourceAllocation<?> original) {
Set<DerivedAllocation> derivedAllocations = original
.getDerivedAllocations();
final Set<Worker> allWorkers = new HashSet<Worker>();
for (DerivedAllocation each : derivedAllocations) {
allWorkers.addAll(Resource.workers(each.getResources()));
}
return new IWorkerFinder() {
@Override
public Collection<Worker> findWorkersMatching(
Collection<? extends Criterion> requiredCriterions) {
Collection<Worker> result = new ArrayList<Worker>();
for (Worker each : allWorkers) {
if (each.satisfiesCriterions(requiredCriterions)) {
result.add(each);
}
}
return result;
}
};
}
private LocalDate asLocalDate(Date date) {
return new LocalDate(date.getTime());
}