diff options
Diffstat (limited to 'src/main/java/org/traccar/api/resource')
6 files changed, 55 insertions, 51 deletions
diff --git a/src/main/java/org/traccar/api/resource/DeviceResource.java b/src/main/java/org/traccar/api/resource/DeviceResource.java index f9c9a139d..7006cdb84 100644 --- a/src/main/java/org/traccar/api/resource/DeviceResource.java +++ b/src/main/java/org/traccar/api/resource/DeviceResource.java @@ -52,7 +52,7 @@ public class DeviceResource extends BaseObjectResource<Device> { @QueryParam("uniqueId") List<String> uniqueIds, @QueryParam("id") List<Long> deviceIds) throws SQLException { DeviceManager deviceManager = Context.getDeviceManager(); - Set<Long> result = null; + Set<Long> result; if (all) { if (Context.getPermissionsManager().getUserAdmin(getUserId())) { result = deviceManager.getAllItems(); diff --git a/src/main/java/org/traccar/api/resource/PositionResource.java b/src/main/java/org/traccar/api/resource/PositionResource.java index 67aa6dd32..e93feaccf 100644 --- a/src/main/java/org/traccar/api/resource/PositionResource.java +++ b/src/main/java/org/traccar/api/resource/PositionResource.java @@ -17,7 +17,6 @@ package org.traccar.api.resource; import org.traccar.Context; import org.traccar.api.BaseResource; -import org.traccar.helper.DateUtil; import org.traccar.model.Position; import org.traccar.web.CsvBuilder; import org.traccar.web.GpxBuilder; @@ -35,6 +34,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.List; @Path("positions") @@ -50,7 +50,7 @@ public class PositionResource extends BaseResource { @GET public Collection<Position> getJson( @QueryParam("deviceId") long deviceId, @QueryParam("id") List<Long> positionIds, - @QueryParam("from") String from, @QueryParam("to") String to) + @QueryParam("from") Date from, @QueryParam("to") Date to) throws SQLException { if (!positionIds.isEmpty()) { ArrayList<Position> positions = new ArrayList<>(); @@ -65,8 +65,7 @@ public class PositionResource extends BaseResource { } else { Context.getPermissionsManager().checkDevice(getUserId(), deviceId); if (from != null && to != null) { - return Context.getDataManager().getPositions( - deviceId, DateUtil.parseDate(from), DateUtil.parseDate(to)); + return Context.getDataManager().getPositions(deviceId, from, to); } else { return Collections.singleton(Context.getDeviceManager().getLastPosition(deviceId)); } @@ -76,25 +75,23 @@ public class PositionResource extends BaseResource { @GET @Produces(TEXT_CSV) public Response getCsv( - @QueryParam("deviceId") long deviceId, @QueryParam("from") String from, @QueryParam("to") String to) + @QueryParam("deviceId") long deviceId, @QueryParam("from") Date from, @QueryParam("to") Date to) throws SQLException { Context.getPermissionsManager().checkDevice(getUserId(), deviceId); CsvBuilder csv = new CsvBuilder(); csv.addHeaderLine(new Position()); - csv.addArray(Context.getDataManager().getPositions( - deviceId, DateUtil.parseDate(from), DateUtil.parseDate(to))); + csv.addArray(Context.getDataManager().getPositions(deviceId, from, to)); return Response.ok(csv.build()).header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_CSV).build(); } @GET @Produces(GPX) public Response getGpx( - @QueryParam("deviceId") long deviceId, @QueryParam("from") String from, @QueryParam("to") String to) + @QueryParam("deviceId") long deviceId, @QueryParam("from") Date from, @QueryParam("to") Date to) throws SQLException { Context.getPermissionsManager().checkDevice(getUserId(), deviceId); GpxBuilder gpx = new GpxBuilder(Context.getIdentityManager().getById(deviceId).getName()); - gpx.addPositions(Context.getDataManager().getPositions( - deviceId, DateUtil.parseDate(from), DateUtil.parseDate(to))); + gpx.addPositions(Context.getDataManager().getPositions(deviceId, from, to)); return Response.ok(gpx.build()).header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_GPX).build(); } diff --git a/src/main/java/org/traccar/api/resource/ReportResource.java b/src/main/java/org/traccar/api/resource/ReportResource.java index d371cf987..7347bfd64 100644 --- a/src/main/java/org/traccar/api/resource/ReportResource.java +++ b/src/main/java/org/traccar/api/resource/ReportResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2020 Anton Tananaev (anton@traccar.org) * Copyright 2016 - 2018 Andrey Kunitsyn (andrey@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +20,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.sql.SQLException; import java.util.Collection; +import java.util.Date; import java.util.List; import javax.activation.DataHandler; @@ -39,7 +40,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.traccar.Context; import org.traccar.api.BaseResource; -import org.traccar.helper.DateUtil; +import org.traccar.helper.LogAction; import org.traccar.model.Event; import org.traccar.model.Position; import org.traccar.reports.Events; @@ -97,9 +98,9 @@ public class ReportResource extends BaseResource { @GET 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 Route.getObjects(getUserId(), deviceIds, groupIds, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + @QueryParam("from") Date from, @QueryParam("to") Date to) throws SQLException { + LogAction.logReport(getUserId(), "route", from, to, deviceIds, groupIds); + return Route.getObjects(getUserId(), deviceIds, groupIds, from, to); } @Path("route") @@ -107,11 +108,11 @@ public class ReportResource extends BaseResource { @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, @QueryParam("mail") boolean mail) + @QueryParam("from") Date from, @QueryParam("to") Date to, @QueryParam("mail") boolean mail) throws SQLException, IOException { return executeReport(getUserId(), mail, stream -> { - Route.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + LogAction.logReport(getUserId(), "route", from, to, deviceIds, groupIds); + Route.getExcel(stream, getUserId(), deviceIds, groupIds, from, to); }); } @@ -120,9 +121,9 @@ public class ReportResource extends BaseResource { 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 Events.getObjects(getUserId(), deviceIds, groupIds, types, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + @QueryParam("from") Date from, @QueryParam("to") Date to) throws SQLException { + LogAction.logReport(getUserId(), "events", from, to, deviceIds, groupIds); + return Events.getObjects(getUserId(), deviceIds, groupIds, types, from, to); } @Path("events") @@ -131,11 +132,11 @@ public class ReportResource extends BaseResource { 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, @QueryParam("mail") boolean mail) + @QueryParam("from") Date from, @QueryParam("to") Date to, @QueryParam("mail") boolean mail) throws SQLException, IOException { return executeReport(getUserId(), mail, stream -> { - Events.getExcel(stream, getUserId(), deviceIds, groupIds, types, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + LogAction.logReport(getUserId(), "events", from, to, deviceIds, groupIds); + Events.getExcel(stream, getUserId(), deviceIds, groupIds, types, from, to); }); } @@ -143,9 +144,10 @@ public class ReportResource extends BaseResource { @GET 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 Summary.getObjects(getUserId(), deviceIds, groupIds, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + @QueryParam("from") Date from, @QueryParam("to") Date to, @QueryParam("daily") boolean daily) + throws SQLException { + LogAction.logReport(getUserId(), "summary", from, to, deviceIds, groupIds); + return Summary.getObjects(getUserId(), deviceIds, groupIds, from, to, daily); } @Path("summary") @@ -153,11 +155,12 @@ public class ReportResource extends BaseResource { @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, @QueryParam("mail") boolean mail) + @QueryParam("from") Date from, @QueryParam("to") Date to, @QueryParam("daily") boolean daily, + @QueryParam("mail") boolean mail) throws SQLException, IOException { return executeReport(getUserId(), mail, stream -> { - Summary.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + LogAction.logReport(getUserId(), "summary", from, to, deviceIds, groupIds); + Summary.getExcel(stream, getUserId(), deviceIds, groupIds, from, to, daily); }); } @@ -166,9 +169,9 @@ public class ReportResource extends BaseResource { @Produces(MediaType.APPLICATION_JSON) 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 Trips.getObjects(getUserId(), deviceIds, groupIds, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + @QueryParam("from") Date from, @QueryParam("to") Date to) throws SQLException { + LogAction.logReport(getUserId(), "trips", from, to, deviceIds, groupIds); + return Trips.getObjects(getUserId(), deviceIds, groupIds, from, to); } @Path("trips") @@ -176,11 +179,11 @@ public class ReportResource extends BaseResource { @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, @QueryParam("mail") boolean mail) + @QueryParam("from") Date from, @QueryParam("to") Date to, @QueryParam("mail") boolean mail) throws SQLException, IOException { return executeReport(getUserId(), mail, stream -> { - Trips.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + LogAction.logReport(getUserId(), "trips", from, to, deviceIds, groupIds); + Trips.getExcel(stream, getUserId(), deviceIds, groupIds, from, to); }); } @@ -189,9 +192,9 @@ public class ReportResource extends BaseResource { @Produces(MediaType.APPLICATION_JSON) public Collection<StopReport> getStops( @QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds, - @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { - return Stops.getObjects(getUserId(), deviceIds, groupIds, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + @QueryParam("from") Date from, @QueryParam("to") Date to) throws SQLException { + LogAction.logReport(getUserId(), "stops", from, to, deviceIds, groupIds); + return Stops.getObjects(getUserId(), deviceIds, groupIds, from, to); } @Path("stops") @@ -199,11 +202,11 @@ public class ReportResource extends BaseResource { @Produces(XLSX) public Response getStopsExcel( @QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds, - @QueryParam("from") String from, @QueryParam("to") String to, @QueryParam("mail") boolean mail) + @QueryParam("from") Date from, @QueryParam("to") Date to, @QueryParam("mail") boolean mail) throws SQLException, IOException { return executeReport(getUserId(), mail, stream -> { - Stops.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + LogAction.logReport(getUserId(), "stops", from, to, deviceIds, groupIds); + Stops.getExcel(stream, getUserId(), deviceIds, groupIds, from, to); }); } diff --git a/src/main/java/org/traccar/api/resource/ServerResource.java b/src/main/java/org/traccar/api/resource/ServerResource.java index e7cad2a0c..91488afff 100644 --- a/src/main/java/org/traccar/api/resource/ServerResource.java +++ b/src/main/java/org/traccar/api/resource/ServerResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2020 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,12 @@ public class ServerResource extends BaseResource { @PermitAll @GET - public Server get() throws SQLException { - return Context.getPermissionsManager().getServer(); + public Server get(@QueryParam("force") boolean force) throws SQLException { + if (force) { + return Context.getDataManager().getServer(); + } else { + return Context.getPermissionsManager().getServer(); + } } @PUT diff --git a/src/main/java/org/traccar/api/resource/StatisticsResource.java b/src/main/java/org/traccar/api/resource/StatisticsResource.java index e801d4ff3..58073e7d1 100644 --- a/src/main/java/org/traccar/api/resource/StatisticsResource.java +++ b/src/main/java/org/traccar/api/resource/StatisticsResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2020 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.traccar.api.resource; import org.traccar.Context; import org.traccar.api.BaseResource; -import org.traccar.helper.DateUtil; import org.traccar.model.Statistics; import javax.ws.rs.Consumes; @@ -28,6 +27,7 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import java.sql.SQLException; import java.util.Collection; +import java.util.Date; @Path("statistics") @Produces(MediaType.APPLICATION_JSON) @@ -36,9 +36,9 @@ public class StatisticsResource extends BaseResource { @GET public Collection<Statistics> get( - @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { + @QueryParam("from") Date from, @QueryParam("to") Date to) throws SQLException { Context.getPermissionsManager().checkAdmin(getUserId()); - return Context.getDataManager().getStatistics(DateUtil.parseDate(from), DateUtil.parseDate(to)); + return Context.getDataManager().getStatistics(from, to); } } diff --git a/src/main/java/org/traccar/api/resource/UserResource.java b/src/main/java/org/traccar/api/resource/UserResource.java index 0b42d8d92..813ace6d6 100644 --- a/src/main/java/org/traccar/api/resource/UserResource.java +++ b/src/main/java/org/traccar/api/resource/UserResource.java @@ -48,7 +48,7 @@ public class UserResource extends BaseObjectResource<User> { @GET public Collection<User> get(@QueryParam("userId") long userId) throws SQLException { UsersManager usersManager = Context.getUsersManager(); - Set<Long> result = null; + Set<Long> result; if (Context.getPermissionsManager().getUserAdmin(getUserId())) { if (userId != 0) { result = usersManager.getUserItems(userId); |