ItEr40S16CUImportacionOrganizacionsTraballoItEr39S17: Created method to update an order on web service via PUT request.
This commit is contained in:
parent
e1ce429fed
commit
98f246ba9d
6 changed files with 114 additions and 0 deletions
|
|
@ -0,0 +1,39 @@
|
|||
package org.navalplanner.ws.common.api;
|
||||
|
||||
/**
|
||||
* {@link Exception} used in update process when two types are not compatible.
|
||||
*
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@SuppressWarnings(value = { "serial", "unchecked" })
|
||||
public class IncompatibleTypeException extends Exception {
|
||||
|
||||
private Object identifier;
|
||||
private Class expectedType;
|
||||
private Class actualType;
|
||||
|
||||
public IncompatibleTypeException(Object identifier, Class expectedType,
|
||||
Class actualType) {
|
||||
super("Incompatible type (identifier = '" + identifier
|
||||
+ "' - expectedType = '" + expectedType.getName()
|
||||
+ "' - actualType = '" + actualType.getName() + "')");
|
||||
|
||||
this.identifier = identifier;
|
||||
this.expectedType = expectedType;
|
||||
this.actualType = actualType;
|
||||
}
|
||||
|
||||
public Object getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public Class getExpectedType() {
|
||||
return expectedType;
|
||||
}
|
||||
|
||||
public Class getActualType() {
|
||||
return actualType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.common.impl;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
import org.navalplanner.ws.common.api.IncompatibleTypeException;
|
||||
import org.navalplanner.ws.common.api.InternalErrorDTO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Exception mapper for {@link IncompatibleTypeException}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@Provider
|
||||
@Component("incompatibleTypeExceptionMapper")
|
||||
public class IncompatibleTypeExceptionMapper implements
|
||||
ExceptionMapper<IncompatibleTypeException> {
|
||||
|
||||
public Response toResponse(IncompatibleTypeException e) {
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||
new InternalErrorDTO(e.getMessage(), Util.getStackTrace(e)))
|
||||
.type("application/xml").build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ package org.navalplanner.ws.orders.api;
|
|||
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.ws.common.api.IncompatibleTypeException;
|
||||
import org.navalplanner.ws.common.api.InstanceConstraintViolationsListDTO;
|
||||
|
||||
/**
|
||||
|
|
@ -36,4 +37,7 @@ public interface IOrderElementService {
|
|||
|
||||
InstanceConstraintViolationsListDTO addOrder(OrderDTO order);
|
||||
|
||||
InstanceConstraintViolationsListDTO updateOrder(OrderDTO orderDTO)
|
||||
throws InstanceNotFoundException, IncompatibleTypeException;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import java.util.List;
|
|||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
|
|
@ -33,7 +34,9 @@ import javax.ws.rs.Produces;
|
|||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.orders.daos.IOrderElementDAO;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.ws.common.api.IncompatibleTypeException;
|
||||
import org.navalplanner.ws.common.api.InstanceConstraintViolationsDTO;
|
||||
import org.navalplanner.ws.common.api.InstanceConstraintViolationsListDTO;
|
||||
import org.navalplanner.ws.common.impl.ConstraintViolationConverter;
|
||||
|
|
@ -97,4 +100,23 @@ public class OrderElementServiceREST implements IOrderElementService {
|
|||
instanceConstraintViolationsList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PUT
|
||||
@Consumes("application/xml")
|
||||
@Transactional
|
||||
public InstanceConstraintViolationsListDTO updateOrder(OrderDTO orderDTO)
|
||||
throws InstanceNotFoundException, IncompatibleTypeException {
|
||||
OrderElement orderElement = orderElementDAO
|
||||
.findUniqueByCode(orderDTO.code);
|
||||
if (!(orderElement instanceof Order)) {
|
||||
throw new IncompatibleTypeException(orderElement.getCode(),
|
||||
Order.class, orderElement.getClass());
|
||||
}
|
||||
|
||||
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = new ArrayList<InstanceConstraintViolationsDTO>();
|
||||
// TODO
|
||||
return new InstanceConstraintViolationsListDTO(
|
||||
instanceConstraintViolationsList);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@
|
|||
<jaxrs:providers>
|
||||
<ref bean="runtimeExceptionMapper" />
|
||||
<ref bean="instanceNotFoundExceptionMapper" />
|
||||
<ref bean="incompatibleTypeExceptionMapper" />
|
||||
</jaxrs:providers>
|
||||
<!-- FIXME: in root pom.xml, enable CXF logging on development and
|
||||
disable it in production.
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
<!-- Web services -->
|
||||
<intercept-url pattern="/ws/rest/**" access="ROLE_WS_READER" method="GET" />
|
||||
<intercept-url pattern="/ws/rest/**" access="ROLE_WS_WRITER" method="POST" />
|
||||
<intercept-url pattern="/ws/rest/**" access="ROLE_WS_WRITER" method="PUT" />
|
||||
|
||||
<!-- Web application -->
|
||||
<intercept-url pattern="/common/img/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue