ItEr29S09CUAltaSubcontrataItEr28S10: First version of the REST-based service layer.

First version of the REST-based service layer, providing support for exporting and importing a list of CriterionType.
This commit is contained in:
Fernando Bellas Permuy 2009-10-08 13:48:52 +02:00 committed by Javier Moran Rua
parent 096cc9369c
commit c4bd06fbd0
18 changed files with 950 additions and 4 deletions

View file

@ -116,5 +116,19 @@
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId> <artifactId>servlet-api</artifactId>
</dependency> </dependency>
<!-- JAX-RS API -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</dependency>
<!-- CXF -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -0,0 +1,55 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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.common.api;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
/**
* It represents an individual error in the service response.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
@XmlRootElement(name="error")
public class WSError {
@XmlAttribute
public String instanceId;
@XmlAttribute
public WSErrorType errorType;
public String explanation;
public WSError() {}
public WSError(WSErrorType errorType, String explanation) {
this.errorType = errorType;
this.explanation = explanation;
}
public WSError(String instanceId, WSErrorType errorType, String explanation) {
this.instanceId = instanceId;
this.errorType = errorType;
this.explanation = explanation;
}
}

View file

@ -0,0 +1,46 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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.common.api;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* It represents list of errors in the service response.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
@XmlRootElement(name="errors")
public class WSErrorList {
@XmlElement(name="error")
public List<WSError> errors = new ArrayList<WSError>();
public WSErrorList() {}
public WSErrorList(List<WSError> errors) {
this.errors = errors;
}
}

View file

@ -0,0 +1,34 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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.common.api;
import javax.xml.bind.annotation.XmlEnum;
/**
* Enumeration type for the types of errors in <code>WSError</code>.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
@XmlEnum
public enum WSErrorType {
SERVICE_INTERNAL_ERROR,
VALIDATION_ERROR
}

View file

@ -0,0 +1,35 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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.common.api;
/**
* Global names.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
public class WSGlobalNames {
public final static String REST_NAMESPACE =
"http://rest.ws.navalplanner.org";
private WSGlobalNames() {}
}

View file

@ -0,0 +1,30 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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 Fernando Bellas Permuy <fbellas@udc.es>
*/
@javax.xml.bind.annotation.XmlSchema(
elementFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
namespace=WSGlobalNames.REST_NAMESPACE
)
package org.navalplanner.ws.common.api;

View file

@ -0,0 +1,62 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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.common.impl;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.navalplanner.ws.common.api.WSError;
import org.navalplanner.ws.common.api.WSErrorType;
import org.springframework.stereotype.Component;
/**
* Exception mapper for <code>RuntimeException</code>.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
@Provider
@Component("runtimeExceptionMapper")
public class RuntimeExceptionMapper
implements ExceptionMapper<RuntimeException> {
public Response toResponse(RuntimeException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
entity(new WSError(WSErrorType.SERVICE_INTERNAL_ERROR,
getStackTrace(e))).
type("application/xml").
build();
}
private String getStackTrace(RuntimeException e) {
StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.toString();
}
}

View file

@ -0,0 +1,60 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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.resources.criterion.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 javax.xml.bind.annotation.XmlRootElement;
/**
* DTO for <code>Criterion</code> entity.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
@XmlRootElement(name="criterion")
public class CriterionDTO {
@XmlAttribute
public String name;
@XmlAttribute
public boolean active = true;
@XmlElementWrapper(name="children")
@XmlElement(name="criterion")
public List<CriterionDTO> children = new ArrayList<CriterionDTO>();
public CriterionDTO() {}
public CriterionDTO(String name, boolean active,
List<CriterionDTO> children) {
this.name = name;
this.active = active;
this.children = children;
}
}

View file

@ -0,0 +1,79 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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.resources.criterion.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 javax.xml.bind.annotation.XmlRootElement;
/**
* DTO for <code>CriterionType</code> entity.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
@XmlRootElement(name="criterion-type")
public class CriterionTypeDTO {
@XmlAttribute
public String name;
@XmlAttribute
public String description;
@XmlAttribute
public boolean allowHierarchy = true;
@XmlAttribute
public boolean allowSimultaneousCriterionsPerResource = true;
@XmlAttribute
public boolean enabled = true;
@XmlAttribute
public ResourceEnumDTO resource = ResourceEnumDTO.RESOURCE;
@XmlElementWrapper(name="criterion-list")
@XmlElement(name="criterion")
public List<CriterionDTO> criterions = new ArrayList<CriterionDTO>();
public CriterionTypeDTO() {}
public CriterionTypeDTO(String name, String description,
boolean allowHierarchy, boolean allowSimultaneousCriterionsPerResource,
boolean enabled, ResourceEnumDTO resource,
List<CriterionDTO> criterions) {
this.name = name;
this.description = description;
this.allowHierarchy = allowHierarchy;
this.allowSimultaneousCriterionsPerResource =
allowSimultaneousCriterionsPerResource;
this.enabled = enabled;
this.resource = resource;
this.criterions = criterions;
}
}

View file

@ -0,0 +1,47 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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.resources.criterion.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>CriterionType</code> entities.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
@XmlRootElement(name="criterion-type-list")
public class CriterionTypeListDTO {
@XmlElement(name="criterion-type")
public List<CriterionTypeDTO> criterionTypes =
new ArrayList<CriterionTypeDTO>();
public CriterionTypeListDTO() {}
public CriterionTypeListDTO(List<CriterionTypeDTO> criterionTypes) {
this.criterionTypes = criterionTypes;
}
}

View file

@ -0,0 +1,36 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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.resources.criterion.api;
import org.navalplanner.ws.common.api.WSErrorList;
/**
* Service for managing criterion-related entities.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
public interface ICriterionService {
public CriterionTypeListDTO getCriterionTypes();
public WSErrorList addCriterionTypes(CriterionTypeListDTO criterionTypes);
}

View file

@ -0,0 +1,34 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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.resources.criterion.api;
import javax.xml.bind.annotation.XmlEnum;
/**
* DTO for <code>ResourceEnum</code> entity.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
@XmlEnum
public enum ResourceEnumDTO {
RESOURCE,
WORKER
}

View file

@ -0,0 +1,31 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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 Fernando Bellas Permuy <fbellas@udc.es>
*/
@javax.xml.bind.annotation.XmlSchema(
elementFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
namespace=WSGlobalNames.REST_NAMESPACE
)
package org.navalplanner.ws.resources.criterion.api;
import org.navalplanner.ws.common.api.WSGlobalNames;

