ItEr38S05ValidacionEProbasFuncionaisItEr37S06: [Bug #91] Allowing to set dates of stretches after the task end date.

This commit is contained in:
Manuel Rego Casasnovas 2009-12-09 13:45:20 +01:00 committed by Javier Moran Rua
parent a7de936581
commit 04f292f134
2 changed files with 28 additions and 9 deletions

View file

@ -94,9 +94,6 @@ public class StretchesFunction extends AssignmentFunction {
public void apply(ResourceAllocation<?> resourceAllocation,
LocalDate allocationStart, LocalDate allocationEnd,
int totalHours) {
if (loadProportion.signum() == 0) {
return;
}
resourceAllocation.withPreviousAssociatedResources()
.onInterval(getStartFor(allocationStart),
getEndFor(allocationEnd))

View file

@ -72,6 +72,8 @@ public class StretchesFunctionModel implements IStretchesFunctionModel {
private Task task;
private Date taskEndDate;
private StretchesFunction originalStretchesFunction;
@Autowired
@ -93,6 +95,7 @@ public class StretchesFunctionModel implements IStretchesFunctionModel {
this.task = task;
forceLoadTask();
this.taskEndDate = task.getEndDate();
}
}
@ -184,17 +187,36 @@ public class StretchesFunctionModel implements IStretchesFunctionModel {
@Override
public void setStretchDate(Stretch stretch, Date date)
throws IllegalArgumentException {
if ((date.compareTo(task.getStartDate()) < 0)
|| (date.compareTo(task.getEndDate()) > 0)) {
if (date.compareTo(task.getStartDate()) < 0) {
throw new IllegalArgumentException(
_("Stretch date should be between task dates"));
_("Stretch date should be greater or equals than task start date"));
}
stretch.setDate(new LocalDate(date));
long stretchDate = date.getTime();
if ((date.compareTo(taskEndDate) > 0)
|| (stretch.getAmountWorkPercentage().compareTo(BigDecimal.ONE) == 0)) {
taskEndDate = date;
recalculateStretchesPercentages();
} else {
calculatePercentage(stretch);
}
}
private void recalculateStretchesPercentages() {
List<Stretch> stretches = stretchesFunction.getStretches();
if (!stretches.isEmpty()) {
for (Stretch stretch : stretches) {
calculatePercentage(stretch);
}
}
}
private void calculatePercentage(Stretch stretch) {
long stretchDate = stretch.getDate().toDateTimeAtStartOfDay().toDate()
.getTime();
long startDate = task.getStartDate().getTime();
long endDate = task.getEndDate().getTime();
long endDate = taskEndDate.getTime();
// (stretchDate - startDate) / (endDate - startDate)
BigDecimal lengthPercenage = (new BigDecimal(stretchDate - startDate)
@ -209,7 +231,7 @@ public class StretchesFunctionModel implements IStretchesFunctionModel {
stretch.setLengthPercentage(lengthPercentage);
long startDate = task.getStartDate().getTime();
long endDate = task.getEndDate().getTime();
long endDate = taskEndDate.getTime();
// startDate + (percentage * (endDate - startDate))
long stretchDate = startDate + lengthPercentage.multiply(