aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource/ReportResource.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-08-03 17:53:54 +0500
committerAbyss777 <abyss@fox5.ru>2016-08-04 16:33:34 +0500
commit504a555b40ee0c2c14e8679ed320b8c2578f8610 (patch)
treed6b0fb2fb95253afcbe7dd7fcb1cbf367b45acc6 /src/org/traccar/api/resource/ReportResource.java
parenta5c431069ca0dfe8240f0c8b43f0508189f8fc86 (diff)
downloadtrackermap-server-504a555b40ee0c2c14e8679ed320b8c2578f8610.tar.gz
trackermap-server-504a555b40ee0c2c14e8679ed320b8c2578f8610.tar.bz2
trackermap-server-504a555b40ee0c2c14e8679ed320b8c2578f8610.zip
- Moved retrieving Accept to BaseResource
- Added Events report - Removed deviceIds from csv
Diffstat (limited to 'src/org/traccar/api/resource/ReportResource.java')
-rw-r--r--src/org/traccar/api/resource/ReportResource.java28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/org/traccar/api/resource/ReportResource.java b/src/org/traccar/api/resource/ReportResource.java
index 598cbebf6..cf11cd4e4 100644
--- a/src/org/traccar/api/resource/ReportResource.java
+++ b/src/org/traccar/api/resource/ReportResource.java
@@ -6,14 +6,12 @@ import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
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.ReportUtils;
import org.traccar.reports.Route;
import org.traccar.web.JsonConverter;
@@ -23,12 +21,10 @@ public class ReportResource extends BaseResource {
@Path("route")
@GET
- public Response getRoute(@Context HttpHeaders headers,
+ public Response getRoute(
@QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds,
@QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
- MultivaluedMap<String, String> headerParams = headers.getRequestHeaders();
- String accept = headerParams.getFirst("Accept");
- if (accept.equals("application/ms-excel")) {
+ if (getAcceptHeader().equals("application/ms-excel")) {
ResponseBuilder response = Response.ok(ReportUtils.getOut(Route.getCsv(getUserId(), deviceIds, groupIds,
JsonConverter.parseDate(from), JsonConverter.parseDate(to))));
response.type("application/ms-excel");
@@ -40,4 +36,22 @@ public class ReportResource extends BaseResource {
return response.build();
}
+ @Path("events")
+ @GET
+ public Response getEvents(
+ @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 {
+ if (getAcceptHeader().equals("application/ms-excel")) {
+ ResponseBuilder response = Response.ok(ReportUtils.getOut(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();
+ }
+
}