[Bug #774] Fix bug

Using DurationBetweenDates to calculate initial lengh for tasks.

FEA: ItEr67S04BugFixing
This commit is contained in:
Óscar González Fernández 2011-01-03 16:22:00 +01:00
parent 266d9d4fe1
commit 2ff4c92213
2 changed files with 16 additions and 12 deletions

View file

@ -75,23 +75,14 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
@Override
protected void initializeDates() {
EffortDuration workHours = EffortDuration.hours(getWorkHours());
EffortDuration effortStandardPerDay = EffortDuration.hours(8);
int daysElapsed = workHours.divideBy(effortStandardPerDay);
EffortDuration remainder = workHours.remainderFor(effortStandardPerDay);
DurationBetweenDates duration = fromFixedDuration(workHours);
IntraDayDate start = getIntraDayStartDate();
if (start != null) {
IntraDayDate calculatedEnd = IntraDayDate.create(
start.getDate().plusDays(daysElapsed), start
.getEffortDuration().plus(remainder));
setIntraDayEndDate(calculatedEnd);
setIntraDayEndDate(duration.fromStartToEnd(start));
} else {
IntraDayDate end = getIntraDayEndDate();
IntraDayDate calculatedStart = IntraDayDate.startOfDay(end
.getDate().minusDays(
daysElapsed + (remainder.isZero() ? 0 : 1)));
setIntraDayStartDate(calculatedStart);
setIntraDayStartDate(duration.fromEndToStart(end));
}
}
@ -573,6 +564,10 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
.getDefaultWorkingDay();
}
private DurationBetweenDates fromFixedDuration(EffortDuration duration) {
return new DurationBetweenDates(0, duration);
}
private class DurationBetweenDates {
private final int numberOfWorkableDays;

View file

@ -505,6 +505,7 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
Order.checkConstraintOrderUniqueCode(order);
HoursGroup.checkConstraintHoursGroupUniqueCode(order);
reattachCalendar();
reattachCriterions();
reattachTasksForTasksSources();
@ -594,6 +595,14 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
}
}
private void reattachCalendar() {
if (order.getCalendar() == null) {
return;
}
BaseCalendar calendar = order.getCalendar();
baseCalendarDAO.reattachUnmodifiedEntity(calendar);
}
private void reattachAllTaskSources() {
// avoid LazyInitializationException for when doing
// removePredecessorsDayAssignmentsFor