diff options
author | Anton Tananaev <anton@traccar.org> | 2022-07-12 17:31:36 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-07-12 17:31:36 -0700 |
commit | 493ff1068ea3e4d96f2475234b265b47cce8691f (patch) | |
tree | 6de7dbc5ac202ba576bc04ecf45dab751aee7bfd /src/main/java/org/traccar/handler | |
parent | 98e2db95f73cb85a2623e2902741bcb4e73683e5 (diff) | |
download | trackermap-server-493ff1068ea3e4d96f2475234b265b47cce8691f.tar.gz trackermap-server-493ff1068ea3e4d96f2475234b265b47cce8691f.tar.bz2 trackermap-server-493ff1068ea3e4d96f2475234b265b47cce8691f.zip |
Persist device status (fix #4890, fix #4891)
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r-- | src/main/java/org/traccar/handler/events/GeofenceEventHandler.java | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java index ca3fc3f89..70bdb84cb 100644 --- a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java +++ b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java @@ -26,6 +26,11 @@ import org.traccar.model.Geofence; import org.traccar.model.Position; import org.traccar.session.ConnectionManager; import org.traccar.session.cache.CacheManager; +import org.traccar.storage.Storage; +import org.traccar.storage.StorageException; +import org.traccar.storage.query.Columns; +import org.traccar.storage.query.Condition; +import org.traccar.storage.query.Request; import javax.inject.Inject; import java.util.ArrayList; @@ -39,12 +44,15 @@ public class GeofenceEventHandler extends BaseEventHandler { private final Config config; private final CacheManager cacheManager; private final ConnectionManager connectionManager; + private final Storage storage; @Inject - public GeofenceEventHandler(Config config, CacheManager cacheManager, ConnectionManager connectionManager) { + public GeofenceEventHandler( + Config config, CacheManager cacheManager, ConnectionManager connectionManager, Storage storage) { this.config = config; this.cacheManager = cacheManager; this.connectionManager = connectionManager; + this.storage = storage; } @Override @@ -66,8 +74,17 @@ public class GeofenceEventHandler extends BaseEventHandler { newGeofences.removeAll(oldGeofences); oldGeofences.removeAll(currentGeofences); - device.setGeofenceIds(currentGeofences); + if (!oldGeofences.isEmpty() || !newGeofences.isEmpty()) { + device.setGeofenceIds(currentGeofences.isEmpty() ? null : currentGeofences); + + try { + storage.updateObject(device, new Request( + new Columns.Include("geofenceIds"), new Condition.Equals("id", "id"))); + } catch (StorageException e) { + throw new RuntimeException("Update device geofences error", e); + } + connectionManager.updateDevice(true, device); } |