ItEr50S13AdaptacionServiciosRESTItEr49S18: Basic structure for the new calendars service.
This commit is contained in:
parent
7fe11da2cf
commit
664a25ec8d
12 changed files with 414 additions and 9 deletions
|
|
@ -29,7 +29,7 @@ import org.hibernate.Criteria;
|
|||
import org.hibernate.criterion.Restrictions;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.calendars.entities.ResourceCalendar;
|
||||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
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;
|
||||
|
|
@ -44,7 +44,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class BaseCalendarDAO extends GenericDAOHibernate<BaseCalendar, Long>
|
||||
public class BaseCalendarDAO extends IntegrationEntityDAO<BaseCalendar>
|
||||
implements IBaseCalendarDAO {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -23,14 +23,15 @@ package org.navalplanner.business.calendars.daos;
|
|||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.common.daos.IGenericDAO;
|
||||
import org.navalplanner.business.common.daos.IIntegrationEntityDAO;
|
||||
|
||||
/**
|
||||
* Contract for {@link BaseCalendarDAO}
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public interface IBaseCalendarDAO extends IGenericDAO<BaseCalendar, Long> {
|
||||
public interface IBaseCalendarDAO extends
|
||||
IIntegrationEntityDAO<BaseCalendar> {
|
||||
|
||||
List<BaseCalendar> getBaseCalendars();
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,9 @@ import java.util.Set;
|
|||
import org.hibernate.validator.NotEmpty;
|
||||
import org.joda.time.DateTimeConstants;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.calendars.daos.IBaseCalendarDAO;
|
||||
import org.navalplanner.business.calendars.entities.CalendarData.Days;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
import org.navalplanner.business.common.IntegrationEntity;
|
||||
import org.navalplanner.business.planner.entities.ResourcesPerDay;
|
||||
|
||||
/**
|
||||
|
|
@ -41,14 +42,12 @@ import org.navalplanner.business.planner.entities.ResourcesPerDay;
|
|||
* some exceptions of its parent calendar.
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class BaseCalendar extends BaseEntity implements IWorkHours {
|
||||
public class BaseCalendar extends IntegrationEntity implements IWorkHours {
|
||||
|
||||
private static final Integer DEFAULT_VALUE = 0;
|
||||
|
||||
public static BaseCalendar create() {
|
||||
BaseCalendar baseCalendar = new BaseCalendar(CalendarData.create());
|
||||
baseCalendar.setNewObject(true);
|
||||
return baseCalendar;
|
||||
return create(new BaseCalendar(CalendarData.create()));
|
||||
}
|
||||
|
||||
@NotEmpty
|
||||
|
|
@ -938,4 +937,9 @@ public class BaseCalendar extends BaseEntity implements IWorkHours {
|
|||
return each.getHours() != 0 || each.getType().isOverAssignable();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IBaseCalendarDAO getIntegrationEntityDAO() {
|
||||
return org.navalplanner.business.common.Registry.getBaseCalendarDAO();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
</id>
|
||||
<version name="version" access="property" type="long" />
|
||||
|
||||
<property name="code" access="property" not-null="true" unique="true"/>
|
||||
|
||||
<property name="name" access="field"/>
|
||||
|
||||
<set name="exceptions" access="field" cascade="all-delete-orphan">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.ws.calendars.api;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.ws.common.api.IntegrationEntityDTO;
|
||||
|
||||
/**
|
||||
* DTO for {@link BaseCalendar} entity.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class BaseCalendarDTO extends IntegrationEntityDTO {
|
||||
|
||||
public final static String ENTITY_TYPE = "base-calendar";
|
||||
|
||||
@XmlAttribute
|
||||
public String name;
|
||||
|
||||
public BaseCalendarDTO() {
|
||||
}
|
||||
|
||||
public BaseCalendarDTO(String code, String name) {
|
||||
super(code);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public BaseCalendarDTO(String name) {
|
||||
this(generateCode(), name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEntityType() {
|
||||
return ENTITY_TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.ws.calendars.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
|
||||
/**
|
||||
* DTO for a list of {@link BaseCalendar} entities.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@XmlRootElement(name = "base-calendar-list")
|
||||
public class BaseCalendarListDTO {
|
||||
|
||||
@XmlElement(name = "base-calendar")
|
||||
public List<BaseCalendarDTO> baseCalendars = new ArrayList<BaseCalendarDTO>();
|
||||
|
||||
public BaseCalendarListDTO() {}
|
||||
|
||||
public BaseCalendarListDTO(List<BaseCalendarDTO> baseCalendars) {
|
||||
this.baseCalendars = baseCalendars;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.ws.calendars.api;
|
||||
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
|
||||
/**
|
||||
* Service for managing {@link BaseCalendar} entities.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public interface ICalendarService {
|
||||
|
||||
BaseCalendarListDTO getBaseCalendars();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Specification of namespace for REST-based services.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@javax.xml.bind.annotation.XmlSchema(elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, namespace = WSCommonGlobalNames.REST_NAMESPACE)
|
||||
package org.navalplanner.ws.calendars.api;
|
||||
|
||||
import org.navalplanner.ws.common.api.WSCommonGlobalNames;
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.ws.calendars.impl;
|
||||
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.ws.calendars.api.BaseCalendarDTO;
|
||||
|
||||
/**
|
||||
* Converter from/to {@link BaseCalendar} related entities to/from DTOs.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public final class CalendarConverter {
|
||||
|
||||
private CalendarConverter() {
|
||||
}
|
||||
|
||||
public final static BaseCalendarDTO toDTO(BaseCalendar baseCalendar) {
|
||||
return new BaseCalendarDTO(baseCalendar.getCode(), baseCalendar
|
||||
.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.ws.calendars.impl;
|
||||
|
||||
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;
|
||||
import org.navalplanner.ws.calendars.api.ICalendarService;
|
||||
import org.navalplanner.ws.common.impl.GenericRESTService;
|
||||
import org.navalplanner.ws.common.impl.RecoverableErrorException;
|
||||
import org.navalplanner.ws.labels.api.ILabelService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* REST-based implementation of {@link ILabelService}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@Path("/calendars/")
|
||||
@Produces("application/xml")
|
||||
@Service("calendarServiceREST")
|
||||
public class CalendarServiceREST extends
|
||||
GenericRESTService<BaseCalendar, BaseCalendarDTO> implements
|
||||
ICalendarService {
|
||||
|
||||
@Autowired
|
||||
private IBaseCalendarDAO baseCalendarDAO;
|
||||
|
||||
@Override
|
||||
protected IIntegrationEntityDAO<BaseCalendar> getIntegrationEntityDAO() {
|
||||
return baseCalendarDAO;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseCalendarDTO toDTO(BaseCalendar entity) {
|
||||
return CalendarConverter.toDTO(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseCalendar toEntity(BaseCalendarDTO entityDTO)
|
||||
throws ValidationException, RecoverableErrorException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateEntity(BaseCalendar entity, BaseCalendarDTO entityDTO)
|
||||
throws ValidationException, RecoverableErrorException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@GET
|
||||
@Transactional(readOnly = true)
|
||||
public BaseCalendarListDTO getBaseCalendars() {
|
||||
return new BaseCalendarListDTO(findAll());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -72,6 +72,7 @@
|
|||
<ref bean="costCategoryServiceREST"/>
|
||||
<ref bean="typeOfWorkHoursServiceREST"/>
|
||||
<ref bean="calendarExceptionTypeServiceREST"/>
|
||||
<ref bean="calendarServiceREST"/>
|
||||
</jaxrs:serviceBeans>
|
||||
<jaxrs:providers>
|
||||
<ref bean="runtimeExceptionMapper" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.web.test.ws.labels.api;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
|
||||
import static org.navalplanner.web.WebappGlobalNames.WEBAPP_SPRING_CONFIG_FILE;
|
||||
import static org.navalplanner.web.test.WebappGlobalNames.WEBAPP_SPRING_CONFIG_TEST_FILE;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.calendars.daos.IBaseCalendarDAO;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.common.IAdHocTransactionService;
|
||||
import org.navalplanner.ws.calendars.api.BaseCalendarDTO;
|
||||
import org.navalplanner.ws.calendars.api.BaseCalendarListDTO;
|
||||
import org.navalplanner.ws.calendars.api.ICalendarService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Tests for {@link ICalendarService}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
|
||||
WEBAPP_SPRING_CONFIG_FILE, WEBAPP_SPRING_CONFIG_TEST_FILE })
|
||||
@Transactional
|
||||
public class CalendarServiceTest {
|
||||
|
||||
@Autowired
|
||||
private ICalendarService calendarService;
|
||||
|
||||
@Autowired
|
||||
private IBaseCalendarDAO baseCalendarDAO;
|
||||
|
||||
@Autowired
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
@Autowired
|
||||
private IAdHocTransactionService transactionService;
|
||||
|
||||
private BaseCalendar givenBaseCalendarStored() {
|
||||
BaseCalendar calendar = BaseCalendar.create();
|
||||
calendar.setName("calendar-name");
|
||||
|
||||
baseCalendarDAO.save(calendar);
|
||||
baseCalendarDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(calendar);
|
||||
calendar.dontPoseAsTransientObjectAnymore();
|
||||
|
||||
return calendar;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportBaseCalendars() {
|
||||
int previous = baseCalendarDAO.getBaseCalendars().size();
|
||||
|
||||
BaseCalendarListDTO baseCalendars = calendarService.getBaseCalendars();
|
||||
assertThat(baseCalendars.baseCalendars.size(), equalTo(previous));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportBaseCalendars2() {
|
||||
int previous = baseCalendarDAO.getBaseCalendars().size();
|
||||
|
||||
BaseCalendar calendar = givenBaseCalendarStored();
|
||||
|
||||
BaseCalendarListDTO baseCalendars = calendarService.getBaseCalendars();
|
||||
assertThat(baseCalendars.baseCalendars.size(), equalTo(previous + 1));
|
||||
|
||||
BaseCalendarDTO calendarDTO = baseCalendars.baseCalendars.get(previous);
|
||||
assertThat(calendarDTO.code, equalTo(calendar.getCode()));
|
||||
assertThat(calendarDTO.name, equalTo(calendar.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue