diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarExceptionType.java b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarExceptionType.java
index 060c9eba2..ab8a7e83a 100644
--- a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarExceptionType.java
+++ b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarExceptionType.java
@@ -51,7 +51,7 @@ public class CalendarExceptionType extends IntegrationEntity implements
private String name;
- private String color;
+ private CalendarExceptionTypeColor color = CalendarExceptionTypeColor.DEFAULT;
private Capacity capacity = Capacity.zero();
@@ -59,19 +59,21 @@ public class CalendarExceptionType extends IntegrationEntity implements
return create(new CalendarExceptionType());
}
- public static CalendarExceptionType create(String name, String color,
+ public static CalendarExceptionType create(String name,
+ CalendarExceptionTypeColor color,
Boolean notAssignable) {
return create(new CalendarExceptionType(name, color, notAssignable));
}
public static CalendarExceptionType create(String code, String name,
- String color, Boolean notAssignable) {
+ CalendarExceptionTypeColor color, Boolean notAssignable) {
return create(new CalendarExceptionType(name, color, notAssignable),
code);
}
public static CalendarExceptionType create(String code, String name,
- String color, Boolean notAssignable, EffortDuration duration) {
+ CalendarExceptionTypeColor color, Boolean notAssignable,
+ EffortDuration duration) {
CalendarExceptionType calendarExceptionType = new CalendarExceptionType(
name, color, notAssignable);
calendarExceptionType.setDuration(duration);
@@ -85,7 +87,7 @@ public class CalendarExceptionType extends IntegrationEntity implements
}
- public CalendarExceptionType(String name, String color,
+ public CalendarExceptionType(String name, CalendarExceptionTypeColor color,
Boolean notOverAssignable) {
this.name = name;
this.color = color;
@@ -103,11 +105,11 @@ public class CalendarExceptionType extends IntegrationEntity implements
this.name = name;
}
- public String getColor() {
+ public CalendarExceptionTypeColor getColor() {
return color;
}
- public void setColor(String color) {
+ public void setColor(CalendarExceptionTypeColor color) {
this.color = color;
}
diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarExceptionTypeColor.java b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarExceptionTypeColor.java
new file mode 100644
index 000000000..993c5f177
--- /dev/null
+++ b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarExceptionTypeColor.java
@@ -0,0 +1,58 @@
+/*
+ * This file is part of NavalPlan
+ *
+ * Copyright (C) 2011 Igalia, S.L.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package org.navalplanner.business.calendars.entities;
+
+import static org.navalplanner.business.i18n.I18nHelper._;
+
+/**
+ * Enum representing the possible colors to choose for a
+ * {@link CalendarExceptionType}
+ *
+ * @author Manuel Rego Casasnovas
+ */
+public enum CalendarExceptionTypeColor {
+ DEFAULT(_("red (default)"), "red", "lightcoral"),
+ GREEN(_("green"), "green", "lightgreen"),
+ BLUE(_("blue"), "blue", "lightblue");
+
+ private final String name;
+ private final String colorOwnException;
+ private final String colorDerivedException;
+
+ private CalendarExceptionTypeColor(String name, String colorOwnException,
+ String colorDerivedException) {
+ this.name = name;
+ this.colorOwnException = colorOwnException;
+ this.colorDerivedException = colorDerivedException;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getColorOwnException() {
+ return colorOwnException;
+ }
+
+ public String getColorDerivedException() {
+ return colorDerivedException;
+ }
+
+}
diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/PredefinedCalendarExceptionTypes.java b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/PredefinedCalendarExceptionTypes.java
index 10f8b8ea5..ced346b9f 100644
--- a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/PredefinedCalendarExceptionTypes.java
+++ b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/PredefinedCalendarExceptionTypes.java
@@ -29,15 +29,17 @@ package org.navalplanner.business.calendars.entities;
*/
public enum PredefinedCalendarExceptionTypes {
- HOLIDAY("HOLIDAY", "red", true), SICK_LEAVE("SICK_LEAVE", "red", true), LEAVE(
- "LEAVE", "red", true), STRIKE("STRIKE", "red", true), BANK_HOLIDAY(
- "BANK_HOLIDAY", "red", true), WORKABLE_BANK_HOLIDAY(
- "WORKABLE_BANK_HOLIDAY", "orange", false);
+ HOLIDAY("HOLIDAY", CalendarExceptionTypeColor.DEFAULT, true),
+ SICK_LEAVE("SICK_LEAVE", CalendarExceptionTypeColor.DEFAULT, true),
+ LEAVE("LEAVE", CalendarExceptionTypeColor.DEFAULT, true),
+ STRIKE("STRIKE", CalendarExceptionTypeColor.DEFAULT, true),
+ BANK_HOLIDAY("BANK_HOLIDAY", CalendarExceptionTypeColor.DEFAULT, true),
+ WORKABLE_BANK_HOLIDAY("WORKABLE_BANK_HOLIDAY", CalendarExceptionTypeColor.DEFAULT, false);
private CalendarExceptionType calendarExceptionType;
- private PredefinedCalendarExceptionTypes(String name, String color,
- Boolean notAssignable) {
+ private PredefinedCalendarExceptionTypes(String name,
+ CalendarExceptionTypeColor color, Boolean notAssignable) {
// Using the name as code in order to be more human friendly
calendarExceptionType = CalendarExceptionType.create(name, name, color,
notAssignable);
diff --git a/navalplanner-business/src/main/resources/db.changelog-1.1.xml b/navalplanner-business/src/main/resources/db.changelog-1.1.xml
index 6ee75e41c..8801fe23c 100644
--- a/navalplanner-business/src/main/resources/db.changelog-1.1.xml
+++ b/navalplanner-business/src/main/resources/db.changelog-1.1.xml
@@ -223,4 +223,11 @@
+
+ Update color in calendar_exception_type to DEFAULT
+
+
+
+
+
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 e8a40358a..346d99d09 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
@@ -92,7 +92,13 @@
column="code_autogenerated" />
-
+
+
+
+ org.navalplanner.business.calendars.entities.CalendarExceptionTypeColor
+ 12
+
+
.
+ */
+
+package org.navalplanner.ws.calendarexceptiontypes.api;
+
+import javax.xml.bind.annotation.XmlEnum;
+
+import org.navalplanner.business.calendars.entities.CalendarExceptionTypeColor;
+
+/**
+ * DTO for {@link CalendarExceptionTypeColor} enum.
+ *
+ * @author Manuel Rego Casasnovas
+ */
+@XmlEnum
+public enum CalendarExceptionTypeColorDTO {
+ DEFAULT, RED, GREEN, BLUE;
+}
diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendarexceptiontypes/api/CalendarExceptionTypeDTO.java b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendarexceptiontypes/api/CalendarExceptionTypeDTO.java
index 3070f303f..1d7f41e15 100644
--- a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendarexceptiontypes/api/CalendarExceptionTypeDTO.java
+++ b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendarexceptiontypes/api/CalendarExceptionTypeDTO.java
@@ -41,7 +41,7 @@ public class CalendarExceptionTypeDTO extends IntegrationEntityDTO {
public String name;
@XmlAttribute
- public String color;
+ public CalendarExceptionTypeColorDTO color;
@XmlAttribute(name = "over-assignable")
public boolean overAssignable;
@@ -52,7 +52,8 @@ public class CalendarExceptionTypeDTO extends IntegrationEntityDTO {
public CalendarExceptionTypeDTO() {
}
- public CalendarExceptionTypeDTO(String code, String name, String color,
+ public CalendarExceptionTypeDTO(String code, String name,
+ CalendarExceptionTypeColorDTO color,
boolean overAssignable, int duration) {
super(code);
this.name = name;
@@ -61,7 +62,8 @@ public class CalendarExceptionTypeDTO extends IntegrationEntityDTO {
this.duration = duration;
}
- public CalendarExceptionTypeDTO(String name, String color,
+ public CalendarExceptionTypeDTO(String name,
+ CalendarExceptionTypeColorDTO color,
boolean overAssignable, int duration) {
this(generateCode(), name, color, overAssignable, duration);
}
diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendarexceptiontypes/impl/CalendarExceptionTypeColorConverter.java b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendarexceptiontypes/impl/CalendarExceptionTypeColorConverter.java
new file mode 100644
index 000000000..4e47302a9
--- /dev/null
+++ b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendarexceptiontypes/impl/CalendarExceptionTypeColorConverter.java
@@ -0,0 +1,101 @@
+/*
+ * This file is part of NavalPlan
+ *
+ * Copyright (C) 2011 Igalia, S.L.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package org.navalplanner.ws.calendarexceptiontypes.impl;
+
+import static org.navalplanner.web.I18nHelper._;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.navalplanner.business.calendars.entities.CalendarExceptionTypeColor;
+import org.navalplanner.ws.calendarexceptiontypes.api.CalendarExceptionTypeColorDTO;
+
+/**
+ * Converter from/to {@link CalendarExceptionTypeColor} entities to/from DTOs.
+ *
+ * @author Manuel Rego Casasnovas
+ */
+public class CalendarExceptionTypeColorConverter {
+
+ private final static Map calendarExceptionTypeColorToDTO = new HashMap();
+
+ private final static Map calendarExceptionTypeColorFromDTO = new HashMap();
+
+ static {
+
+ calendarExceptionTypeColorFromDTO.put(
+ CalendarExceptionTypeColorDTO.RED,
+ CalendarExceptionTypeColor.DEFAULT);
+
+ calendarExceptionTypeColorToDTO.put(CalendarExceptionTypeColor.DEFAULT,
+ CalendarExceptionTypeColorDTO.DEFAULT);
+ calendarExceptionTypeColorFromDTO.put(
+ CalendarExceptionTypeColorDTO.DEFAULT,
+ CalendarExceptionTypeColor.DEFAULT);
+
+ calendarExceptionTypeColorToDTO.put(CalendarExceptionTypeColor.GREEN,
+ CalendarExceptionTypeColorDTO.GREEN);
+ calendarExceptionTypeColorFromDTO.put(
+ CalendarExceptionTypeColorDTO.GREEN,
+ CalendarExceptionTypeColor.GREEN);
+
+ calendarExceptionTypeColorToDTO.put(CalendarExceptionTypeColor.BLUE,
+ CalendarExceptionTypeColorDTO.BLUE);
+ calendarExceptionTypeColorFromDTO.put(
+ CalendarExceptionTypeColorDTO.BLUE,
+ CalendarExceptionTypeColor.BLUE);
+
+ }
+
+ public final static CalendarExceptionTypeColorDTO toDTO(
+ CalendarExceptionTypeColor resource) {
+ CalendarExceptionTypeColorDTO value = calendarExceptionTypeColorToDTO
+ .get(resource);
+
+ if (value == null) {
+ throw new RuntimeException(_("Unable to convert {0} "
+ + "value to {1} type", resource.toString(),
+ CalendarExceptionTypeColorDTO.class.getName()));
+ } else {
+ return value;
+ }
+ }
+
+ /**
+ * It returns null if the parameter is null.
+ */
+ public final static CalendarExceptionTypeColor toEntity(
+ CalendarExceptionTypeColorDTO resource) {
+ if (resource == null) {
+ return null;
+ }
+
+ CalendarExceptionTypeColor value = calendarExceptionTypeColorFromDTO
+ .get(resource);
+
+ if (value == null) {
+ throw new RuntimeException(_("Unable to convert value to {0} type",
+ CalendarExceptionTypeColor.class.getName()));
+ } else {
+ return value;
+ }
+ }
+
+}
diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendarexceptiontypes/impl/CalendarExceptionTypeConverter.java b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendarexceptiontypes/impl/CalendarExceptionTypeConverter.java
index a72fb87be..51b4d7fae 100644
--- a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendarexceptiontypes/impl/CalendarExceptionTypeConverter.java
+++ b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendarexceptiontypes/impl/CalendarExceptionTypeConverter.java
@@ -23,6 +23,7 @@ package org.navalplanner.ws.calendarexceptiontypes.impl;
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
import org.navalplanner.business.workingday.EffortDuration;
+import org.navalplanner.ws.calendarexceptiontypes.api.CalendarExceptionTypeColorDTO;
import org.navalplanner.ws.calendarexceptiontypes.api.CalendarExceptionTypeDTO;
/**
@@ -40,23 +41,29 @@ public final class CalendarExceptionTypeConverter {
CalendarExceptionType calendarExceptionType) {
EffortDuration duration = calendarExceptionType.getDuration();
int seconds = (duration != null) ? duration.getSeconds() : 0;
+
+ CalendarExceptionTypeColorDTO colorDTO = CalendarExceptionTypeColorConverter
+ .toDTO(calendarExceptionType.getColor());
+
return new CalendarExceptionTypeDTO(calendarExceptionType.getCode(),
- calendarExceptionType.getName(), calendarExceptionType
- .getColor(), calendarExceptionType.isOverAssignableWithoutLimit(),
+ calendarExceptionType.getName(), colorDTO,
+ calendarExceptionType.isOverAssignableWithoutLimit(),
seconds);
}
public final static CalendarExceptionType toEntity(
CalendarExceptionTypeDTO entityDTO) {
return CalendarExceptionType.create(entityDTO.code, entityDTO.name,
- entityDTO.color, entityDTO.overAssignable, EffortDuration
- .seconds(entityDTO.duration));
+ CalendarExceptionTypeColorConverter.toEntity(entityDTO.color),
+ entityDTO.overAssignable,
+ EffortDuration.seconds(entityDTO.duration));
}
public static void updateCalendarExceptionType(
CalendarExceptionType entity, CalendarExceptionTypeDTO entityDTO) {
entity.setName(entityDTO.name);
- entity.setColor(entityDTO.color);
+ entity.setColor(CalendarExceptionTypeColorConverter
+ .toEntity(entityDTO.color));
entity.setOverAssignable(entityDTO.overAssignable);
entity.setDuration(EffortDuration.seconds(entityDTO.duration));
}
diff --git a/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/basecalendars/BaseCalendarServiceTest.java b/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/basecalendars/BaseCalendarServiceTest.java
index 6f10e8d50..73e87e815 100644
--- a/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/basecalendars/BaseCalendarServiceTest.java
+++ b/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/basecalendars/BaseCalendarServiceTest.java
@@ -45,6 +45,7 @@ import org.navalplanner.business.calendars.daos.ICalendarExceptionTypeDAO;
import org.navalplanner.business.calendars.entities.BaseCalendar;
import org.navalplanner.business.calendars.entities.CalendarData;
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
+import org.navalplanner.business.calendars.entities.CalendarExceptionTypeColor;
import org.navalplanner.business.calendars.entities.Capacity;
import org.navalplanner.business.common.IAdHocTransactionService;
import org.navalplanner.business.common.IOnTransaction;
@@ -120,7 +121,7 @@ public class BaseCalendarServiceTest {
@Rollback(false)
public void givenCalendarExceptionTypeStored() {
CalendarExceptionType calendarExceptionType = CalendarExceptionType
- .create("name", "color", false);
+ .create("name", CalendarExceptionTypeColor.DEFAULT, false);
calendarExceptionType.setCode(typeCode);
calendarExceptionTypeDAO.save(calendarExceptionType);
diff --git a/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/calendarexceptiontypes/api/CalendarExceptionTypeServiceTest.java b/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/calendarexceptiontypes/api/CalendarExceptionTypeServiceTest.java
index 57541b995..9b2c7ee0d 100644
--- a/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/calendarexceptiontypes/api/CalendarExceptionTypeServiceTest.java
+++ b/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/calendarexceptiontypes/api/CalendarExceptionTypeServiceTest.java
@@ -35,9 +35,11 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.navalplanner.business.calendars.daos.ICalendarExceptionTypeDAO;
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
+import org.navalplanner.business.calendars.entities.CalendarExceptionTypeColor;
import org.navalplanner.ws.calendarexceptiontypes.api.CalendarExceptionTypeDTO;
import org.navalplanner.ws.calendarexceptiontypes.api.CalendarExceptionTypeListDTO;
import org.navalplanner.ws.calendarexceptiontypes.api.ICalendarExceptionTypeService;
+import org.navalplanner.ws.calendarexceptiontypes.impl.CalendarExceptionTypeColorConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -68,7 +70,7 @@ public class CalendarExceptionTypeServiceTest {
private CalendarExceptionType givenCalendarExceptionTypeStored() {
CalendarExceptionType calendarExceptionType = CalendarExceptionType
- .create("name", "color", false);
+ .create("name", CalendarExceptionTypeColor.DEFAULT, false);
calendarExceptionTypeDAO.save(calendarExceptionType);
calendarExceptionTypeDAO.flush();
@@ -79,14 +81,14 @@ public class CalendarExceptionTypeServiceTest {
}
@Test
- public void exportLabelTypes() {
+ public void exportExceptionTypes() {
CalendarExceptionTypeListDTO list = calendarExceptionTypeService
.getCalendarExceptionType();
assertTrue(list.calendarExceptionTypes.isEmpty());
}
@Test
- public void exportLabelTypes2() {
+ public void exportExceptionTypes2() {
CalendarExceptionType calendarExceptionType = givenCalendarExceptionTypeStored();
CalendarExceptionTypeListDTO list = calendarExceptionTypeService
@@ -99,7 +101,9 @@ public class CalendarExceptionTypeServiceTest {
.getCode()));
assertThat(calendarExceptionTypeDTO.name, equalTo(calendarExceptionType
.getName()));
- assertThat(calendarExceptionTypeDTO.color,
+ assertThat(
+ CalendarExceptionTypeColorConverter
+ .toEntity(calendarExceptionTypeDTO.color),
equalTo(calendarExceptionType.getColor()));
assertThat(calendarExceptionTypeDTO.overAssignable,
equalTo(calendarExceptionType.isOverAssignableWithoutLimit()));