ItEr60S19TimeUnitDataType: Introduce EffortDuration in CalendarException.

This changes must be applied to the database:

ALTER TABLE calendarexception RENAME COLUMN hours to duration;
UPDATE calendarexception SET duration = duration * 3600;
This commit is contained in:
Óscar González Fernández 2010-08-16 11:14:25 +02:00
parent dbb45934e4
commit 0e0cab4a77
2 changed files with 13 additions and 5 deletions

View file

@ -27,6 +27,8 @@ import org.joda.time.LocalDate;
import org.navalplanner.business.calendars.daos.ICalendarExceptionDAO;
import org.navalplanner.business.common.IntegrationEntity;
import org.navalplanner.business.common.Registry;
import org.navalplanner.business.workingday.EffortDuration;
import org.navalplanner.business.workingday.EffortDuration.Granularity;
/**
* Represents an exceptional day that has a different number of hours. For
@ -53,6 +55,11 @@ public class CalendarException extends IntegrationEntity {
return create(new CalendarException(date, hours, type), code);
}
private static EffortDuration fromHours(Integer hours) {
return hours == null ? null : EffortDuration.elapsing(hours,
Granularity.HOURS);
}
public void updateUnvalidated(LocalDate date, Integer hours,
CalendarExceptionType type) {
if (date != null) {
@ -60,7 +67,7 @@ public class CalendarException extends IntegrationEntity {
}
if (hours != null) {
this.hours = hours;
this.duration = fromHours(hours);
}
if (type != null) {
@ -70,7 +77,7 @@ public class CalendarException extends IntegrationEntity {
private LocalDate date;
private Integer hours;
private EffortDuration duration;
private CalendarExceptionType type;
@ -84,7 +91,7 @@ public class CalendarException extends IntegrationEntity {
private CalendarException(LocalDate date, Integer hours,
CalendarExceptionType type) {
this.date = date;
this.hours = hours;
this.duration = fromHours(hours);
this.type = type;
}
@ -95,7 +102,7 @@ public class CalendarException extends IntegrationEntity {
@NotNull
public Integer getHours() {
return hours != null ? hours : 0;
return duration != null ? duration.getHours() : 0;
}
@NotNull

View file

@ -59,7 +59,8 @@
<property name="date" access="field"
type="org.joda.time.contrib.hibernate.PersistentLocalDate"/>
<property name="hours" access="field"/>
<property name="duration" access="field"
type="org.navalplanner.business.workingday.hibernate.EffortDurationType"/>
<!-- Not indexed -->
<many-to-one name="type" cascade="none"
column="CALENDAR_EXCEPTION_ID" />