Use Capacity instead of EffortDuration for CalendarData

FEA: ItEr68OTS05IntroducionLimiteSobreasignacionCalendarios
This commit is contained in:
Óscar González Fernández 2011-01-17 18:48:43 +01:00
parent db9a92fe51
commit 100a863969
3 changed files with 42 additions and 13 deletions

View file

@ -71,7 +71,7 @@ public class CalendarData extends IntegrationEntity {
}
}
private Map<Integer, EffortDuration> effortPerDay;
private Map<Integer, Capacity> capacityPerDay;
private LocalDate expiringDate;
@ -85,33 +85,48 @@ public class CalendarData extends IntegrationEntity {
* Constructor for hibernate. Do not use!
*/
public CalendarData() {
effortPerDay = new HashMap<Integer, EffortDuration>();
capacityPerDay = new HashMap<Integer, Capacity>();
for (Days each : Days.values()) {
setDurationAt(each, null);
}
}
public Map<Integer, Integer> getHoursPerDay() {
return asHours(effortPerDay);
return asHours(capacityPerDay);
}
private Map<Integer, Integer> asHours(Map<Integer, EffortDuration> efforts) {
private Map<Integer, Integer> asHours(Map<Integer, Capacity> capacities) {
Map<Integer, Integer> result = new HashMap<Integer, Integer>();
for (Entry<Integer, EffortDuration> each : efforts.entrySet()) {
EffortDuration value = each.getValue();
for (Entry<Integer, Capacity> each : capacities.entrySet()) {
EffortDuration value = toDuration(each.getValue());
result.put(each.getKey(), value == null ? null : value.getHours());
}
return result;
}
private static EffortDuration toDuration(Capacity capacity) {
if (capacity == null) {
return null;
}
return capacity.getStandardEffort();
}
private Capacity toCapacity(EffortDuration duration) {
if (duration == null) {
return null;
}
return Capacity.create(duration).overAssignable(true);
}
public EffortDuration getDurationAt(Days day) {
return effortPerDay.get(day.ordinal());
return toDuration(capacityPerDay.get(day.ordinal()));
}
public void setDurationAt(Days day, EffortDuration duration) {
effortPerDay.put(day.ordinal(), duration);
capacityPerDay.put(day.ordinal(), toCapacity(duration));
}
public boolean isDefault(Days day) {
return getDurationAt(day) == null;
}
@ -137,8 +152,8 @@ public class CalendarData extends IntegrationEntity {
public CalendarData copy() {
CalendarData copy = create();
copy.effortPerDay = new HashMap<Integer, EffortDuration>(
this.effortPerDay);
copy.capacityPerDay = new HashMap<Integer, Capacity>(
this.capacityPerDay);
copy.expiringDate = this.expiringDate;
copy.parent = this.parent;

View file

@ -46,4 +46,14 @@
</sql>
</changeSet>
<changeSet id="use-capacity-for-capacity-per-day-for-calendar-data" author="ogonzalez">
<comment>Convert from duration to capacity in effort per day for CalendarData</comment>
<renameTable newTableName="capacity_per_day" oldTableName="effort_per_day" />
<addColumn tableName="capacity_per_day">
<column name="allowed_extra_effort" type="INTEGER" defaultValue="NULL"/>
</addColumn>
<renameColumn tableName="capacity_per_day" oldColumnName="effort"
newColumnName="standard_effort" columnDataType="INTEGER"/>
</changeSet>
</databaseChangeLog>

View file

@ -113,11 +113,15 @@
<property name="code" access="property" not-null="true" unique="true"/>
<map name="effortPerDay" table="effort_per_day">
<map name="capacityPerDay" table="capacity_per_day">
<key column="base_calendar_id"/>
<index column="day_id" type="integer" />
<element column="effort"
type="org.navalplanner.business.workingday.hibernate.EffortDurationType" />
<composite-element class="org.navalplanner.business.calendars.entities.Capacity">
<property name="standardEffort" column="standard_effort"
type="org.navalplanner.business.workingday.hibernate.EffortDurationType"/>
<property name="allowedExtraEffort" column="allowed_extra_effort"
type="org.navalplanner.business.workingday.hibernate.EffortDurationType"/>
</composite-element>
</map>
<!-- Not indexed -->