diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-18 11:08:32 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-18 11:08:32 -0700 |
commit | ddbe4d7de6ae7590e2b927066312597efa129393 (patch) | |
tree | 777882e24ce5488b4cfc8a4d6f11119abcbeb7a3 /src/main/java/org/traccar/helper/model | |
parent | 182656b6dc1fb5d167bb752c16ecf633add001a8 (diff) | |
download | trackermap-server-ddbe4d7de6ae7590e2b927066312597efa129393.tar.gz trackermap-server-ddbe4d7de6ae7590e2b927066312597efa129393.tar.bz2 trackermap-server-ddbe4d7de6ae7590e2b927066312597efa129393.zip |
Remove positions from manager
Diffstat (limited to 'src/main/java/org/traccar/helper/model')
-rw-r--r-- | src/main/java/org/traccar/helper/model/PositionUtil.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/helper/model/PositionUtil.java b/src/main/java/org/traccar/helper/model/PositionUtil.java index 566e31bc5..31f828947 100644 --- a/src/main/java/org/traccar/helper/model/PositionUtil.java +++ b/src/main/java/org/traccar/helper/model/PositionUtil.java @@ -15,7 +15,10 @@ */ package org.traccar.helper.model; +import org.traccar.model.BaseModel; +import org.traccar.model.Device; import org.traccar.model.Position; +import org.traccar.model.User; import org.traccar.session.cache.CacheManager; import org.traccar.storage.Storage; import org.traccar.storage.StorageException; @@ -26,6 +29,7 @@ import org.traccar.storage.query.Request; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; public final class PositionUtil { @@ -60,4 +64,17 @@ public final class PositionUtil { new Order("fixTime"))); } + public static List<Position> getLatestPositions(Storage storage, long userId) throws StorageException { + var devices = storage.getObjects(Device.class, new Request( + new Columns.Include("id"), + new Condition.Permission(User.class, userId, Device.class))); + var deviceIds = devices.stream().map(BaseModel::getId).collect(Collectors.toUnmodifiableSet()); + + var positions = storage.getObjects(Position.class, new Request( + new Columns.All(), new Condition.LatestPositions())); + return positions.stream() + .filter(position -> deviceIds.contains(position.getDeviceId())) + .collect(Collectors.toList()); + } + } |