aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource/ReportResource.java
diff options
context:
space:
mode:
authorRenaud Allard <renaud@allard.it>2016-10-20 08:31:57 +0200
committerRenaud Allard <renaud@allard.it>2016-10-20 08:31:57 +0200
commit1104c2738e19579c5865db5c030388e1e320f0b4 (patch)
treea6571455b6f5d88581c8034bd1059968d506ed01 /src/org/traccar/api/resource/ReportResource.java
parent0d347cd7aac2ebfad01c1635f3893964be2e67ae (diff)
parent4f7356cc1c6962f46ca522246d5b63dc06a2d268 (diff)
downloadtrackermap-server-1104c2738e19579c5865db5c030388e1e320f0b4.tar.gz
trackermap-server-1104c2738e19579c5865db5c030388e1e320f0b4.tar.bz2
trackermap-server-1104c2738e19579c5865db5c030388e1e320f0b4.zip
Merge branch 'master' of https://github.com/tananaev/traccar
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();
}
}