Take into account the allocation direction

The scheduling window must do the scheduling according to the last
allocation direction. The start and end dates are updated depending on
the type of scheduling done.

FEA: ItEr66S04BugFixing
This commit is contained in:
Óscar González Fernández 2010-12-22 18:59:25 +01:00
parent 621d72508e
commit fc01b5d223
4 changed files with 74 additions and 17 deletions

View file

@ -831,9 +831,14 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
}
public Integer getWorkableDaysUntil(LocalDate end) {
return getWorkableDaysFrom(getStartAsLocalDate(), end);
}
public Integer getWorkableDaysFrom(LocalDate startInclusive,
LocalDate endExclusive) {
int result = 0;
LocalDate start = getStartAsLocalDate();
for (LocalDate current = start; current.compareTo(end) < 0; current = current
for (LocalDate current = startInclusive; current
.compareTo(endExclusive) < 0; current = current
.plusDays(1)) {
if (isWorkable(current)) {
result++;
@ -843,8 +848,13 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
}
public LocalDate calculateEndGivenWorkableDays(int workableDays) {
LocalDate result = getIntraDayStartDate().getDate();
return calculateEndGivenWorkableDays(result, workableDays);
return calculateEndGivenWorkableDays(getIntraDayStartDate().getDate(),
workableDays);
}
public LocalDate calculateStartGivenWorkableDays(int workableDays) {
return calculateStartGivenWorkableDays(getEndAsLocalDate(),
workableDays);
}
private LocalDate calculateEndGivenWorkableDays(LocalDate start,

View file

@ -33,6 +33,7 @@ import org.navalplanner.business.planner.entities.CalculatedValue;
import org.navalplanner.business.planner.entities.DerivedAllocationGenerator.IWorkerFinder;
import org.navalplanner.business.planner.entities.ResourceAllocation;
import org.navalplanner.business.planner.entities.ResourceAllocation.AllocationsSpecified.INotFulfilledReceiver;
import org.navalplanner.business.planner.entities.ResourceAllocation.Direction;
import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.business.planner.entities.allocationalgorithms.HoursModification;
import org.navalplanner.business.planner.entities.allocationalgorithms.ResourcesPerDayModification;
@ -230,7 +231,7 @@ public class AllocationRowsHandler {
calculateNumberOfHoursAllocation();
break;
case END_DATE:
calculateEndDateAllocation();
calculateEndDateOrStartDateAllocation();
break;
case RESOURCES_PER_DAY:
calculateResourcesPerDayAllocation();
@ -249,14 +250,24 @@ public class AllocationRowsHandler {
private void calculateNumberOfHoursAllocation() {
List<ResourcesPerDayModification> allocations = AllocationRow
.createAndAssociate(task, currentRows);
ResourceAllocation.allocating(allocations).allocateUntil(
formBinder.getAllocationEnd());
if (isForwardsAllocation()) {
ResourceAllocation.allocating(allocations).allocateUntil(
formBinder.getAllocationEnd());
} else {
ResourceAllocation.allocating(allocations).allocateFromEndUntil(
formBinder.getAllocationStart());
}
}
private void calculateEndDateAllocation() {
private boolean isForwardsAllocation() {
return Direction.FORWARD.equals(task.getLastAllocationDirection());
}
private void calculateEndDateOrStartDateAllocation() {
List<ResourcesPerDayModification> allocations = AllocationRow
.createAndAssociate(task, currentRows);
ResourceAllocation.allocating(allocations).untilAllocating(
task.getLastAllocationDirection(),
formBinder.getAssignedHours(), notFullfiledReceiver());
}
@ -279,8 +290,13 @@ public class AllocationRowsHandler {
private void calculateResourcesPerDayAllocation() {
List<HoursModification> hours = AllocationRow
.createHoursModificationsAndAssociate(task, currentRows);
ResourceAllocation.allocatingHours(hours).allocateUntil(
formBinder.getAllocationEnd());
if (isForwardsAllocation()) {
ResourceAllocation.allocatingHours(hours).allocateUntil(
formBinder.getAllocationEnd());
} else {
ResourceAllocation.allocatingHours(hours).allocateFromEndUntil(
formBinder.getAllocationStart());
}
}
private Integer getWorkableDaysIfApplyable() {

View file

@ -37,6 +37,7 @@ import org.joda.time.format.DateTimeFormatter;
import org.navalplanner.business.common.ProportionalDistributor;
import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations;
import org.navalplanner.business.planner.entities.CalculatedValue;
import org.navalplanner.business.planner.entities.ResourceAllocation.Direction;
import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.Resource;
@ -299,6 +300,11 @@ public class FormBinder {
taskPropertiesController);
}
private boolean isForwardAllocated() {
Direction direction = getTask().getLastAllocationDirection();
return Direction.FORWARD.equals(direction);
}
class WorkableDaysAndDatesBinder {
private Intbox taskWorkableDays;
@ -308,7 +314,7 @@ public class FormBinder {
private Label labelTaskEnd;
WorkableDaysAndDatesBinder(final Intbox taskWorkableDays,
Label labelTaskStart, final Label labelTaskEnd,
final Label labelTaskStart, final Label labelTaskEnd,
final TaskPropertiesController taskPropertiesController) {
this.taskWorkableDays = taskWorkableDays;
this.labelTaskStart = labelTaskStart;
@ -321,10 +327,19 @@ public class FormBinder {
public void onEvent(Event event) throws Exception {
Task task = getTask();
Integer workableDays = taskWorkableDays.getValue();
LocalDate newEndDate = task
.calculateEndGivenWorkableDays(workableDays);
taskPropertiesController.updateTaskEndDate(newEndDate);
showValueOfDateOn(labelTaskEnd, newEndDate);
if (isForwardAllocated()) {
LocalDate newEndDate = task
.calculateEndGivenWorkableDays(workableDays);
taskPropertiesController
.updateTaskEndDate(newEndDate);
showValueOfDateOn(labelTaskEnd, newEndDate);
} else {
LocalDate newStart = task
.calculateStartGivenWorkableDays(workableDays);
taskPropertiesController
.updateTaskStartDate(newStart);
showValueOfDateOn(labelTaskStart, newStart);
}
}
});
applyDisabledRules();
@ -363,7 +378,7 @@ public class FormBinder {
}
private void clearDateAndDurationFields() {
labelTaskEnd.setValue("");
(isForwardAllocated() ? labelTaskEnd : labelTaskStart).setValue("");
taskWorkableDays.setConstraint((Constraint) null);
lastSpecifiedWorkableDays = taskWorkableDays.getValue();
taskWorkableDays.setValue(null);
@ -388,9 +403,12 @@ public class FormBinder {
|| aggregate.isEmpty()) {
return;
}
LocalDate start = aggregate.getStart().getDate();
LocalDate end = aggregate.getEnd().asExclusiveEnd();
showValueOfDateOn(labelTaskStart, start);
showValueOfDateOn(labelTaskEnd, end);
taskWorkableDays.setValue(getTask().getWorkableDaysUntil(end));
taskWorkableDays
.setValue(getTask().getWorkableDaysFrom(start, end));
}
private void showValueOfDateOn(final Label label, LocalDate date) {
@ -411,6 +429,11 @@ public class FormBinder {
workableDaysAndDatesBinder.getValue());
}
public LocalDate getAllocationStart() {
return getTask().calculateStartGivenWorkableDays(
workableDaysAndDatesBinder.getValue());
}
private Task getTask() {
return allocationRowsHandler.getTask();
}

View file

@ -196,6 +196,8 @@ public class TaskPropertiesController extends GenericForwardComposer {
private Intbox duration;
private Datebox startDateBox;
private Datebox endDateBox;
private Combobox startConstraintTypes;
@ -706,4 +708,10 @@ public class TaskPropertiesController extends GenericForwardComposer {
getGanttTaskDTO().endDate = endDate.toDateTimeAtStartOfDay().toDate();
Util.reloadBindings(endDateBox);
}
public void updateTaskStartDate(LocalDate newStart) {
getGanttTaskDTO().beginDate = newStart.toDateTimeAtStartOfDay()
.toDate();
Util.reloadBindings(startDateBox);
}
}