View file

@ -0,0 +1,199 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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.resources.criterion.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.CriterionType;
import org.navalplanner.business.resources.entities.ResourceEnum;
import org.navalplanner.ws.resources.criterion.api.CriterionDTO;
import org.navalplanner.ws.resources.criterion.api.CriterionTypeDTO;
import org.navalplanner.ws.resources.criterion.api.CriterionTypeListDTO;
import org.navalplanner.ws.resources.criterion.api.ResourceEnumDTO;
/**
* Converter from/to criterion-related entities to/from DTOs.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
public final class CriterionConverter {
private final static Map<ResourceEnum, ResourceEnumDTO>
resourceEnumToDTO =
new HashMap<ResourceEnum, ResourceEnumDTO>();
private final static Map<ResourceEnumDTO, ResourceEnum>
resourceEnumFromDTO =
new HashMap<ResourceEnumDTO, ResourceEnum>();
static {
resourceEnumToDTO.put(ResourceEnum.RESOURCE,
ResourceEnumDTO.RESOURCE);
resourceEnumFromDTO.put(ResourceEnumDTO.RESOURCE,
ResourceEnum.RESOURCE);
resourceEnumToDTO.put(ResourceEnum.WORKER,
ResourceEnumDTO.WORKER);
resourceEnumFromDTO.put(ResourceEnumDTO.WORKER,
ResourceEnum.WORKER);
}
private CriterionConverter() {}
public final static CriterionTypeListDTO toDTO(
Collection<CriterionType> criterionTypes) {
List<CriterionTypeDTO> criterionTypeDTOs =
new ArrayList<CriterionTypeDTO>();
for (CriterionType c : criterionTypes) {
criterionTypeDTOs.add(toDTO(c));
}
return new CriterionTypeListDTO(criterionTypeDTOs);
}
public final static CriterionTypeDTO toDTO(CriterionType criterionType) {
List<CriterionDTO> criterionDTOs = new ArrayList<CriterionDTO>();
for (Criterion c : criterionType.getCriterions()) {
if (c.getParent() == null) {
criterionDTOs.add(toDTO(c));
}
}
if (criterionDTOs.isEmpty()) {
criterionDTOs = null;
}
return new CriterionTypeDTO(
criterionType.getName(),
criterionType.getDescription(),
criterionType.allowHierarchy(),
criterionType.isAllowSimultaneousCriterionsPerResource(),
criterionType.isEnabled(),
toDTO(criterionType.resource()),
criterionDTOs);
}
public final static CriterionDTO toDTO(Criterion criterion) {
List<CriterionDTO> childrenDTOs = new ArrayList<CriterionDTO>();
for (Criterion c : criterion.getChildren()) {
childrenDTOs.add(toDTO(c));
}
if (childrenDTOs.isEmpty()) {
childrenDTOs = null;
}
return new CriterionDTO(criterion.getName(), criterion.isActive(),
childrenDTOs);
}
public final static ResourceEnumDTO toDTO(ResourceEnum resource) {
ResourceEnumDTO value = resourceEnumToDTO.get(resource);
if (value == null) {
throw new RuntimeException("Unable to convert '" +
resource.toString() + "' value to ResourceEnumDTO");
} else {
return value;
}
}
public final static CriterionType toEntity(
CriterionTypeDTO criterionTypeDTO) {
CriterionType criterionType = CriterionType.create(
criterionTypeDTO.name,
criterionTypeDTO.description,
criterionTypeDTO.allowHierarchy,
criterionTypeDTO.allowSimultaneousCriterionsPerResource,
criterionTypeDTO.enabled,
CriterionConverter.fromDTO(criterionTypeDTO.resource));
for (CriterionDTO criterionDTO : criterionTypeDTO.criterions) {
addCriterion(criterionType, criterionDTO, null);
}
return criterionType;
}
private static ResourceEnum fromDTO(ResourceEnumDTO resource) {
ResourceEnum value = resourceEnumFromDTO.get(resource);
if (value == null) {
throw new RuntimeException("Unable to convert '" +
resource.toString() + "' value to ResourceEnum");
} else {
return value;
}
}
private static Criterion addCriterion(CriterionType criterionType,
CriterionDTO criterionDTO, Criterion criterionParent) {
Criterion criterion = toEntityWithoutChildren(criterionDTO,
criterionType, criterionParent);
criterionType.getCriterions().add(criterion);
for (CriterionDTO childDTO : criterionDTO.children) {
Criterion child = addCriterion(criterionType, childDTO, criterion);
criterion.getChildren().add(child);
}
return criterion;
}
private static Criterion toEntityWithoutChildren(
CriterionDTO childDTO, CriterionType criterionType,
Criterion criterionParent) {
Criterion criterion = Criterion.create(childDTO.name, criterionType);
criterion.setActive(childDTO.active);
criterion.setParent(criterionParent);
return criterion;
}
}

View file

@ -0,0 +1,95 @@
/*
* This file is part of ###PROJECT_NAME###
*
* 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.resources.criterion.impl;
import java.util.ArrayList;
import java.util.List;
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.resources.daos.CriterionTypeDAO;
import org.navalplanner.ws.common.api.WSError;
import org.navalplanner.ws.common.api.WSErrorList;
import org.navalplanner.ws.common.api.WSErrorType;
import org.navalplanner.ws.resources.criterion.api.CriterionTypeDTO;
import org.navalplanner.ws.resources.criterion.api.CriterionTypeListDTO;
import org.navalplanner.ws.resources.criterion.api.ICriterionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* REST-based implementation of <code>ICriterionService</code>.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
@Path("/criteriontypes/")
@Produces("application/xml")
@Service("criterionServiceREST")
public class CriterionServiceREST implements ICriterionService {
@Autowired
private CriterionTypeDAO criterionTypeDAO;
@Override
@GET
@Transactional(readOnly = true)
public CriterionTypeListDTO getCriterionTypes() {
return CriterionConverter.toDTO(criterionTypeDAO.getCriterionTypes());
}
@Override
@POST
@Consumes("application/xml")
@Transactional
public WSErrorList addCriterionTypes(CriterionTypeListDTO criterionTypes) {
List<WSError> errorList = new ArrayList<WSError>();
for (CriterionTypeDTO criterionTypeDTO :
criterionTypes.criterionTypes) {
try {
criterionTypeDAO.save(
CriterionConverter.toEntity(criterionTypeDTO));
} catch (Exception e) {
e.printStackTrace(System.out);
errorList.add(new WSError(criterionTypeDTO.name,
WSErrorType.VALIDATION_ERROR, e.getMessage()));
}
}
if (errorList.isEmpty()) {
return null;
} else {
return new WSErrorList(errorList);
}
}
}

View file

@ -1,12 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation=" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<!-- <!--
For enabling annotation-based configuration (in particular, For enabling annotation-based configuration (in particular,
@ -27,5 +35,23 @@
<lookup-method name="getResourceLoadForOrderCommand" bean="resourceLoadForOrderCommand"/> <lookup-method name="getResourceLoadForOrderCommand" bean="resourceLoadForOrderCommand"/>
</bean> </bean>
<context:component-scan base-package="org.navalplanner.web"/> <context:component-scan base-package="org.navalplanner"/>
<!-- CXF -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxrs:server id="rest" address="/">
<jaxrs:serviceBeans>
<ref bean="criterionServiceREST"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="runtimeExceptionMapper" />
</jaxrs:providers>
<jaxrs:features>
<cxf:logging/>
</jaxrs:features>
</jaxrs:server>
</beans> </beans>

View file

@ -89,6 +89,20 @@
</servlet-mapping> </servlet-mapping>
<!-- //// --> <!-- //// -->
<!-- CXF -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/ws/rest/*</url-pattern>
</servlet-mapping>
<welcome-file-list> <welcome-file-list>
<welcome-file>/planner/main.zul</welcome-file> <welcome-file>/planner/main.zul</welcome-file>
</welcome-file-list> </welcome-file-list>

49
pom.xml
View file

@ -387,6 +387,55 @@
<type>jar</type> <type>jar</type>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- JAX-RS API -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.0</version>
</dependency>
<!-- CXF -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.2.3</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>2.2.3</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>