diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-08-08 10:39:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-08 10:39:07 +0300 |
commit | 1f0e1dddadd32a1f40695bf33d877d192ecd1403 (patch) | |
tree | 0718bbcd23b1c1dc8fce80fbfa41095c28b5d633 /src/org/traccar/api/resource | |
parent | ecf3ebdd176fafc0e9bfbdb1bca8f3a1cfd6cbb0 (diff) | |
parent | e316afef8768c9c08d41cb9ae0a845a93a5fe95a (diff) | |
download | trackermap-server-1f0e1dddadd32a1f40695bf33d877d192ecd1403.tar.gz trackermap-server-1f0e1dddadd32a1f40695bf33d877d192ecd1403.tar.bz2 trackermap-server-1f0e1dddadd32a1f40695bf33d877d192ecd1403.zip |
Merge pull request #2190 from Abyss777/reports
Implement reports API calls
Diffstat (limited to 'src/org/traccar/api/resource')
-rw-r--r-- | src/org/traccar/api/resource/ReportResource.java | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/org/traccar/api/resource/ReportResource.java b/src/org/traccar/api/resource/ReportResource.java new file mode 100644 index 000000000..8682070b1 --- /dev/null +++ b/src/org/traccar/api/resource/ReportResource.java @@ -0,0 +1,85 @@ +package org.traccar.api.resource; + +import java.sql.SQLException; +import java.util.List; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +import org.traccar.api.BaseResource; +import org.traccar.reports.Events; +import org.traccar.reports.Summary; +import org.traccar.reports.Route; +import org.traccar.web.JsonConverter; + +@Path("reports") +@Consumes("application/json") +public class ReportResource extends BaseResource { + + @Path("route") + @GET + @Produces("application/json") + public Response getRouteJson( + @QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds, + @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { + return Response.ok(Route.getJson(getUserId(), deviceIds, groupIds, + JsonConverter.parseDate(from), JsonConverter.parseDate(to))).build(); + } + + @Path("route") + @GET + @Produces("application/ms-excel") + public Response getRouteCsv( + @QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds, + @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { + return Response.ok(Route.getCsv(getUserId(), deviceIds, groupIds, + JsonConverter.parseDate(from), JsonConverter.parseDate(to))).build(); + } + + @Path("events") + @GET + @Produces("application/json") + public Response getEventsJson( + @QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds, + @QueryParam("type") final List<String> types, + @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { + return Response.ok(Events.getJson(getUserId(), deviceIds, groupIds, types, + JsonConverter.parseDate(from), JsonConverter.parseDate(to))).build(); + } + + @Path("events") + @GET + @Produces("application/ms-excel") + public Response getEventsCsv( + @QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds, + @QueryParam("type") final List<String> types, + @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { + return Response.ok(Events.getCsv(getUserId(), deviceIds, groupIds, + types, JsonConverter.parseDate(from), JsonConverter.parseDate(to))).build(); + } + + @Path("summary") + @GET + @Produces("application/json") + public Response getSummaryJson( + @QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds, + @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { + return Response.ok(Summary.getJson(getUserId(), deviceIds, groupIds, + JsonConverter.parseDate(from), JsonConverter.parseDate(to))).build(); + } + + @Path("summary") + @GET + @Produces("application/ms-excel") + public Response getSummaryCsv( + @QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds, + @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { + return Response.ok(Summary.getCsv(getUserId(), deviceIds, groupIds, + JsonConverter.parseDate(from), JsonConverter.parseDate(to))).build(); + } + +} |