Extract common functionality into methods

FEA: ItEr74S04BugFixing
This commit is contained in:
Óscar González Fernández 2011-05-16 18:37:44 +02:00
parent 0b97acc372
commit 71235e2c8e

View file

@ -25,6 +25,8 @@ import static org.navalplanner.web.I18nHelper._;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
@ -211,30 +213,30 @@ public class AdvanceConsolidationModel implements IAdvanceConsolidationModel {
Set<ResourceAllocation<?>> allResourceAllocations = task
.getAllResourceAllocations();
for (ResourceAllocation<?> resourceAllocation : allResourceAllocations) {
LocalDate endExclusive = LocalDate
.fromDateFields(task.getEndDate());
EffortDuration pendingEffort = consolidation
.getNotConsolidated(resourceAllocation
.getIntendedTotalAssigment());
resourceAllocation
.setOnDayAssignmentRemoval(new DetachDayAssignmentOnRemoval());
withDetachOnDayAssignmentRemoval(allResourceAllocations);
LocalDate endExclusive = LocalDate.fromDateFields(task.getEndDate());
if (value.getDate().compareTo(endExclusive.minusDays(1)) >= 0) {
if (!AllocationsSpecified.isZero(resourceAllocation
.asResourcesPerDayModification().getGoal().getAmount())) {
IntraDayDate date = ResourceAllocation.allocating(
Arrays.asList(resourceAllocation
.asResourcesPerDayModification()))
.untilAllocating(pendingEffort);
task.setIntraDayEndDate(date.nextDayAtStart());
}
reassignExpandingTask(allResourceAllocations);
} else {
reassign(resourceAllocation, endExclusive, pendingEffort);
reassignAll(endExclusive, allResourceAllocations);
}
}
private void withDetachOnDayAssignmentRemoval(
Collection<? extends ResourceAllocation<?>> allocations) {
for (ResourceAllocation<?> each : allocations) {
each.setOnDayAssignmentRemoval(new DetachDayAssignmentOnRemoval());
}
}
private void reassignAll(LocalDate endExclusive,
Collection<? extends ResourceAllocation<?>> allocations) {
for (ResourceAllocation<?> each : allocations) {
EffortDuration pendingEffort = consolidation
.getNotConsolidated(each.getIntendedTotalAssigment());
reassign(each, endExclusive, pendingEffort);
}
}
private void reassign(ResourceAllocation<?> resourceAllocation,
@ -250,6 +252,28 @@ public class AdvanceConsolidationModel implements IAdvanceConsolidationModel {
}
}
private void reassignExpandingTask(
Collection<? extends ResourceAllocation<?>> allResourceAllocations) {
List<IntraDayDate> ends = new ArrayList<IntraDayDate>();
for (ResourceAllocation<?> resourceAllocation : allResourceAllocations) {
if (!AllocationsSpecified.isZero(resourceAllocation
.asResourcesPerDayModification().getGoal().getAmount())) {
EffortDuration pendingEffort = consolidation
.getNotConsolidated(resourceAllocation
.getIntendedTotalAssigment());
IntraDayDate date = ResourceAllocation.allocating(
Arrays.asList(resourceAllocation
.asResourcesPerDayModification()))
.untilAllocating(pendingEffort);
ends.add(date);
}
}
if (!ends.isEmpty()) {
task.setIntraDayEndDate(Collections.max(ends));
}
}
private ConsolidatedValue createNewConsolidatedValue(
AdvanceConsolidationDTO dto) {
if (consolidation != null && task != null) {
@ -301,15 +325,9 @@ public class AdvanceConsolidationModel implements IAdvanceConsolidationModel {
Set<ResourceAllocation<?>> allResourceAllocations = task
.getAllResourceAllocations();
for (ResourceAllocation<?> resourceAllocation : allResourceAllocations) {
resourceAllocation
.setOnDayAssignmentRemoval(new DetachDayAssignmentOnRemoval());
EffortDuration pendingEffort = task.getConsolidation()
.getNotConsolidated(
resourceAllocation.getIntendedTotalAssigment());
reassign(resourceAllocation, task.getEndAsLocalDate(),
pendingEffort);
}
withDetachOnDayAssignmentRemoval(allResourceAllocations);
reassignAll(task.getEndAsLocalDate(), allResourceAllocations);
}
private void updateConsolidationInAdvanceIfIsNeeded() {