diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-11-01 19:11:22 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-01 19:11:22 +1300 |
commit | 7adac25c304b046ebfc59b1197663625e862cc81 (patch) | |
tree | e61c162edfe823f7f97226c097ac2173ccff3f96 /src/org/traccar/api/resource/ReportResource.java | |
parent | 12ddac1b181692a1e32a1a26e9189ab3091dd4bc (diff) | |
parent | fdc61388a4f86bbd7fc7034fcf672486910eb58c (diff) | |
download | trackermap-server-7adac25c304b046ebfc59b1197663625e862cc81.tar.gz trackermap-server-7adac25c304b046ebfc59b1197663625e862cc81.tar.bz2 trackermap-server-7adac25c304b046ebfc59b1197663625e862cc81.zip |
Merge pull request #2502 from Abyss777/reports_jsonconverter
Remove explicit JSON conversion from reports
Diffstat (limited to 'src/org/traccar/api/resource/ReportResource.java')
-rw-r--r-- | src/org/traccar/api/resource/ReportResource.java | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/src/org/traccar/api/resource/ReportResource.java b/src/org/traccar/api/resource/ReportResource.java index 709eef377..2717fe01e 100644 --- a/src/org/traccar/api/resource/ReportResource.java +++ b/src/org/traccar/api/resource/ReportResource.java @@ -3,6 +3,7 @@ package org.traccar.api.resource; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.sql.SQLException; +import java.util.Collection; import java.util.List; import javax.ws.rs.Consumes; @@ -15,11 +16,15 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.traccar.api.BaseResource; +import org.traccar.helper.DateUtil; +import org.traccar.model.Event; +import org.traccar.model.Position; import org.traccar.reports.Events; import org.traccar.reports.Summary; import org.traccar.reports.Trips; +import org.traccar.reports.model.SummaryReport; +import org.traccar.reports.model.TripReport; import org.traccar.reports.Route; -import org.traccar.web.JsonConverter; @Path("reports") @Consumes(MediaType.APPLICATION_JSON) @@ -31,11 +36,11 @@ public class ReportResource extends BaseResource { @Path("route") @GET @Produces(MediaType.APPLICATION_JSON) - public Response getRouteJson( + public Collection<Position> getRoute( @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(); + return Route.getObjects(getUserId(), deviceIds, groupIds, + DateUtil.parseDate(from), DateUtil.parseDate(to)); } @Path("route") @@ -46,7 +51,7 @@ public class ReportResource extends BaseResource { @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)); + DateUtil.parseDate(from), DateUtil.parseDate(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -55,12 +60,12 @@ public class ReportResource extends BaseResource { @Path("events") @GET @Produces(MediaType.APPLICATION_JSON) - public Response getEventsJson( + public Collection<Event> 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 { - return Response.ok(Events.getJson(getUserId(), deviceIds, groupIds, types, - JsonConverter.parseDate(from), JsonConverter.parseDate(to))).build(); + return Events.getObjects(getUserId(), deviceIds, groupIds, types, + DateUtil.parseDate(from), DateUtil.parseDate(to)); } @Path("events") @@ -72,7 +77,7 @@ public class ReportResource extends BaseResource { @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)); + DateUtil.parseDate(from), DateUtil.parseDate(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -81,11 +86,11 @@ public class ReportResource extends BaseResource { @Path("summary") @GET @Produces(MediaType.APPLICATION_JSON) - public Response getSummaryJson( + public Collection<SummaryReport> getSummary( @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(); + return Summary.getObjects(getUserId(), deviceIds, groupIds, + DateUtil.parseDate(from), DateUtil.parseDate(to)); } @Path("summary") @@ -96,7 +101,7 @@ public class ReportResource extends BaseResource { @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)); + DateUtil.parseDate(from), DateUtil.parseDate(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -105,11 +110,11 @@ public class ReportResource extends BaseResource { @Path("trips") @GET @Produces(MediaType.APPLICATION_JSON) - public Response getTripsJson( + public Collection<TripReport> getTrips( @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.getJson(getUserId(), deviceIds, groupIds, - JsonConverter.parseDate(from), JsonConverter.parseDate(to))).build(); + return Trips.getObjects(getUserId(), deviceIds, groupIds, + DateUtil.parseDate(from), DateUtil.parseDate(to)); } @Path("trips") @@ -120,7 +125,7 @@ public class ReportResource extends BaseResource { @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)); + DateUtil.parseDate(from), DateUtil.parseDate(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); |