From fb3bd8bacfff2b17107d8ec6e6071edf6a69ebfc Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Mon, 22 Mar 2010 12:01:33 +0100 Subject: [PATCH] ItEr50S13AdaptacionServiciosRESTItEr49S18: Implementing calendars export service. --- .../calendars/daos/CalendarDataDAO.java | 40 ++++++++++ .../calendars/daos/CalendarExceptionDAO.java | 40 ++++++++++ .../calendars/daos/ICalendarDataDAO.java | 34 +++++++++ .../calendars/daos/ICalendarExceptionDAO.java | 34 +++++++++ .../calendars/entities/CalendarData.java | 15 ++-- .../calendars/entities/CalendarException.java | 21 +++--- .../business/common/Registry.java | 16 ++++ .../calendars/entities/Calendars.hbm.xml | 4 + .../ws/calendars/api/BaseCalendarDTO.java | 27 ++++++- .../ws/calendars/api/BaseCalendarListDTO.java | 2 +- .../ws/calendars/api/CalendarDataDTO.java | 74 +++++++++++++++++++ .../calendars/api/CalendarExceptionDTO.java | 69 +++++++++++++++++ .../ws/calendars/api/HoursPerDayDTO.java | 48 ++++++++++++ .../ws/calendars/api/ICalendarService.java | 2 +- .../ws/calendars/impl/CalendarConverter.java | 52 ++++++++++++- .../calendars/impl/CalendarServiceREST.java | 10 ++- scripts/rest-clients/README | 4 + scripts/rest-clients/export-calendars.sh | 21 ++++++ 18 files changed, 487 insertions(+), 26 deletions(-) create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/CalendarDataDAO.java create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/CalendarExceptionDAO.java create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/ICalendarDataDAO.java create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/ICalendarExceptionDAO.java create mode 100644 navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/CalendarDataDTO.java create mode 100644 navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/CalendarExceptionDTO.java create mode 100644 navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/HoursPerDayDTO.java create mode 100755 scripts/rest-clients/export-calendars.sh diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/CalendarDataDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/CalendarDataDAO.java new file mode 100644 index 000000000..fb2670393 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/CalendarDataDAO.java @@ -0,0 +1,40 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * 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.daos; + +import org.navalplanner.business.calendars.entities.CalendarData; +import org.navalplanner.business.common.daos.IntegrationEntityDAO; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Repository; + +/** + * DAO for {@link CalendarData} + * + * @author Manuel Rego Casasnovas + */ +@Repository +@Scope(BeanDefinition.SCOPE_SINGLETON) +public class CalendarDataDAO extends + IntegrationEntityDAO + implements ICalendarDataDAO { + +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/CalendarExceptionDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/CalendarExceptionDAO.java new file mode 100644 index 000000000..1863c6b22 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/CalendarExceptionDAO.java @@ -0,0 +1,40 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * 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.daos; + +import org.navalplanner.business.calendars.entities.CalendarException; +import org.navalplanner.business.common.daos.IntegrationEntityDAO; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Repository; + +/** + * DAO for {@link CalendarException} + * + * @author Manuel Rego Casasnovas + */ +@Repository +@Scope(BeanDefinition.SCOPE_SINGLETON) +public class CalendarExceptionDAO extends + IntegrationEntityDAO implements + ICalendarExceptionDAO { + +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/ICalendarDataDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/ICalendarDataDAO.java new file mode 100644 index 000000000..e1dbf7fed --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/ICalendarDataDAO.java @@ -0,0 +1,34 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * 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.daos; + +import org.navalplanner.business.calendars.entities.CalendarData; +import org.navalplanner.business.common.daos.IIntegrationEntityDAO; + +/** + * Contract for {@link CalendarDataDAO} + * + * @author Manuel Rego Casasnovas + */ +public interface ICalendarDataDAO extends + IIntegrationEntityDAO { + +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/ICalendarExceptionDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/ICalendarExceptionDAO.java new file mode 100644 index 000000000..3db41b8a6 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/daos/ICalendarExceptionDAO.java @@ -0,0 +1,34 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * 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.daos; + +import org.navalplanner.business.calendars.entities.CalendarException; +import org.navalplanner.business.common.daos.IIntegrationEntityDAO; + +/** + * Contract for {@link CalendarExceptionDAO}. + * + * @author Manuel Rego Casasnovas + */ +public interface ICalendarExceptionDAO extends + IIntegrationEntityDAO { + +} 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 f9b474978..27a089c53 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 @@ -25,19 +25,19 @@ import java.util.HashMap; import java.util.Map; import org.joda.time.LocalDate; -import org.navalplanner.business.common.BaseEntity; +import org.navalplanner.business.calendars.daos.ICalendarDataDAO; +import org.navalplanner.business.common.IntegrationEntity; +import org.navalplanner.business.common.Registry; /** * Represents the information about the calendar that can change through time. * * @author Manuel Rego Casasnovas */ -public class CalendarData extends BaseEntity { +public class CalendarData extends IntegrationEntity { public static CalendarData create() { - CalendarData calendarData = new CalendarData(); - calendarData.setNewObject(true); - return calendarData; + return create(new CalendarData()); } private Map hoursPerDay; @@ -159,4 +159,9 @@ public class CalendarData extends BaseEntity { return true; } + @Override + protected ICalendarDataDAO getIntegrationEntityDAO() { + return Registry.getCalendarDataDAO(); + } + } diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarException.java b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarException.java index 1abff1058..37c09c721 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarException.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CalendarException.java @@ -24,7 +24,9 @@ import java.util.Date; import org.hibernate.validator.NotNull; import org.joda.time.LocalDate; -import org.navalplanner.business.common.BaseEntity; +import org.navalplanner.business.calendars.daos.ICalendarExceptionDAO; +import org.navalplanner.business.common.IntegrationEntity; +import org.navalplanner.business.common.Registry; /** * Represents an exceptional day that has a different number of hours. For @@ -34,22 +36,16 @@ import org.navalplanner.business.common.BaseEntity; * * @author Manuel Rego Casasnovas */ -public class CalendarException extends BaseEntity { +public class CalendarException extends IntegrationEntity { public static CalendarException create(Date date, Integer hours, CalendarExceptionType type) { - CalendarException exceptionDay = new CalendarException(new LocalDate( - date), hours, type); - exceptionDay.setNewObject(true); - return exceptionDay; + return create(new CalendarException(new LocalDate(date), hours, type)); } public static CalendarException create(LocalDate date, Integer hours, CalendarExceptionType type) { - CalendarException exceptionDay = new CalendarException(date, hours, - type); - exceptionDay.setNewObject(true); - return exceptionDay; + return create(new CalendarException(date, hours, type)); } private LocalDate date; @@ -85,4 +81,9 @@ public class CalendarException extends BaseEntity { return type; } + @Override + protected ICalendarExceptionDAO getIntegrationEntityDAO() { + return Registry.getCalendarExceptionDAO(); + } + } diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/common/Registry.java b/navalplanner-business/src/main/java/org/navalplanner/business/common/Registry.java index 2ed0c7357..f8ca7feaa 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/common/Registry.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/common/Registry.java @@ -22,6 +22,8 @@ package org.navalplanner.business.common; import org.navalplanner.business.advance.daos.IAdvanceTypeDAO; import org.navalplanner.business.calendars.daos.IBaseCalendarDAO; +import org.navalplanner.business.calendars.daos.ICalendarDataDAO; +import org.navalplanner.business.calendars.daos.ICalendarExceptionDAO; import org.navalplanner.business.calendars.daos.ICalendarExceptionTypeDAO; import org.navalplanner.business.common.daos.IConfigurationDAO; import org.navalplanner.business.costcategories.daos.ICostCategoryDAO; @@ -154,6 +156,12 @@ public class Registry { @Autowired private IHourCostDAO hourCostDAO; + @Autowired + private ICalendarExceptionDAO calendarExceptionDAO; + + @Autowired + private ICalendarDataDAO calendarDataDAO; + @Autowired private ICalendarExceptionTypeDAO calendarExceptionTypeDAO; @@ -282,4 +290,12 @@ public class Registry { return getInstance().calendarExceptionTypeDAO; } + public static ICalendarExceptionDAO getCalendarExceptionDAO() { + return getInstance().calendarExceptionDAO; + } + + public static ICalendarDataDAO getCalendarDataDAO() { + return getInstance().calendarDataDAO; + } + } \ No newline at end of file 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 25e6d97b2..1e9d2b822 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 @@ -51,6 +51,8 @@ + + @@ -85,6 +87,8 @@ + + diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/BaseCalendarDTO.java b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/BaseCalendarDTO.java index dad6cd1ff..6099c737b 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/BaseCalendarDTO.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/BaseCalendarDTO.java @@ -20,7 +20,12 @@ package org.navalplanner.ws.calendars.api; +import java.util.ArrayList; +import java.util.List; + import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; import org.navalplanner.business.calendars.entities.BaseCalendar; import org.navalplanner.ws.common.api.IntegrationEntityDTO; @@ -37,16 +42,30 @@ public class BaseCalendarDTO extends IntegrationEntityDTO { @XmlAttribute public String name; + @XmlElementWrapper(name = "calendar-exception-list") + @XmlElement(name = "calendar-exception") + public List calendarExceptions = new ArrayList(); + + @XmlElementWrapper(name = "calendar-data-list") + @XmlElement(name = "calendar-data") + public List calendarDatas = new ArrayList(); + public BaseCalendarDTO() { } - public BaseCalendarDTO(String code, String name) { + public BaseCalendarDTO(String code, String name, + List calendarExceptions, + List calendarDatas) { super(code); this.name = name; + this.calendarExceptions = calendarExceptions; + this.calendarDatas = calendarDatas; } - public BaseCalendarDTO(String name) { - this(generateCode(), name); + public BaseCalendarDTO(String name, + List calendarExceptions, + List calendarDatas) { + this(generateCode(), name, calendarExceptions, calendarDatas); } @Override @@ -54,4 +73,4 @@ public class BaseCalendarDTO extends IntegrationEntityDTO { return ENTITY_TYPE; } -} +} \ No newline at end of file diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/BaseCalendarListDTO.java b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/BaseCalendarListDTO.java index ec62aa268..656e0af90 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/BaseCalendarListDTO.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/BaseCalendarListDTO.java @@ -45,4 +45,4 @@ public class BaseCalendarListDTO { this.baseCalendars = baseCalendars; } -} +} \ No newline at end of file diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/CalendarDataDTO.java b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/CalendarDataDTO.java new file mode 100644 index 000000000..b086f1290 --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/CalendarDataDTO.java @@ -0,0 +1,74 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * 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.calendars.api; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; + +import org.navalplanner.business.calendars.entities.CalendarData; +import org.navalplanner.ws.common.api.IntegrationEntityDTO; + +/** + * DTO for {@link CalendarData} entity. + * + * @author Manuel Rego Casasnovas + */ +public class CalendarDataDTO extends IntegrationEntityDTO { + + public final static String ENTITY_TYPE = "calendar-data"; + + @XmlElementWrapper(name = "hors-per-day-list") + @XmlElement(name = "hors-per-day") + public List hoursPerDays = new ArrayList(); + + @XmlAttribute(name = "expiring-date") + public Date expiringDate; + + @XmlAttribute(name = "parent-calendar") + public String parentCalendar; + + public CalendarDataDTO() { + } + + public CalendarDataDTO(String code, List hoursPerDays, + Date expiringDate, String parentCalendar) { + super(code); + this.hoursPerDays = hoursPerDays; + this.expiringDate = expiringDate; + this.parentCalendar = parentCalendar; + } + + public CalendarDataDTO(List hoursPerDays, + Date expiringDate, String parentCalendar) { + this(generateCode(), hoursPerDays, expiringDate, parentCalendar); + } + + @Override + public String getEntityType() { + return ENTITY_TYPE; + } + +} diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/CalendarExceptionDTO.java b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/CalendarExceptionDTO.java new file mode 100644 index 000000000..085674689 --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/CalendarExceptionDTO.java @@ -0,0 +1,69 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * 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.calendars.api; + +import java.util.Date; + +import javax.xml.bind.annotation.XmlAttribute; + +import org.navalplanner.business.calendars.entities.CalendarException; +import org.navalplanner.ws.common.api.IntegrationEntityDTO; + +/** + * DTO for {@link CalendarException} entity. + * + * @author Manuel Rego Casasnovas + */ +public class CalendarExceptionDTO extends IntegrationEntityDTO { + + public final static String ENTITY_TYPE = "calendar-exception"; + + @XmlAttribute + public Date date; + + @XmlAttribute + public Integer hours; + + @XmlAttribute(name = "calendar-exception-type-name") + public String calendarExceptionTypeName; + + public CalendarExceptionDTO() { + } + + public CalendarExceptionDTO(String code, Date date, Integer hours, + String calendarExceptionTypeName) { + super(code); + this.date = date; + this.hours = hours; + this.calendarExceptionTypeName = calendarExceptionTypeName; + } + + public CalendarExceptionDTO(Date date, Integer hours, + String calendarExceptionTypeName) { + this(generateCode(), date, hours, calendarExceptionTypeName); + } + + @Override + public String getEntityType() { + return ENTITY_TYPE; + } + +} diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/HoursPerDayDTO.java b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/HoursPerDayDTO.java new file mode 100644 index 000000000..4fe553aff --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/HoursPerDayDTO.java @@ -0,0 +1,48 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * 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.calendars.api; + +import javax.xml.bind.annotation.XmlAttribute; + +import org.navalplanner.business.calendars.entities.CalendarData; + +/** + * DTO for represent hours per day of {@link CalendarData} entity. + * + * @author Manuel Rego Casasnovas + */ +public class HoursPerDayDTO { + + @XmlAttribute + public String day; + + @XmlAttribute + public Integer hours; + + public HoursPerDayDTO() { + } + + public HoursPerDayDTO(String day, Integer hours) { + this.day = day; + this.hours = hours; + } + +} diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/ICalendarService.java b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/ICalendarService.java index 98b190958..94f9ca754 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/ICalendarService.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/api/ICalendarService.java @@ -31,4 +31,4 @@ public interface ICalendarService { BaseCalendarListDTO getBaseCalendars(); -} +} \ No newline at end of file diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/impl/CalendarConverter.java b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/impl/CalendarConverter.java index 87b5a307e..06e0ae25f 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/impl/CalendarConverter.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/impl/CalendarConverter.java @@ -20,8 +20,18 @@ package org.navalplanner.ws.calendars.impl; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + import org.navalplanner.business.calendars.entities.BaseCalendar; +import org.navalplanner.business.calendars.entities.CalendarData; +import org.navalplanner.business.calendars.entities.CalendarException; +import org.navalplanner.business.calendars.entities.CalendarData.Days; import org.navalplanner.ws.calendars.api.BaseCalendarDTO; +import org.navalplanner.ws.calendars.api.CalendarDataDTO; +import org.navalplanner.ws.calendars.api.CalendarExceptionDTO; +import org.navalplanner.ws.calendars.api.HoursPerDayDTO; /** * Converter from/to {@link BaseCalendar} related entities to/from DTOs. @@ -34,8 +44,46 @@ public final class CalendarConverter { } public final static BaseCalendarDTO toDTO(BaseCalendar baseCalendar) { + List calendarExceptionDTOs = new ArrayList(); + for (CalendarException calendarException : baseCalendar.getExceptions()) { + calendarExceptionDTOs.add(toDTO(calendarException)); + } + + List calendarDataDTOs = new ArrayList(); + for (CalendarData calendarData : baseCalendar.getCalendarDataVersions()) { + calendarDataDTOs.add(toDTO(calendarData)); + } + return new BaseCalendarDTO(baseCalendar.getCode(), baseCalendar - .getName()); + .getName(), calendarExceptionDTOs, calendarDataDTOs); } -} + private final static CalendarExceptionDTO toDTO( + CalendarException calendarException) { + return new CalendarExceptionDTO(calendarException.getCode(), + calendarException.getDate().toDateTimeAtStartOfDay().toDate(), + calendarException.getHours(), calendarException.getType() + .getName()); + } + + private final static CalendarDataDTO toDTO(CalendarData calendarData) { + List hoursPerDayDTOs = new ArrayList(); + Days[] days = CalendarData.Days.values(); + for (Integer day : calendarData.getHoursPerDay().keySet()) { + String dayName = days[day].name(); + Integer hours = calendarData.getHoursPerDay().get(day); + hoursPerDayDTOs.add(new HoursPerDayDTO(dayName, hours)); + } + + Date expiringDate = (calendarData.getExpiringDate() != null) ? calendarData + .getExpiringDate().toDateTimeAtStartOfDay().toDate() + : null; + String parentCalendar = (calendarData.getParent() != null) ? calendarData + .getParent().getCode() + : null; + + return new CalendarDataDTO(hoursPerDayDTOs, expiringDate, + parentCalendar); + } + +} \ No newline at end of file diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/impl/CalendarServiceREST.java b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/impl/CalendarServiceREST.java index 5e43c813f..7a9b02029 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/impl/CalendarServiceREST.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/ws/calendars/impl/CalendarServiceREST.java @@ -20,13 +20,14 @@ package org.navalplanner.ws.calendars.impl; +import java.util.List; + import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import org.navalplanner.business.calendars.daos.IBaseCalendarDAO; import org.navalplanner.business.calendars.entities.BaseCalendar; -import org.navalplanner.business.common.daos.IIntegrationEntityDAO; import org.navalplanner.business.common.exceptions.ValidationException; import org.navalplanner.ws.calendars.api.BaseCalendarDTO; import org.navalplanner.ws.calendars.api.BaseCalendarListDTO; @@ -54,7 +55,7 @@ public class CalendarServiceREST extends private IBaseCalendarDAO baseCalendarDAO; @Override - protected IIntegrationEntityDAO getIntegrationEntityDAO() { + protected IBaseCalendarDAO getIntegrationEntityDAO() { return baseCalendarDAO; } @@ -81,7 +82,10 @@ public class CalendarServiceREST extends @GET @Transactional(readOnly = true) public BaseCalendarListDTO getBaseCalendars() { - return new BaseCalendarListDTO(findAll()); + // Avoid ResourceCalendar entities + List justBaseCalendars = getIntegrationEntityDAO() + .getBaseCalendars(); + return new BaseCalendarListDTO(toDTO(justBaseCalendars)); } } \ No newline at end of file diff --git a/scripts/rest-clients/README b/scripts/rest-clients/README index 3e2dbeed3..a689b64bf 100644 --- a/scripts/rest-clients/README +++ b/scripts/rest-clients/README @@ -82,6 +82,10 @@ - export-calendar-exception-types.sh (authenticate with wsreader/wsreader) + * Export calendars: + + - export-calendars.sh (authenticate with wsreader/wsreader) + + When working with the online demo add "--prod" argument to every command. Example: diff --git a/scripts/rest-clients/export-calendars.sh b/scripts/rest-clients/export-calendars.sh new file mode 100755 index 000000000..ceeaa29f2 --- /dev/null +++ b/scripts/rest-clients/export-calendars.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +. ./rest-common-env.sh + +printf "Login name: " +read loginName +printf "Password: " +read password + +if [ "$1" = "--prod" ]; then + baseServiceURL=$PRODUCTION_BASE_SERVICE_URL + certificate=$PRODUCTION_CERTIFICATE +else + baseServiceURL=$DEVELOPMENT_BASE_SERVICE_URL + certificate=$DEVELOPMENT_CERTIFICATE +fi + +authorization=`./base64.sh $loginName:$password` + +curl -sv -X GET $certificate --header "Authorization: Basic $authorization" \ + $baseServiceURL/calendars | tidy -xml -i -q -utf8