diff options
author | Christoph Krey <krey.christoph@gmail.com> | 2017-07-01 21:20:41 +0200 |
---|---|---|
committer | Christoph Krey <krey.christoph@gmail.com> | 2017-07-01 21:20:41 +0200 |
commit | 4fce9334c72acf8e7ef78c7b2c7b60380e77e6cb (patch) | |
tree | 697c7d8898e70d81f1d4d8e0498f86c7b122c460 /src/org | |
parent | 89f5ca6340b71f01e57684ed4900c801e043a9c4 (diff) | |
download | trackermap-server-4fce9334c72acf8e7ef78c7b2c7b60380e77e6cb.tar.gz trackermap-server-4fce9334c72acf8e7ef78c7b2c7b60380e77e6cb.tar.bz2 trackermap-server-4fce9334c72acf8e7ef78c7b2c7b60380e77e6cb.zip |
[FIX] get devices with IDs works like PositionResource
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/api/resource/DeviceResource.java | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java index 64d40f4af..0f75b5e33 100644 --- a/src/org/traccar/api/resource/DeviceResource.java +++ b/src/org/traccar/api/resource/DeviceResource.java @@ -31,10 +31,11 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import javax.ws.rs.WebApplicationException; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; @Path("devices") @Produces(MediaType.APPLICATION_JSON) @@ -43,20 +44,31 @@ 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) { + Device device = Context.getDeviceManager().getDeviceById(deviceId); + Context.getPermissionsManager().checkDevice(getUserId(), device.getId()); + devices.add(device); } - Context.getPermissionsManager().checkUser(getUserId(), userId); - return Context.getDeviceManager().getDevices(userId); + return devices; } } @@ -75,18 +87,6 @@ public class DeviceResource extends BaseResource { } @Path("{id}") - @GET - public Response get(@PathParam("id") long id) throws SQLException { - Context.getPermissionsManager().checkDevice(getUserId(), id); - Device device = Context.getDeviceManager().getDeviceById(id); - if (device != null) { - return Response.ok(Context.getDeviceManager().getDeviceById(id)).build(); - } else { - throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build()); - } - } - - @Path("{id}") @PUT public Response update(Device entity) throws SQLException { Context.getPermissionsManager().checkReadonly(getUserId()); |