aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-07-19 22:07:07 +1200
committerGitHub <noreply@github.com>2017-07-19 22:07:07 +1200
commitcd0fea51f9b654744a29530cb8c4ef347dc8e064 (patch)
tree6a074823806e97236f76aa6e7f5bbed94ac04960 /src
parent5b56c2cc17fa23251b1985aa4d8f56dd6552b970 (diff)
parent97d57828301ef04ccd4a3c58ca9ce5a23038345e (diff)
downloadtrackermap-server-cd0fea51f9b654744a29530cb8c4ef347dc8e064.tar.gz
trackermap-server-cd0fea51f9b654744a29530cb8c4ef347dc8e064.tar.bz2
trackermap-server-cd0fea51f9b654744a29530cb8c4ef347dc8e064.zip
Merge pull request #3369 from jpmens/device_uniqueid
[NEW] add GET with list of uniqueId to API
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/api/resource/DeviceResource.java44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java
index ce46b4e29..2957d623c 100644
--- a/src/org/traccar/api/resource/DeviceResource.java
+++ b/src/org/traccar/api/resource/DeviceResource.java
@@ -45,30 +45,36 @@ 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<>();
- for (Long deviceId : deviceIds) {
- Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- devices.add(Context.getDeviceManager().getDeviceById(deviceId));
+ }
+ if (uniqueIds.isEmpty() && deviceIds.isEmpty()) {
+ if (userId == 0) {
+ userId = getUserId();
}
- return devices;
+ Context.getPermissionsManager().checkUser(getUserId(), userId);
+ return Context.getDeviceManager().getDevices(userId);
+ }
+
+ ArrayList<Device> devices = new ArrayList<>();
+
+ for (String uniqueId : uniqueIds) {
+ Device device = Context.getDeviceManager().getDeviceByUniqueId(uniqueId);
+ Context.getPermissionsManager().checkDevice(getUserId(), device.getId());
+ devices.add(device);
+ }
+ for (Long deviceId : deviceIds) {
+ Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
+ devices.add(Context.getDeviceManager().getDeviceById(deviceId));
}
+ return devices;
}
@POST