aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorJan-Piet Mens <jp@mens.de>2017-07-19 09:38:51 +0200
committerJan-Piet Mens <jp@mens.de>2017-07-19 09:38:51 +0200
commit2aaa4a5e00e801b9b310e42f538113dd83e60188 (patch)
treee7f8b07359e50f97d74b691c21a143337e1c3fd7 /src/org/traccar
parent73fb44dfb7dea5cdddcb3ab939e9b7a64ae49abb (diff)
downloadtrackermap-server-2aaa4a5e00e801b9b310e42f538113dd83e60188.tar.gz
trackermap-server-2aaa4a5e00e801b9b310e42f538113dd83e60188.tar.bz2
trackermap-server-2aaa4a5e00e801b9b310e42f538113dd83e60188.zip
[NEW] add GET with list of uniqueId
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/api/resource/DeviceResource.java41
1 files changed, 25 insertions, 16 deletions
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<Device> get(
@QueryParam("all") boolean all, @QueryParam("userId") long userId,
+ @QueryParam("uniqueId") List<String> uniqueIds,
@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());
- }
+ 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<Device> devices = new ArrayList<>();
+ }
+ if (uniqueIds.isEmpty() && deviceIds.isEmpty()) {
+ if (userId == 0) {
+ userId = getUserId();
+ }
+ Context.getPermissionsManager().checkUser(getUserId(), userId);
+ return Context.getDeviceManager().getDevices(userId);
+ }
+
+ ArrayList<Device> 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