ItEr50S13AdaptacionServiciosRESTItEr49S18 : Creation and Adapting of TypeOfWorkHoursServiceRest.
This commit is contained in:
parent
ae3bf8193a
commit
105a2f0169
18 changed files with 660 additions and 14 deletions
|
|
@ -22,14 +22,15 @@ package org.navalplanner.business.costcategories.daos;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.common.daos.IGenericDAO;
|
||||
import org.navalplanner.business.common.daos.IIntegrationEntityDAO;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.costcategories.entities.TypeOfWorkHours;
|
||||
|
||||
/**
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
*/
|
||||
public interface ITypeOfWorkHoursDAO extends IGenericDAO<TypeOfWorkHours, Long> {
|
||||
public interface ITypeOfWorkHoursDAO extends
|
||||
IIntegrationEntityDAO<TypeOfWorkHours> {
|
||||
|
||||
TypeOfWorkHours findUniqueByCode(TypeOfWorkHours typeOfWorkHours)
|
||||
throws InstanceNotFoundException;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import java.util.List;
|
|||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
import org.navalplanner.business.common.daos.IntegrationEntityDAO;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.costcategories.entities.TypeOfWorkHours;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
|
@ -40,7 +40,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class TypeOfWorkHoursDAO extends GenericDAOHibernate<TypeOfWorkHours, Long> implements
|
||||
public class TypeOfWorkHoursDAO extends IntegrationEntityDAO<TypeOfWorkHours>
|
||||
implements
|
||||
ITypeOfWorkHoursDAO {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -22,9 +22,10 @@ package org.navalplanner.business.costcategories.entities;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
import org.navalplanner.business.common.IntegrationEntity;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.costcategories.daos.ITypeOfWorkHoursDAO;
|
||||
|
|
@ -32,12 +33,10 @@ import org.navalplanner.business.costcategories.daos.ITypeOfWorkHoursDAO;
|
|||
/**
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
*/
|
||||
public class TypeOfWorkHours extends BaseEntity {
|
||||
public class TypeOfWorkHours extends IntegrationEntity {
|
||||
|
||||
@NotEmpty
|
||||
private String code;
|
||||
|
||||
@NotEmpty
|
||||
private String name;
|
||||
|
||||
private BigDecimal defaultPrice;
|
||||
|
|
@ -57,11 +56,40 @@ public class TypeOfWorkHours extends BaseEntity {
|
|||
return (TypeOfWorkHours) create(new TypeOfWorkHours(code, name));
|
||||
}
|
||||
|
||||
public static TypeOfWorkHours createUnvalidated(String code, String name,
|
||||
Boolean enabled, BigDecimal defaultPrice) {
|
||||
|
||||
TypeOfWorkHours typeOfWorkHours = create(
|
||||
new TypeOfWorkHours(code, name), code);
|
||||
|
||||
if (enabled != null) {
|
||||
typeOfWorkHours.enabled = enabled;
|
||||
}
|
||||
if (defaultPrice != null) {
|
||||
typeOfWorkHours.defaultPrice = defaultPrice;
|
||||
}
|
||||
return typeOfWorkHours;
|
||||
}
|
||||
|
||||
public void updateUnvalidated(String name, Boolean enabled,
|
||||
BigDecimal defaultPrice) {
|
||||
if (!StringUtils.isBlank(name)) {
|
||||
this.name = name;
|
||||
}
|
||||
if (enabled != null) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
if (defaultPrice != null) {
|
||||
this.defaultPrice = defaultPrice;
|
||||
}
|
||||
}
|
||||
|
||||
protected TypeOfWorkHours(String code, String name) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@NotEmpty(message = "name not specified")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
@ -70,6 +98,7 @@ public class TypeOfWorkHours extends BaseEntity {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
@NotEmpty(message = "code not specified")
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
|
@ -96,6 +125,11 @@ public class TypeOfWorkHours extends BaseEntity {
|
|||
|
||||
@AssertTrue(message="type code has to be unique. It is already used")
|
||||
public boolean checkConstraintUniqueCode() {
|
||||
|
||||
if (code == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean result;
|
||||
if (isNewObject()) {
|
||||
result = !existsTypeWithTheCode();
|
||||
|
|
@ -120,4 +154,9 @@ public class TypeOfWorkHours extends BaseEntity {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ITypeOfWorkHoursDAO getIntegrationEntityDAO() {
|
||||
return Registry.getTypeOfWorkHoursDAO();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
/*
|
||||
* 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.costcategories.api;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ public class CostCategoryConverter {
|
|||
public final static void updateCostCategory(CostCategory costCategory,
|
||||
CostCategoryDTO costCategoryDTO) throws ValidationException {
|
||||
/*
|
||||
* 1: Update the existing work report line or add newwork report line.
|
||||
* 1: Update the existing hour cost or add new hour cost.
|
||||
*/
|
||||
for (HourCostDTO hourCostDTO : costCategoryDTO.hourCostDTOs) {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.typeofworkhours.api;
|
||||
|
||||
import org.navalplanner.ws.common.api.InstanceConstraintViolationsListDTO;
|
||||
|
||||
/**
|
||||
* Service for managing cost categories.
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
public interface ITypeOfWorkHoursService {
|
||||
|
||||
InstanceConstraintViolationsListDTO addTypeOfWorkHours(
|
||||
TypeOfWorkHoursListDTO typeOfWorkHoursListDTO);
|
||||
|
||||
public TypeOfWorkHoursListDTO getTypeOfWorkHours();
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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.typeofworkhours.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
import org.navalplanner.business.costcategories.entities.TypeOfWorkHours;
|
||||
import org.navalplanner.ws.common.api.IntegrationEntityDTO;
|
||||
|
||||
/**
|
||||
* DTO for {@link TypeOfWorkHours} entity.
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
public class TypeOfWorkHoursDTO extends IntegrationEntityDTO {
|
||||
|
||||
public final static String ENTITY_TYPE = "type-work-hours";
|
||||
|
||||
@XmlAttribute
|
||||
public String name;
|
||||
|
||||
@XmlAttribute
|
||||
public BigDecimal defaultPrice;
|
||||
|
||||
@XmlAttribute
|
||||
public Boolean enabled;
|
||||
|
||||
public TypeOfWorkHoursDTO() {
|
||||
}
|
||||
|
||||
public TypeOfWorkHoursDTO(String code, String name, Boolean enabled,
|
||||
BigDecimal defaultPrice) {
|
||||
|
||||
super(code);
|
||||
this.name = name;
|
||||
this.enabled = enabled;
|
||||
this.defaultPrice = defaultPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor automatically generates a unique code. It is intended to
|
||||
* facilitate the implementation of test cases that add new instances (such
|
||||
* instances will have a unique code).
|
||||
*/
|
||||
public TypeOfWorkHoursDTO(String name, Boolean enabled,
|
||||
BigDecimal defaultPrice) {
|
||||
|
||||
this(generateCode(), name, enabled, defaultPrice);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEntityType() {
|
||||
return ENTITY_TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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.typeofworkhours.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* DTO for a list of <code>TypeOfWorkHours</code> entities.
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@XmlRootElement(name = "type-work-hours-list")
|
||||
public class TypeOfWorkHoursListDTO {
|
||||
|
||||
@XmlElement(name = "type-work-hours")
|
||||
public List<TypeOfWorkHoursDTO> typeOfWorkHoursDTOs = new ArrayList<TypeOfWorkHoursDTO>();
|
||||
|
||||
public TypeOfWorkHoursListDTO() {
|
||||
}
|
||||
|
||||
public TypeOfWorkHoursListDTO(List<TypeOfWorkHoursDTO> typeOfWorkHoursDTOs) {
|
||||
this.typeOfWorkHoursDTOs = typeOfWorkHoursDTOs;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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 Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@javax.xml.bind.annotation.XmlSchema(elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, namespace = WSCommonGlobalNames.REST_NAMESPACE)
|
||||
package org.navalplanner.ws.typeofworkhours.api;
|
||||
import org.navalplanner.ws.common.api.WSCommonGlobalNames;
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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.typeofworkhours.impl;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.costcategories.entities.TypeOfWorkHours;
|
||||
import org.navalplanner.ws.typeofworkhours.api.TypeOfWorkHoursDTO;
|
||||
|
||||
/**
|
||||
* Converter from/to Type-Of-Work-Hours-related entities to/from DTOs.
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
public class TypeOfWorkHoursConverter {
|
||||
|
||||
private TypeOfWorkHoursConverter() {
|
||||
}
|
||||
|
||||
public final static TypeOfWorkHoursDTO toDTO(TypeOfWorkHours typeOfWorkHours) {
|
||||
return new TypeOfWorkHoursDTO(typeOfWorkHours.getCode(),
|
||||
typeOfWorkHours.getName(), typeOfWorkHours.getEnabled(),
|
||||
typeOfWorkHours.getDefaultPrice());
|
||||
|
||||
}
|
||||
|
||||
public final static TypeOfWorkHours toEntity(
|
||||
TypeOfWorkHoursDTO typeOfWorkHoursDTO) {
|
||||
|
||||
TypeOfWorkHours typeOfWorkHours = TypeOfWorkHours.createUnvalidated(
|
||||
StringUtils.trim(typeOfWorkHoursDTO.code), StringUtils
|
||||
.trim(typeOfWorkHoursDTO.name),
|
||||
typeOfWorkHoursDTO.enabled, typeOfWorkHoursDTO.defaultPrice);
|
||||
|
||||
return typeOfWorkHours;
|
||||
|
||||
}
|
||||
|
||||
public final static void updateTypeOfWorkHours(
|
||||
TypeOfWorkHours typeOfWorkHours,
|
||||
TypeOfWorkHoursDTO typeOfWorkHoursDTO) throws ValidationException {
|
||||
/* 1: Update typeOfWorkHours basic properties. */
|
||||
typeOfWorkHours.updateUnvalidated(StringUtils
|
||||
.trim(typeOfWorkHoursDTO.name), typeOfWorkHoursDTO.enabled,
|
||||
typeOfWorkHoursDTO.defaultPrice);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* 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.typeofworkhours.impl;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.navalplanner.business.common.daos.IIntegrationEntityDAO;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.costcategories.daos.ITypeOfWorkHoursDAO;
|
||||
import org.navalplanner.business.costcategories.entities.TypeOfWorkHours;
|
||||
import org.navalplanner.ws.common.api.InstanceConstraintViolationsListDTO;
|
||||
import org.navalplanner.ws.common.impl.GenericRESTService;
|
||||
import org.navalplanner.ws.typeofworkhours.api.ITypeOfWorkHoursService;
|
||||
import org.navalplanner.ws.typeofworkhours.api.TypeOfWorkHoursDTO;
|
||||
import org.navalplanner.ws.typeofworkhours.api.TypeOfWorkHoursListDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* REST-based implementation of <code>ITypeOfWorkHoursService</code>.
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
@Path("/typeofworkhours/")
|
||||
@Produces("application/xml")
|
||||
@Service("typeOfWorkHoursServiceREST")
|
||||
public class TypeOfWorkHoursServiceREST extends
|
||||
GenericRESTService<TypeOfWorkHours, TypeOfWorkHoursDTO> implements
|
||||
ITypeOfWorkHoursService {
|
||||
|
||||
@Autowired
|
||||
private ITypeOfWorkHoursDAO typeOfWorkHoursDAO;
|
||||
|
||||
@Override
|
||||
@GET
|
||||
@Transactional(readOnly = true)
|
||||
public TypeOfWorkHoursListDTO getTypeOfWorkHours() {
|
||||
return new TypeOfWorkHoursListDTO(findAll());
|
||||
}
|
||||
|
||||
@Override
|
||||
@POST
|
||||
@Consumes("application/xml")
|
||||
public InstanceConstraintViolationsListDTO addTypeOfWorkHours(
|
||||
TypeOfWorkHoursListDTO typeOfWorkHoursListDTO) {
|
||||
|
||||
return save(typeOfWorkHoursListDTO.typeOfWorkHoursDTOs);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeOfWorkHours toEntity(TypeOfWorkHoursDTO entityDTO) {
|
||||
return TypeOfWorkHoursConverter.toEntity(entityDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeOfWorkHoursDTO toDTO(TypeOfWorkHours entity) {
|
||||
return TypeOfWorkHoursConverter.toDTO(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IIntegrationEntityDAO<TypeOfWorkHours> getIntegrationEntityDAO() {
|
||||
return typeOfWorkHoursDAO;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateEntity(TypeOfWorkHours entity,
|
||||
TypeOfWorkHoursDTO entityDTO)
|
||||
throws ValidationException {
|
||||
|
||||
TypeOfWorkHoursConverter.updateTypeOfWorkHours(entity, entityDTO);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -66,6 +66,7 @@
|
|||
<ref bean="workReportServiceREST"/>
|
||||
<ref bean="labelServiceREST"/>
|
||||
<ref bean="costCategoryServiceREST"/>
|
||||
<ref bean="typeOfWorkHoursServiceREST"/>
|
||||
</jaxrs:serviceBeans>
|
||||
<jaxrs:providers>
|
||||
<ref bean="runtimeExceptionMapper" />
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ public class CostCategoryServiceTest {
|
|||
cc4_HourCostDTOs.add(cc4_1_HourCostDTO);
|
||||
CostCategoryDTO cc4 = new CostCategoryDTO("cc4", true, cc4_HourCostDTOs);
|
||||
|
||||
/* Criterion type list. */
|
||||
/* Cost category type list. */
|
||||
CostCategoryListDTO costCategoryListDTO = createCostCategoryListDTO(
|
||||
cc1, cc2, cc3, cc4);
|
||||
|
||||
|
|
@ -178,7 +178,6 @@ public class CostCategoryServiceTest {
|
|||
cc1_HourCostDTOs.add(cc1_1_HourCostDTO);
|
||||
CostCategoryDTO cc1 = new CostCategoryDTO(costCategoryCode,"newCC1", true, cc1_HourCostDTOs);
|
||||
|
||||
/* Criterion type list. */
|
||||
CostCategoryListDTO costCategoryListDTO = createCostCategoryListDTO(cc1);
|
||||
|
||||
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = costCategoryService
|
||||
|
|
@ -209,20 +208,19 @@ public class CostCategoryServiceTest {
|
|||
cc2_HourCostDTOs.add(cc2_1_HourCostDTO);
|
||||
CostCategoryDTO cc2 = new CostCategoryDTO(costCategoryCode,"updateCC1", false, cc2_HourCostDTOs);
|
||||
|
||||
/* Criterion type list. */
|
||||
/* Cost category type list. */
|
||||
costCategoryListDTO = createCostCategoryListDTO(cc2);
|
||||
|
||||
instanceConstraintViolationsList = costCategoryService
|
||||
.addCostCategories(costCategoryListDTO).instanceConstraintViolationsList;
|
||||
|
||||
/* Test. */
|
||||
// the end date cannot be before the initDate
|
||||
assertTrue(instanceConstraintViolationsList.toString(),
|
||||
instanceConstraintViolationsList.size() == 0);
|
||||
assertTrue(costCategoryDAO.existsByCode(cc1.code));
|
||||
assertTrue(hourCostDAO.existsByCode(cc1_1_HourCostDTO.code));
|
||||
|
||||
// Check if the changes was updated
|
||||
// Check if the changes was updated
|
||||
try {
|
||||
costCategory = costCategoryDAO
|
||||
.findByCode(costCategoryCode);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* 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.typeofworkhours;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
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 java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.costcategories.daos.ITypeOfWorkHoursDAO;
|
||||
import org.navalplanner.business.costcategories.entities.TypeOfWorkHours;
|
||||
import org.navalplanner.ws.common.api.InstanceConstraintViolationsDTO;
|
||||
import org.navalplanner.ws.typeofworkhours.api.ITypeOfWorkHoursService;
|
||||
import org.navalplanner.ws.typeofworkhours.api.TypeOfWorkHoursDTO;
|
||||
import org.navalplanner.ws.typeofworkhours.api.TypeOfWorkHoursListDTO;
|
||||
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 <code>ITypeOfWorkHoursService</code>.
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
|
||||
WEBAPP_SPRING_CONFIG_FILE, WEBAPP_SPRING_CONFIG_TEST_FILE })
|
||||
@Transactional
|
||||
public class TypeOfWorkHoursServiceTest {
|
||||
|
||||
@Autowired
|
||||
private ITypeOfWorkHoursService typeOfWorkHoursService;
|
||||
|
||||
@Autowired
|
||||
private ITypeOfWorkHoursDAO typeOfWorkHoursDAO;
|
||||
|
||||
@Autowired
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
@Test
|
||||
public void testAddAndGetTypeOfWorkHours() {
|
||||
|
||||
// Missing TypeOfWorkHours name.
|
||||
TypeOfWorkHoursDTO cc1 = new TypeOfWorkHoursDTO(null, true,
|
||||
new BigDecimal(5));
|
||||
// Valid TypeOfWorkHours DTO without hour cost
|
||||
TypeOfWorkHoursDTO cc2 = new TypeOfWorkHoursDTO("codeB", "cc2", true,
|
||||
new BigDecimal(5));
|
||||
|
||||
/* TypeOfWorkHours list. */
|
||||
TypeOfWorkHoursListDTO typeOfWorkHoursListDTO = createTypeOfWorkHoursListDTO(
|
||||
cc1, cc2);
|
||||
|
||||
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = typeOfWorkHoursService
|
||||
.addTypeOfWorkHours(typeOfWorkHoursListDTO).instanceConstraintViolationsList;
|
||||
|
||||
assertTrue(instanceConstraintViolationsList.toString(),
|
||||
instanceConstraintViolationsList.size() == 1);
|
||||
assertTrue(instanceConstraintViolationsList.get(0).constraintViolations
|
||||
.toString(),
|
||||
instanceConstraintViolationsList.get(0).constraintViolations
|
||||
.size() == 1); // cc1 constraint violations.
|
||||
|
||||
/* Test. */
|
||||
assertFalse(typeOfWorkHoursDAO.existsByCode(cc1.code));
|
||||
assertTrue(typeOfWorkHoursDAO.existsByCode(cc2.code));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateTypeOfWorkHours() throws InstanceNotFoundException {
|
||||
|
||||
// First one it creates valid type of work hours
|
||||
|
||||
TypeOfWorkHoursDTO cc1 = new TypeOfWorkHoursDTO("newTypeOfWorkHours",
|
||||
true, new BigDecimal(5));
|
||||
TypeOfWorkHoursListDTO typeOfWorkHoursListDTO = createTypeOfWorkHoursListDTO(cc1);
|
||||
|
||||
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = typeOfWorkHoursService
|
||||
.addTypeOfWorkHours(typeOfWorkHoursListDTO).instanceConstraintViolationsList;
|
||||
typeOfWorkHoursDAO.flush();
|
||||
|
||||
/* Test. */
|
||||
assertTrue(instanceConstraintViolationsList.toString(),
|
||||
instanceConstraintViolationsList.size() == 0);
|
||||
assertTrue(typeOfWorkHoursDAO.existsByCode(cc1.code));
|
||||
|
||||
TypeOfWorkHours typeOfWorkHours = null;
|
||||
try {
|
||||
typeOfWorkHours = typeOfWorkHoursDAO.findByCode(cc1.code);
|
||||
assertTrue(typeOfWorkHours.getName().equalsIgnoreCase(
|
||||
"newTypeOfWorkHours"));
|
||||
assertTrue(typeOfWorkHours.getEnabled());
|
||||
assertTrue(typeOfWorkHours.getDefaultPrice().compareTo(
|
||||
new BigDecimal(5)) == 0);
|
||||
} catch (InstanceNotFoundException e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
typeOfWorkHoursDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(typeOfWorkHours);
|
||||
typeOfWorkHours.dontPoseAsTransientObjectAnymore();
|
||||
|
||||
// Update the previous type of work hours
|
||||
TypeOfWorkHoursDTO cc2 = new TypeOfWorkHoursDTO(cc1.code, "updateCC1",
|
||||
false, new BigDecimal(100));
|
||||
|
||||
typeOfWorkHoursListDTO = createTypeOfWorkHoursListDTO(cc2);
|
||||
|
||||
instanceConstraintViolationsList = typeOfWorkHoursService
|
||||
.addTypeOfWorkHours(typeOfWorkHoursListDTO).instanceConstraintViolationsList;
|
||||
|
||||
/* Test. */
|
||||
assertTrue(instanceConstraintViolationsList.toString(),
|
||||
instanceConstraintViolationsList.size() == 0);
|
||||
assertTrue(typeOfWorkHoursDAO.existsByCode(cc1.code));
|
||||
|
||||
// Check if the changes was updated
|
||||
try {
|
||||
typeOfWorkHours = typeOfWorkHoursDAO.findByCode(cc1.code);
|
||||
assertTrue(typeOfWorkHours.getName().equalsIgnoreCase("updateCC1"));
|
||||
assertFalse(typeOfWorkHours.getEnabled());
|
||||
assertTrue(typeOfWorkHours.getDefaultPrice().compareTo(
|
||||
new BigDecimal(100)) == 0);
|
||||
} catch (InstanceNotFoundException e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
private TypeOfWorkHoursListDTO createTypeOfWorkHoursListDTO(
|
||||
TypeOfWorkHoursDTO... typeOfWorkHours) {
|
||||
|
||||
List<TypeOfWorkHoursDTO> typeOfWorkHoursList = new ArrayList<TypeOfWorkHoursDTO>();
|
||||
|
||||
for (TypeOfWorkHoursDTO c : typeOfWorkHours) {
|
||||
typeOfWorkHoursList.add(c);
|
||||
}
|
||||
|
||||
return new TypeOfWorkHoursListDTO(typeOfWorkHoursList);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -42,6 +42,15 @@
|
|||
|
||||
- export-label-types.sh (authenticate with wsreader/wsreader)
|
||||
|
||||
* Import type of work hours:
|
||||
|
||||
- import-type-work-hours.sh type-work-hours-sample.xml
|
||||
(authenticate with wswriter/wswriter)
|
||||
|
||||
* Export type of work hours:
|
||||
|
||||
- export-type-work-hours.sh (authenticate with wsreader/wsreader)
|
||||
|
||||
* Import resources:
|
||||
|
||||
- import-resources.sh resources-sample-mini.xml (or resources-sample.xml)
|
||||
|
|
|
|||
21
scripts/rest-clients/export-type-work-hours.sh
Executable file
21
scripts/rest-clients/export-type-work-hours.sh
Executable file
|
|
@ -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/typeofworkhours | tidy -xml -i -q -utf8
|
||||
33
scripts/rest-clients/import-type-work-hours.sh
Executable file
33
scripts/rest-clients/import-type-work-hours.sh
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./rest-common-env.sh
|
||||
|
||||
printf "Login name: "
|
||||
read loginName
|
||||
printf "Password: "
|
||||
read password
|
||||
|
||||
baseServiceURL=$DEVELOPMENT_BASE_SERVICE_URL
|
||||
certificate=$DEVELOPMENT_CERTIFICATE
|
||||
|
||||
for i in "$@"
|
||||
do
|
||||
if [ "$i" = "--prod" ]; then
|
||||
baseServiceURL=$PRODUCTION_BASE_SERVICE_URL
|
||||
certificate=$PRODUCTION_CERTIFICATE
|
||||
else
|
||||
file=$i
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$file" = "" ]; then
|
||||
printf "Missing file\n" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
authorization=`./base64.sh $loginName:$password`
|
||||
|
||||
curl -sv -X POST $certificate -d @$file \
|
||||
--header "Content-type: application/xml" \
|
||||
--header "Authorization: Basic $authorization" \
|
||||
$baseServiceURL/typeofworkhours | tidy -xml -i -q -utf8
|
||||
9
scripts/rest-clients/type-work-hours-sample.xml
Normal file
9
scripts/rest-clients/type-work-hours-sample.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<type-work-hours-list xmlns="http://rest.ws.navalplanner.org">
|
||||
<type-work-hours enabled="true" defaultPrice="8.00" name="Hora Extra"
|
||||
code="code-E" />
|
||||
<type-work-hours enabled="false" defaultPrice="5.00" name="Normal"
|
||||
code="code-N" />
|
||||
<type-work-hours enabled="true" defaultPrice="9.50"
|
||||
name="Plus Nocturnidad" code="code-P" />
|
||||
</type-work-hours-list>
|
||||
Loading…
Add table
Reference in a new issue