package org.traccar.api.resource; import java.sql.SQLException; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; import org.traccar.api.BaseResource; import org.traccar.reports.Events; import org.traccar.reports.General; import org.traccar.reports.Route; import org.traccar.web.JsonConverter; @Path("reports") public class ReportResource extends BaseResource { @Path("route") @GET public Response getRoute( @QueryParam("deviceId") final List deviceIds, @QueryParam("groupId") final List groupIds, @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { if (getAcceptHeader().equals("application/ms-excel")) { ResponseBuilder response = Response.ok(Route.getCsv(getUserId(), deviceIds, groupIds, JsonConverter.parseDate(from), JsonConverter.parseDate(to))); response.type("application/ms-excel"); return response.build(); } ResponseBuilder response = Response.ok(Route.getJson(getUserId(), deviceIds, groupIds, JsonConverter.parseDate(from), JsonConverter.parseDate(to))); response.type(MediaType.APPLICATION_JSON); return response.build(); } @Path("events") @GET public Response getEvents( @QueryParam("deviceId") final List deviceIds, @QueryParam("groupId") final List groupIds, @QueryParam("type") final List types, @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { if (getAcceptHeader().equals("application/ms-excel")) { ResponseBuilder response = Response.ok(Events.getCsv(getUserId(), deviceIds, groupIds, types, JsonConverter.parseDate(from), JsonConverter.parseDate(to))); response.type("application/ms-excel"); return response.build(); } ResponseBuilder response = Response.ok(Events.getJson(getUserId(), deviceIds, groupIds, types, JsonConverter.parseDate(from), JsonConverter.parseDate(to))); response.type(MediaType.APPLICATION_JSON); return response.build(); } @Path("general") @GET public Response getGeneral( @QueryParam("deviceId") final List deviceIds, @QueryParam("groupId") final List groupIds, @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { if (getAcceptHeader().equals("application/ms-excel")) { ResponseBuilder response = Response.ok(General.getCsv(getUserId(), deviceIds, groupIds, JsonConverter.parseDate(from), JsonConverter.parseDate(to))); response.type("application/ms-excel"); return response.build(); } ResponseBuilder response = Response.ok(General.getJson(getUserId(), deviceIds, groupIds, JsonConverter.parseDate(from), JsonConverter.parseDate(to))); response.type(MediaType.APPLICATION_JSON); return response.build(); } }