[Bug #1132] Create new enum CalendarExceptionTypeColor

The enum is being used in CalendarExceptionType and all the entities
related have been updated to work with the new enum. Web service has
also been updated.

Colors defined now are: DEFAULT (red), GREEN and BLUE. Colors to show in
the interface are just examples and should be changed in a later patch.

FEA: ItEr75S04BugFixing
This commit is contained in:
Manuel Rego Casasnovas 2011-08-04 14:28:51 +02:00
parent 343330151c
commit e633a179b1
12 changed files with 253 additions and 28 deletions

View file

@ -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;
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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 <rego@igalia.com>
*/
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;
}
}

View file

@ -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);

View file

@ -223,4 +223,11 @@
</addColumn>
</changeSet>
<changeSet id="update-color-in-calendar_exception_type-to-default" author="mrego">
<comment>Update color in calendar_exception_type to DEFAULT</comment>
<update tableName="calendar_exception_type">
<column name="color" value="DEFAULT" />
</update>
</changeSet>
</databaseChangeLog>

View file

@ -92,7 +92,13 @@
column="code_autogenerated" />
<property name="name" unique="true" />
<property name="color" />
<property name="color">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.navalplanner.business.calendars.entities.CalendarExceptionTypeColor</param>
<param name="type">12</param>
</type>
</property>
<component name="capacity" class="org.navalplanner.business.calendars.entities.Capacity">
<property name="standardEffort" column="standard_effort"

View file

@ -41,6 +41,7 @@ import org.navalplanner.business.calendars.entities.BaseCalendar.DayType;
import org.navalplanner.business.calendars.entities.CalendarData.Days;
import org.navalplanner.business.calendars.entities.CalendarException;
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.workingday.EffortDuration;
import org.navalplanner.business.workingday.IntraDayDate.PartialDay;
@ -114,7 +115,7 @@ public class BaseCalendarTest {
public static CalendarExceptionType createCalendarExceptionType() {
CalendarExceptionType result = CalendarExceptionType.create("TEST",
"black", true);
CalendarExceptionTypeColor.DEFAULT, true);
return result;
}

View file

@ -0,0 +1,34 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
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 <rego@igalia.com>
*/
@XmlEnum
public enum CalendarExceptionTypeColorDTO {
DEFAULT, RED, GREEN, BLUE;
}

View file

@ -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);
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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 <rego@igalia.com>
*/
public class CalendarExceptionTypeColorConverter {
private final static Map<CalendarExceptionTypeColor, CalendarExceptionTypeColorDTO> calendarExceptionTypeColorToDTO = new HashMap<CalendarExceptionTypeColor, CalendarExceptionTypeColorDTO>();
private final static Map<CalendarExceptionTypeColorDTO, CalendarExceptionTypeColor> calendarExceptionTypeColorFromDTO = new HashMap<CalendarExceptionTypeColorDTO, CalendarExceptionTypeColor>();
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 <code>null</code> if the parameter is <code>null</code>.
*/
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;
}
}
}

View file

@ -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));
}

View file

@ -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);

View file

@ -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()));