From 2aaa4a5e00e801b9b310e42f538113dd83e60188 Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Wed, 19 Jul 2017 09:38:51 +0200 Subject: [NEW] add GET with list of uniqueId --- src/org/traccar/api/resource/DeviceResource.java | 41 +++++++++++++++--------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'src/org/traccar/api') diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java index ce46b4e29..0bf0aa45f 100644 --- a/src/org/traccar/api/resource/DeviceResource.java +++ b/src/org/traccar/api/resource/DeviceResource.java @@ -45,30 +45,39 @@ public class DeviceResource extends BaseResource { @GET public Collection get( @QueryParam("all") boolean all, @QueryParam("userId") long userId, + @QueryParam("uniqueId") List uniqueIds, @QueryParam("id") List 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()); - } + if (all) { + if (Context.getPermissionsManager().isAdmin(getUserId())) { + return Context.getDeviceManager().getAllDevices(); } else { - if (userId == 0) { - userId = getUserId(); - } - Context.getPermissionsManager().checkUser(getUserId(), userId); - return Context.getDeviceManager().getDevices(userId); + Context.getPermissionsManager().checkManager(getUserId()); + return Context.getDeviceManager().getManagedDevices(getUserId()); } - } else { - ArrayList devices = new ArrayList<>(); + } + if (uniqueIds.isEmpty() && deviceIds.isEmpty()) { + if (userId == 0) { + userId = getUserId(); + } + Context.getPermissionsManager().checkUser(getUserId(), userId); + return Context.getDeviceManager().getDevices(userId); + } + + ArrayList devices = new ArrayList<>(); + if (!uniqueIds.isEmpty()) { + for (String uniqueId : uniqueIds) { + Device device = Context.getDeviceManager().getDeviceByUniqueId(uniqueId); + Context.getPermissionsManager().checkDevice(getUserId(), device.getId()); + devices.add(device); + } + } + if (!deviceIds.isEmpty()) { for (Long deviceId : deviceIds) { Context.getPermissionsManager().checkDevice(getUserId(), deviceId); devices.add(Context.getDeviceManager().getDeviceById(deviceId)); } - return devices; } + return devices; } @POST -- cgit v1.2.3 From 97d57828301ef04ccd4a3c58ca9ce5a23038345e Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Wed, 19 Jul 2017 12:02:27 +0200 Subject: remove redundant checks --- src/org/traccar/api/resource/DeviceResource.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/org/traccar/api') diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java index 0bf0aa45f..2957d623c 100644 --- a/src/org/traccar/api/resource/DeviceResource.java +++ b/src/org/traccar/api/resource/DeviceResource.java @@ -64,18 +64,15 @@ public class DeviceResource extends BaseResource { } ArrayList devices = new ArrayList<>(); - if (!uniqueIds.isEmpty()) { - for (String uniqueId : uniqueIds) { - Device device = Context.getDeviceManager().getDeviceByUniqueId(uniqueId); - Context.getPermissionsManager().checkDevice(getUserId(), device.getId()); - devices.add(device); - } + + for (String uniqueId : uniqueIds) { + Device device = Context.getDeviceManager().getDeviceByUniqueId(uniqueId); + Context.getPermissionsManager().checkDevice(getUserId(), device.getId()); + devices.add(device); } - if (!deviceIds.isEmpty()) { - for (Long deviceId : deviceIds) { - Context.getPermissionsManager().checkDevice(getUserId(), deviceId); - devices.add(Context.getDeviceManager().getDeviceById(deviceId)); - } + for (Long deviceId : deviceIds) { + Context.getPermissionsManager().checkDevice(getUserId(), deviceId); + devices.add(Context.getDeviceManager().getDeviceById(deviceId)); } return devices; } -- cgit v1.2.3