Datasets:
ArXiv:
License:
| /* | |
| * To change this license header, choose License Headers in Project Properties. | |
| * To change this template file, choose Tools | Templates | |
| * and open the template in the editor. | |
| */ | |
| package ws; | |
| import beans.InfoVehiculo; | |
| import beans.Respuesta; | |
| import beans.Vehiculo; | |
| import beans.VehiculoAnonimo; | |
| import java.sql.Date; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import javax.ws.rs.core.Context; | |
| import javax.ws.rs.core.UriInfo; | |
| import javax.ws.rs.Consumes; | |
| import javax.ws.rs.DELETE; | |
| import javax.ws.rs.FormParam; | |
| import javax.ws.rs.Produces; | |
| import javax.ws.rs.GET; | |
| import javax.ws.rs.POST; | |
| import javax.ws.rs.Path; | |
| import javax.ws.rs.PUT; | |
| import javax.ws.rs.core.MediaType; | |
| import model.dao.VehiculoDAO; | |
| /** | |
| * REST Web Service | |
| * | |
| * @author Juan Carlos | |
| */ | |
| public class VehiculoWS { | |
| private UriInfo context; | |
| /** | |
| * Creates a new instance of VehiculoWS | |
| */ | |
| public VehiculoWS() { | |
| } | |
| public Respuesta registrarVehiculo( | |
| String numPlacas, | |
| String idMarca, | |
| String modelo, | |
| String color, | |
| String year, | |
| String numPoliza, | |
| String idAseguradora, | |
| String fechaVencimientoString, | |
| String idConductor | |
| ) { | |
| Respuesta res = new Respuesta(); | |
| Vehiculo vehiculo = new Vehiculo(); | |
| vehiculo.setColor(color); | |
| vehiculo.setIdMarca(Integer.parseInt(idMarca)); | |
| vehiculo.setModelo(modelo); | |
| vehiculo.setNumPlacas(numPlacas); | |
| vehiculo.setYear(year); | |
| Date fechaVencimiento = Date.valueOf(fechaVencimientoString); | |
| if (idAseguradora != null && !idAseguradora.toString().trim().isEmpty()) { | |
| if (numPoliza != null && !numPoliza.toString().trim().isEmpty()) { | |
| vehiculo.setNumPoliza(numPoliza); | |
| vehiculo.setIdAseguradora(Integer.parseInt(idAseguradora)); | |
| } else { | |
| res.setError(true); | |
| res.setErrorcode(7); | |
| res.setMensaje("Porfavor ingrese su numero de póliza"); | |
| return res; | |
| } | |
| } | |
| int fa = VehiculoDAO.registrarVehiculo(vehiculo, fechaVencimiento, Integer.parseInt(idConductor)); | |
| System.out.println(fa); | |
| if (fa >= 0) { | |
| res.setError(false); | |
| res.setErrorcode(0); | |
| res.setMensaje("Vehículo registrado exitosamente"); | |
| } else { | |
| switch (fa) { | |
| case -1: | |
| res.setError(true); | |
| res.setErrorcode(1); | |
| res.setMensaje("Error al registrar Vehículo, datos no válidos"); | |
| break; | |
| case -2: | |
| res.setError(true); | |
| res.setErrorcode(2); | |
| res.setMensaje("Error al registrar Vehículo," | |
| + " ya hay un vehiculo registrado con las mismas placas"); | |
| break; | |
| default: | |
| res.setError(true); | |
| res.setErrorcode(3); | |
| res.setMensaje("Error de conexión"); | |
| break; | |
| } | |
| } | |
| return res ; | |
| } | |
| public Respuesta registrarVehiculoAnonimo( | |
| String numPlacas, | |
| String marca, | |
| String modelo, | |
| String color, | |
| String year, | |
| String numPoliza, | |
| String idAseguradora | |
| ) { | |
| Respuesta res = new Respuesta(); | |
| VehiculoAnonimo vehiculo = new VehiculoAnonimo(); | |
| vehiculo.setColor(color); | |
| vehiculo.setIdMarca(Integer.parseInt(marca)); | |
| vehiculo.setModelo(modelo); | |
| vehiculo.setNumPlacas(numPlacas); | |
| vehiculo.setYear(year); | |
| vehiculo.setNumPoliza(numPoliza); | |
| vehiculo.setIdAseguradora(Integer.parseInt(idAseguradora)); | |
| int fa = VehiculoDAO.registrarVehiculoAnonimo(vehiculo); | |
| if (fa > 0) { | |
| res.setError(false); | |
| res.setErrorcode(0); | |
| res.setMensaje("Vehículo registrado exitosamente"); | |
| } else { | |
| switch (fa) { | |
| case -1: | |
| res.setError(true); | |
| res.setErrorcode(1); | |
| res.setMensaje("Error al registrar Vehículo, datos no válidos"); | |
| break; | |
| case -2: | |
| res.setError(true); | |
| res.setErrorcode(2); | |
| res.setMensaje("Error al registrar Vehículo," | |
| + " ya hay un vehiculo registrado con las mismas placas"); | |
| break; | |
| default: | |
| res.setError(true); | |
| res.setErrorcode(3); | |
| res.setMensaje("Error de conexión"); | |
| break; | |
| } | |
| } | |
| return res; | |
| } | |
| public List<InfoVehiculo> getVehiculos( | |
| String idConductorString | |
| ){ | |
| List<Vehiculo> list = new ArrayList<>(); | |
| int idConductor = Integer.parseInt(idConductorString); | |
| return VehiculoDAO.getVehiculos(idConductor); | |
| } | |
| public Respuesta editarVehiculo( | |
| String idVehiculoString, | |
| String numPlacas, | |
| String idMarca, | |
| String modelo, | |
| String color, | |
| String year, | |
| String numPoliza | |
| ){ | |
| Respuesta res = new Respuesta(); | |
| int idVehiculo = Integer.parseInt(idVehiculoString); | |
| Vehiculo vehiculo = new Vehiculo(idVehiculo, numPlacas, modelo, Integer.parseInt(idMarca), year, color, numPoliza); | |
| int fa = VehiculoDAO.editarVehiculo(vehiculo); | |
| if (fa > 0) { | |
| res.setError(false); | |
| res.setErrorcode(0); | |
| res.setMensaje("Vehículo actualizado exitosamente"); | |
| } else { | |
| switch (fa) { | |
| case -1: | |
| res.setError(true); | |
| res.setErrorcode(1); | |
| res.setMensaje("Error al actualizar Vehículo, datos no válidos"); | |
| break; | |
| case -2: | |
| res.setError(true); | |
| res.setErrorcode(2); | |
| res.setMensaje("Error al registrar Vehículo," | |
| + " ya hay un vehiculo registrado con las mismas placas"); | |
| break; | |
| default: | |
| res.setError(true); | |
| res.setErrorcode(3); | |
| res.setMensaje("Error de conexión"); | |
| break; | |
| } | |
| } | |
| return res; | |
| } | |
| public List<Vehiculo> getVehiculosReporte( | |
| String idReporteString | |
| ){ | |
| List<Vehiculo> list = new ArrayList<>(); | |
| int idReporte = Integer.parseInt(idReporteString); | |
| return VehiculoDAO.getVehiculosReporte(idReporte); | |
| } | |
| public Respuesta eliminarVehiculo( | |
| String numPlacas | |
| ) { | |
| Respuesta res = new Respuesta(); | |
| return VehiculoDAO.eliminarVehiculo(numPlacas); | |
| } | |
| } | |