From 5890e03199142f041dc19160329a740b4d01450d Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 7 Jun 2022 19:23:16 -0700 Subject: Fix last position requests (fix #4863) --- .../java/org/traccar/api/resource/AttributeResource.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/main/java/org/traccar/api/resource') diff --git a/src/main/java/org/traccar/api/resource/AttributeResource.java b/src/main/java/org/traccar/api/resource/AttributeResource.java index fdd0d4f6f..ab7e43add 100644 --- a/src/main/java/org/traccar/api/resource/AttributeResource.java +++ b/src/main/java/org/traccar/api/resource/AttributeResource.java @@ -53,22 +53,12 @@ public class AttributeResource extends ExtendedObjectResource { permissionsService.checkAdmin(getUserId()); permissionsService.checkPermission(Device.class, getUserId(), deviceId); - Device device = storage.getObject(Device.class, new Request( + Position position = storage.getObject(Position.class, new Request( new Columns.All(), - new Condition.Equals("id", "id", deviceId))); - if (device == null) { - throw new IllegalArgumentException("Device not found"); - } - - Position last = storage.getObject(Position.class, new Request( - new Columns.All(), - new Condition.Equals("id", "id", device.getPositionId()))); - if (last == null) { - throw new IllegalArgumentException("Device has no last position"); - } + new Condition.LatestPositions(deviceId))); Object result = new ComputedAttributesHandler(Context.getConfig(), Context.getIdentityManager(), null) - .computeAttribute(entity, last); + .computeAttribute(entity, position); if (result != null) { switch (entity.getType()) { case "number": -- cgit v1.2.3