aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource/ReportResource.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-10-17 14:02:23 +0500
committerAbyss777 <abyss@fox5.ru>2016-10-17 14:02:23 +0500
commitc613143105d9f7c898dd3fb236d683b76cf8a42c (patch)
tree0facff2ac16b5d0067fc651fd5024aa2b668ebaf /src/org/traccar/api/resource/ReportResource.java
parent83ca0476167d91f16f18ae3cc532d56cd97f743e (diff)
downloadtrackermap-server-c613143105d9f7c898dd3fb236d683b76cf8a42c.tar.gz
trackermap-server-c613143105d9f7c898dd3fb236d683b76cf8a42c.tar.bz2
trackermap-server-c613143105d9f7c898dd3fb236d683b76cf8a42c.zip
- Implement export reports to excel
- Migrate csv export to /api/positions
Diffstat (limited to 'src/org/traccar/api/resource/ReportResource.java')
-rw-r--r--src/org/traccar/api/resource/ReportResource.java70
1 files changed, 40 insertions, 30 deletions
diff --git a/src/org/traccar/api/resource/ReportResource.java b/src/org/traccar/api/resource/ReportResource.java
index 0dd0452ff..709eef377 100644
--- a/src/org/traccar/api/resource/ReportResource.java
+++ b/src/org/traccar/api/resource/ReportResource.java
@@ -1,5 +1,7 @@
package org.traccar.api.resource;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
@@ -23,8 +25,8 @@ import org.traccar.web.JsonConverter;
@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";
+ private static final String XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+ private static final String CONTENT_DISPOSITION_VALUE_XLSX = "attachment; filename=report.xlsx";
@Path("route")
@GET
@@ -38,14 +40,16 @@ public class ReportResource extends BaseResource {
@Path("route")
@GET
- @Produces(TEXT_CSV)
- public Response getRouteCsv(
+ @Produces(XLSX)
+ public Response getRouteExcel(
@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)))
- .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE)
- .build();
+ @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ Route.getExcel(stream, getUserId(), deviceIds, groupIds,
+ JsonConverter.parseDate(from), JsonConverter.parseDate(to));
+
+ return Response.ok(stream.toByteArray())
+ .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build();
}
@Path("events")
@@ -61,15 +65,17 @@ public class ReportResource extends BaseResource {
@Path("events")
@GET
- @Produces(TEXT_CSV)
- public Response getEventsCsv(
+ @Produces(XLSX)
+ public Response getEventsExcel(
@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)))
- .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE)
- .build();
+ @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ Events.getExcel(stream, getUserId(), deviceIds, groupIds, types,
+ JsonConverter.parseDate(from), JsonConverter.parseDate(to));
+
+ return Response.ok(stream.toByteArray())
+ .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build();
}
@Path("summary")
@@ -84,14 +90,16 @@ public class ReportResource extends BaseResource {
@Path("summary")
@GET
- @Produces(TEXT_CSV)
- public Response getSummaryCsv(
+ @Produces(XLSX)
+ public Response getSummaryExcel(
@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)))
- .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE)
- .build();
+ @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ Summary.getExcel(stream, getUserId(), deviceIds, groupIds,
+ JsonConverter.parseDate(from), JsonConverter.parseDate(to));
+
+ return Response.ok(stream.toByteArray())
+ .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build();
}
@Path("trips")
@@ -106,14 +114,16 @@ public class ReportResource extends BaseResource {
@Path("trips")
@GET
- @Produces(TEXT_CSV)
- public Response getTripsCsv(
+ @Produces(XLSX)
+ public Response getTripsExcel(
@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(Trips.getCsv(getUserId(), deviceIds, groupIds,
- JsonConverter.parseDate(from), JsonConverter.parseDate(to)))
- .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE)
- .build();
+ @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ Trips.getExcel(stream, getUserId(), deviceIds, groupIds,
+ JsonConverter.parseDate(from), JsonConverter.parseDate(to));
+
+ return Response.ok(stream.toByteArray())
+ .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build();
}
}