Now CalendarException uses a Capacity instead of the field duration

FEA: ItEr68OTS05IntroducionLimiteSobreasignacionCalendarios
This commit is contained in:
Óscar González Fernández 2011-01-12 13:02:30 +01:00
parent 64367510ee
commit db9a92fe51
3 changed files with 41 additions and 12 deletions

View file

@ -42,18 +42,25 @@ public class CalendarException extends IntegrationEntity {
public static CalendarException create(Date date, EffortDuration duration,
CalendarExceptionType type) {
return create(new CalendarException(new LocalDate(date), duration, type));
return create(new CalendarException(new LocalDate(date), from(duration,
type), type));
}
public static CalendarException create(LocalDate date,
EffortDuration duration,
CalendarExceptionType type) {
return create(new CalendarException(date, duration, type));
return create(new CalendarException(date, from(duration, type), type));
}
public static CalendarException create(String code, LocalDate date,
EffortDuration duration, CalendarExceptionType type) {
return create(new CalendarException(date, duration, type), code);
return create(new CalendarException(date, from(duration, type), type),
code);
}
private static Capacity from(EffortDuration duration,
CalendarExceptionType type) {
return type.getCapacity().withNormalDuration(duration);
}
private static EffortDuration fromHours(Integer hours) {
@ -67,7 +74,7 @@ public class CalendarException extends IntegrationEntity {
}
if (hours != null) {
this.duration = fromHours(hours);
this.capacity.withNormalDuration(fromHours(hours));
}
if (type != null) {
@ -77,7 +84,7 @@ public class CalendarException extends IntegrationEntity {
private LocalDate date;
private EffortDuration duration;
private Capacity capacity;
private CalendarExceptionType type;
@ -88,11 +95,11 @@ public class CalendarException extends IntegrationEntity {
}
private CalendarException(LocalDate date, EffortDuration duration,
private CalendarException(LocalDate date, Capacity capacity,
CalendarExceptionType type) {
Validate.notNull(duration);
Validate.notNull(capacity);
this.date = date;
this.duration = duration;
this.capacity = capacity;
this.type = type;
}
@ -101,9 +108,13 @@ public class CalendarException extends IntegrationEntity {
return date;
}
@NotNull
public EffortDuration getDuration() {
return duration;
return capacity.getStandardEffort();
}
@NotNull
public Capacity getCapacity() {
return capacity;
}
@NotNull

View file

@ -32,4 +32,18 @@
<dropColumn tableName="calendar_exception_type" columnName="not_assignable"/>
</changeSet>
<changeSet id="use-capacity-for-exceptions" author="ogonzalez">
<comment>Convert from duration to capacity property for calendar exceptions</comment>
<addColumn tableName="calendar_exception">
<column name="allowed_extra_effort" type="INTEGER" defaultValue="NULL"/>
</addColumn>
<renameColumn tableName="calendar_exception" oldColumnName="duration"
newColumnName="standard_effort" columnDataType="INTEGER"/>
<sql>
update calendar_exception SET allowed_extra_effort =
(select allowed_extra_effort from calendar_exception_type
where calendar_exception_type.id = calendar_exception.calendar_exception_id)
</sql>
</changeSet>
</databaseChangeLog>

View file

@ -65,8 +65,12 @@
<property name="date" access="field"
type="org.joda.time.contrib.hibernate.PersistentLocalDate"/>
<property name="duration" access="field"
type="org.navalplanner.business.workingday.hibernate.EffortDurationType"/>
<component name="capacity" class="org.navalplanner.business.calendars.entities.Capacity">
<property name="standardEffort" column="standard_effort"
type="org.navalplanner.business.workingday.hibernate.EffortDurationType"></property>
<property name="allowedExtraEffort" column="allowed_extra_effort"
type="org.navalplanner.business.workingday.hibernate.EffortDurationType"></property>
</component>
<!-- Not indexed -->
<many-to-one name="type" cascade="none"
column="calendar_exception_id" />