diff options
author | Abyss777 <abyss@fox5.ru> | 2016-11-30 09:58:48 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2016-11-30 09:58:48 +0500 |
commit | d5ec75ecd3697e37782c9dd53998c889d5b9ef4d (patch) | |
tree | 22096d3869db469ad556a0e7aeaecd17ad02c6b6 | |
parent | e24b3588647fc1597f31b9bcd26ed9b7378f9f5b (diff) | |
download | trackermap-server-d5ec75ecd3697e37782c9dd53998c889d5b9ef4d.tar.gz trackermap-server-d5ec75ecd3697e37782c9dd53998c889d5b9ef4d.tar.bz2 trackermap-server-d5ec75ecd3697e37782c9dd53998c889d5b9ef4d.zip |
Add API to get positions by Id
-rw-r--r-- | setup/default.xml | 4 | ||||
-rw-r--r-- | src/org/traccar/api/resource/PositionResource.java | 16 | ||||
-rw-r--r-- | src/org/traccar/database/DataManager.java | 6 |
3 files changed, 23 insertions, 3 deletions
diff --git a/setup/default.xml b/setup/default.xml index 7df352c4d..5c6f8fe90 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -171,6 +171,10 @@ SELECT * FROM positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime </entry> + <entry key='database.selectPosition'> + SELECT * FROM positions WHERE id = :id + </entry> + <entry key='database.insertPosition'> INSERT INTO positions (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, attributes) VALUES (:deviceId, :protocol, :now, :deviceTime, :fixTime, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :attributes) diff --git a/src/org/traccar/api/resource/PositionResource.java b/src/org/traccar/api/resource/PositionResource.java index c1cfc0b5c..4db73cfd2 100644 --- a/src/org/traccar/api/resource/PositionResource.java +++ b/src/org/traccar/api/resource/PositionResource.java @@ -32,7 +32,9 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; @Path("positions") @Consumes(MediaType.APPLICATION_JSON) @@ -46,9 +48,18 @@ public class PositionResource extends BaseResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<Position> getJson( - @QueryParam("deviceId") long deviceId, @QueryParam("from") String from, @QueryParam("to") String to) + @QueryParam("deviceId") long deviceId, @QueryParam("positionId") List<Long> positionIds, + @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { - if (deviceId == 0) { + if (!positionIds.isEmpty()) { + ArrayList<Position> positions = new ArrayList<>(); + for (Long positionId : positionIds) { + Position position = Context.getDataManager().getPosition(positionId); + Context.getPermissionsManager().checkDevice(getUserId(), position.getDeviceId()); + positions.add(position); + } + return positions; + } else if (deviceId == 0) { return Context.getDeviceManager().getInitialState(getUserId()); } else { Context.getPermissionsManager().checkDevice(getUserId(), deviceId); @@ -81,5 +92,4 @@ public class PositionResource extends BaseResource { deviceId, DateUtil.parseDate(from), DateUtil.parseDate(to))); return Response.ok(gpx.build()).header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_GPX).build(); } - } diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index afa8b1677..8be53ad7b 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -280,6 +280,12 @@ public class DataManager { .executeQuery(Position.class); } + public Position getPosition(long positionId) throws SQLException { + return QueryBuilder.create(dataSource, getQuery("database.selectPosition")) + .setLong("id", positionId) + .executeQuerySingle(Position.class); + } + public void addPosition(Position position) throws SQLException { position.setId(QueryBuilder.create(dataSource, getQuery("database.insertPosition"), true) .setDate("now", new Date()) |