diff options
Diffstat (limited to 'src/org/traccar/api')
-rw-r--r-- | src/org/traccar/api/resource/ReportResource.java | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/org/traccar/api/resource/ReportResource.java b/src/org/traccar/api/resource/ReportResource.java index 8682070b1..e87d6401c 100644 --- a/src/org/traccar/api/resource/ReportResource.java +++ b/src/org/traccar/api/resource/ReportResource.java @@ -8,6 +8,8 @@ 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.HttpHeaders; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.traccar.api.BaseResource; @@ -17,12 +19,15 @@ import org.traccar.reports.Route; import org.traccar.web.JsonConverter; @Path("reports") -@Consumes("application/json") +@Consumes(MediaType.APPLICATION_JSON) public class ReportResource extends BaseResource { + public static final String TEXT_CSV = "text/csv"; + public static final String CONTENT_DISPOSITION_VALUE = "attachment; filename=report.csv"; + @Path("route") @GET - @Produces("application/json") + @Produces(MediaType.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 { @@ -32,17 +37,19 @@ public class ReportResource extends BaseResource { @Path("route") @GET - @Produces("application/ms-excel") + @Produces(TEXT_CSV) 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(); + JsonConverter.parseDate(from), JsonConverter.parseDate(to))) + .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE) + .build(); } @Path("events") @GET - @Produces("application/json") + @Produces(MediaType.APPLICATION_JSON) public Response getEventsJson( @QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds, @QueryParam("type") final List<String> types, @@ -53,18 +60,20 @@ public class ReportResource extends BaseResource { @Path("events") @GET - @Produces("application/ms-excel") + @Produces(TEXT_CSV) 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(); + types, JsonConverter.parseDate(from), JsonConverter.parseDate(to))) + .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE) + .build(); } @Path("summary") @GET - @Produces("application/json") + @Produces(MediaType.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 { @@ -74,12 +83,14 @@ public class ReportResource extends BaseResource { @Path("summary") @GET - @Produces("application/ms-excel") + @Produces(TEXT_CSV) 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(); + JsonConverter.parseDate(from), JsonConverter.parseDate(to))) + .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE) + .build(); } } |