aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-30 09:15:19 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-30 09:15:19 -0700
commit45c076da2d5be1cad89a9a7e1c0dc2d3755bd7b5 (patch)
treea2fcc7927cff2ac684df911bab962b4237e060cb /src/main
parent29ad12512ba5e109e78a3c8384ae10747e1eabec (diff)
downloadtrackermap-server-45c076da2d5be1cad89a9a7e1c0dc2d3755bd7b5.tar.gz
trackermap-server-45c076da2d5be1cad89a9a7e1c0dc2d3755bd7b5.tar.bz2
trackermap-server-45c076da2d5be1cad89a9a7e1c0dc2d3755bd7b5.zip
Fix online device removal
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/session/cache/CacheManager.java56
1 files changed, 29 insertions, 27 deletions
diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java
index bc5fc357f..9d1db7d14 100644
--- a/src/main/java/org/traccar/session/cache/CacheManager.java
+++ b/src/main/java/org/traccar/session/cache/CacheManager.java
@@ -268,38 +268,40 @@ public class CacheManager implements BroadcastInterface {
Device device = storage.getObject(Device.class, new Request(
new Columns.All(), new Condition.Equals("id", "id", deviceId)));
- addObject(deviceId, device);
+ if (device != null) {
+ addObject(deviceId, device);
+
+ for (Class<? extends BaseModel> clazz : CLASSES) {
+ var objects = storage.getObjects(clazz, new Request(
+ new Columns.All(), new Condition.Permission(Device.class, deviceId, clazz)));
+ links.put(clazz, objects.stream().map(BaseModel::getId).collect(Collectors.toList()));
+ objects.forEach(object -> addObject(deviceId, object));
+ }
- for (Class<? extends BaseModel> clazz : CLASSES) {
- var objects = storage.getObjects(clazz, new Request(
- new Columns.All(), new Condition.Permission(Device.class, deviceId, clazz)));
- links.put(clazz, objects.stream().map(BaseModel::getId).collect(Collectors.toList()));
- objects.forEach(object -> addObject(deviceId, object));
- }
+ var users = storage.getObjects(User.class, new Request(
+ new Columns.All(), new Condition.Permission(User.class, Device.class, deviceId)));
+ links.put(User.class, users.stream().map(BaseModel::getId).collect(Collectors.toList()));
+ for (var user : users) {
+ addObject(deviceId, user);
+ var notifications = storage.getObjects(Notification.class, new Request(
+ new Columns.All(), new Condition.Permission(User.class, user.getId(), Notification.class)));
+ notifications.stream()
+ .filter(Notification::getAlways)
+ .forEach(object -> {
+ links.computeIfAbsent(Notification.class, k -> new LinkedList<>()).add(object.getId());
+ addObject(deviceId, object);
+ });
+ }
- var users = storage.getObjects(User.class, new Request(
- new Columns.All(), new Condition.Permission(User.class, Device.class, deviceId)));
- links.put(User.class, users.stream().map(BaseModel::getId).collect(Collectors.toList()));
- for (var user : users) {
- addObject(deviceId, user);
- var notifications = storage.getObjects(Notification.class, new Request(
- new Columns.All(), new Condition.Permission(User.class, user.getId(), Notification.class)));
- notifications.stream()
- .filter(Notification::getAlways)
- .forEach(object -> {
- links.computeIfAbsent(Notification.class, k -> new LinkedList<>()).add(object.getId());
- addObject(deviceId, object);
- });
- }
+ deviceLinks.put(deviceId, links);
- deviceLinks.put(deviceId, links);
+ if (device.getPositionId() > 0) {
+ devicePositions.put(deviceId, storage.getObject(Position.class, new Request(
+ new Columns.All(), new Condition.Equals("id", "id", device.getPositionId()))));
+ }
- if (device.getPositionId() > 0) {
- devicePositions.put(deviceId, storage.getObject(Position.class, new Request(
- new Columns.All(), new Condition.Equals("id", "id", device.getPositionId()))));
+ invalidateDeviceGeofences(device);
}
-
- invalidateDeviceGeofences(device);
}
private void unsafeRemoveDevice(long deviceId) {