From dbb45934e42e1e5defeace0119b8dfb73a7b851d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Fri, 13 Aug 2010 19:00:13 +0200 Subject: [PATCH] ItEr60S19TimeUnitDataType: Introduce EffortDuration in CalendarData. This changes must be applied to the database: ALTER TABLE hoursperday RENAME TO effortperday; ALTER TABLE effortperday RENAME COLUMN hours TO effort; update effortperday set effort = effort * 3600; --- .../calendars/entities/CalendarData.java | 30 ++++++++++++++----- .../calendars/entities/Calendars.hbm.xml | 5 ++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarData.java b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarData.java index abb8cbf98..09de0f092 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarData.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarData.java @@ -23,11 +23,14 @@ package org.navalplanner.business.calendars.entities; import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import org.joda.time.LocalDate; import org.navalplanner.business.calendars.daos.ICalendarDataDAO; 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 the information about the calendar that can change through time. @@ -69,7 +72,7 @@ public class CalendarData extends IntegrationEntity { } } - private Map hoursPerDay; + private Map effortPerDay; private LocalDate expiringDate; @@ -83,14 +86,23 @@ public class CalendarData extends IntegrationEntity { * Constructor for hibernate. Do not use! */ public CalendarData() { - hoursPerDay = new HashMap(); + effortPerDay = new HashMap(); for (Days each : Days.values()) { setHoursForDay(each, null); } } public Map getHoursPerDay() { - return hoursPerDay; + return asHours(effortPerDay); + } + + private Map asHours(Map efforts) { + Map result = new HashMap(); + for (Entry each : efforts.entrySet()) { + EffortDuration value = each.getValue(); + result.put(each.getKey(), value == null ? null : value.getHours()); + } + return result; } public Integer getHours(Days day) { @@ -108,11 +120,15 @@ public class CalendarData extends IntegrationEntity { throw new IllegalArgumentException( "The number of hours for a day can not be negative"); } - hoursPerDay.put(day.ordinal(), hours); + effortPerDay.put( + day.ordinal(), + hours == null ? null : + EffortDuration.elapsing(hours, Granularity.HOURS)); } private Integer getHoursForDay(Days day) { - return hoursPerDay.get(day.ordinal()); + EffortDuration effort = effortPerDay.get(day.ordinal()); + return effort == null ? null : effort.getHours(); } public boolean isDefault(Days day) { @@ -140,8 +156,8 @@ public class CalendarData extends IntegrationEntity { public CalendarData copy() { CalendarData copy = create(); - - copy.hoursPerDay = new HashMap(this.hoursPerDay); + copy.effortPerDay = new HashMap( + this.effortPerDay); copy.expiringDate = this.expiringDate; copy.parent = this.parent; diff --git a/navalplanner-business/src/main/resources/org/navalplanner/business/calendars/entities/Calendars.hbm.xml b/navalplanner-business/src/main/resources/org/navalplanner/business/calendars/entities/Calendars.hbm.xml index 13b8bedd9..262a0444b 100644 --- a/navalplanner-business/src/main/resources/org/navalplanner/business/calendars/entities/Calendars.hbm.xml +++ b/navalplanner-business/src/main/resources/org/navalplanner/business/calendars/entities/Calendars.hbm.xml @@ -94,10 +94,11 @@ - + - +