aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-07-02 22:07:53 +1200
committerGitHub <noreply@github.com>2017-07-02 22:07:53 +1200
commitae6d52ee6ae9cf832b5d23c43e40852450d6f4cc (patch)
treef88eb09c75486037f46b33a3132d144ecacaf766
parent64501f3f846c62527bbc224f3fb031b9f708475f (diff)
parentc67bf883bf0aa84293b94b000536c2061c3e00b2 (diff)
downloadtraccar-server-ae6d52ee6ae9cf832b5d23c43e40852450d6f4cc.tar.gz
traccar-server-ae6d52ee6ae9cf832b5d23c43e40852450d6f4cc.tar.bz2
traccar-server-ae6d52ee6ae9cf832b5d23c43e40852450d6f4cc.zip
Merge pull request #3309 from ckrey/api-get-device
[NEW] add GET device to API for external monitoring
-rw-r--r--src/org/traccar/api/resource/DeviceResource.java32
-rw-r--r--swagger.json10
2 files changed, 31 insertions, 11 deletions
diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java
index bfd05aad5..ce46b4e29 100644
--- a/src/org/traccar/api/resource/DeviceResource.java
+++ b/src/org/traccar/api/resource/DeviceResource.java
@@ -33,7 +33,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("devices")
@Produces(MediaType.APPLICATION_JSON)
@@ -42,20 +44,30 @@ public class DeviceResource extends BaseResource {
@GET
public Collection<Device> get(
- @QueryParam("all") boolean all, @QueryParam("userId") long userId) throws SQLException {
- if (all) {
- if (Context.getPermissionsManager().isAdmin(getUserId())) {
- return Context.getDeviceManager().getAllDevices();
+ @QueryParam("all") boolean all, @QueryParam("userId") long userId,
+ @QueryParam("id") List<Long> deviceIds) throws SQLException {
+ if (deviceIds.isEmpty()) {
+ if (all) {
+ if (Context.getPermissionsManager().isAdmin(getUserId())) {
+ return Context.getDeviceManager().getAllDevices();
+ } else {
+ Context.getPermissionsManager().checkManager(getUserId());
+ return Context.getDeviceManager().getManagedDevices(getUserId());
+ }
} else {
- Context.getPermissionsManager().checkManager(getUserId());
- return Context.getDeviceManager().getManagedDevices(getUserId());
+ if (userId == 0) {
+ userId = getUserId();
+ }
+ Context.getPermissionsManager().checkUser(getUserId(), userId);
+ return Context.getDeviceManager().getDevices(userId);
}
} else {
- if (userId == 0) {
- userId = getUserId();
+ ArrayList<Device> devices = new ArrayList<>();
+ for (Long deviceId : deviceIds) {
+ Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
+ devices.add(Context.getDeviceManager().getDeviceById(deviceId));
}
- Context.getPermissionsManager().checkUser(getUserId(), userId);
- return Context.getDeviceManager().getDevices(userId);
+ return devices;
}
}
diff --git a/swagger.json b/swagger.json
index 32391d4fa..734e42eab 100644
--- a/swagger.json
+++ b/swagger.json
@@ -57,6 +57,14 @@
},
{
"$ref": "#/parameters/userId"
+ },
+ {
+ "name" : "id",
+ "in" : "query",
+ "description" : "To fetch one or more devices. Multiple params can be passed like `id=31&id=42`",
+ "required" : false,
+ "type" : "integer",
+ "collectionFormat" : "multi"
}
],
"responses": {
@@ -112,7 +120,7 @@
}
},
"delete": {
- "summary": "Update a Device",
+ "summary": "Delete a Device",
"parameters": [
{
"$ref": "#/parameters/entityId"