Datasets:

ArXiv:
License:
File size: 3,394 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * 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.Reporte;
import beans.ReporteDictamen;
import beans.ReporteResumido;
import beans.Respuesta;
import beans.RespuestaReporte;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import model.dao.ReporteDAO;

/**
 * REST Web Service
 *
 * @author Juan Carlos
 */
@Path("reportes")
public class ReporteWS {

    @Context
    private UriInfo context;

    /**
     * Creates a new instance of ReporteWS
     */
    public ReporteWS() {
    }

    @POST
    @Path("nuevoReporte")
    @Produces(MediaType.APPLICATION_JSON)
    public RespuestaReporte agregarReporte(
            @FormParam ("descripcion") String descripcion,
            @FormParam ("idConductor") String idConductorString,
            @FormParam ("latitud") String latitud,
            @FormParam ("longitud") String longitud,
            @FormParam ("placasVehiculos") String placasVehiculos
    ){
        RespuestaReporte res = new RespuestaReporte();
        int idConductor = Integer.parseInt(idConductorString);
        Reporte reporte = new Reporte();
        reporte.setDescripcion(descripcion);
        reporte.setIdConductor(idConductor);
        reporte.setLatitud(Float.parseFloat(latitud));
        reporte.setLongitud(Float.parseFloat(longitud));
        reporte.setPlacasVehiculos(placasVehiculos);
        reporte.setEstado(1);
        reporte.setIdReporte(0);
        int fa = ReporteDAO.agregarReporte(reporte);
        if (fa > 0) {
            res.setError(false);
            res.setErrorcode(0);
            res.setMensaje("Reporte enviado exitosamente");
            res.setIdReporte(reporte.getIdReporte().toString());
        } else {
            switch (fa) {
                case -1:
                    res.setError(true);
                    res.setErrorcode(1);
                    res.setMensaje("Error al levantar reporte, datos no válidos");
                    break;
                case -2:
                    res.setError(true);
                    res.setErrorcode(3);
                    res.setMensaje("Error de conexión");
                    break;
            }
        }
        return res;
    }
    
    @POST
    @Path("getReportes")
    @Produces(MediaType.APPLICATION_JSON)
    public List<ReporteResumido> getReportes(
            @FormParam("idConductor") String idConductorString
    ){
        List<ReporteResumido> list = new ArrayList<>();
        int idConductor = Integer.parseInt(idConductorString);
        list = ReporteDAO.getReportes(idConductor);
        return list;
    }
    
    @POST
    @Path("obtenerDetalleReporte")
    @Produces(MediaType.APPLICATION_JSON)
    public ReporteDictamen getDetallesReporte(
            @FormParam("idReporte") String idReporte
    ){
        ReporteDictamen reporte = new ReporteDictamen();
        reporte = ReporteDAO.getDetallesReporte(Integer.parseInt(idReporte));
        return reporte;
    }
}