From 4fb9eba760b571d86fff4c1b0f645a7c6d4fbe16 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 15 Sep 2021 23:13:16 -0700 Subject: Update when geofences change --- src/main/java/org/traccar/MainModule.java | 11 +++++++++-- .../java/org/traccar/handler/events/GeofenceEventHandler.java | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index 80baebeee..11100f66e 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -23,6 +23,7 @@ import org.traccar.config.Config; import org.traccar.config.Keys; import org.traccar.database.AttributesManager; import org.traccar.database.CalendarManager; +import org.traccar.database.ConnectionManager; import org.traccar.database.DataManager; import org.traccar.database.DeviceManager; import org.traccar.database.GeofenceManager; @@ -105,6 +106,11 @@ public class MainModule extends AbstractModule { return Context.getIdentityManager(); } + @Provides + public static ConnectionManager provideConnectionManager() { + return Context.getConnectionManager(); + } + @Provides public static Client provideClient() { return Context.getClient(); @@ -393,8 +399,9 @@ public class MainModule extends AbstractModule { @Singleton @Provides public static GeofenceEventHandler provideGeofenceEventHandler( - IdentityManager identityManager, GeofenceManager geofenceManager, CalendarManager calendarManager) { - return new GeofenceEventHandler(identityManager, geofenceManager, calendarManager); + IdentityManager identityManager, GeofenceManager geofenceManager, CalendarManager calendarManager, + ConnectionManager connectionManager) { + return new GeofenceEventHandler(identityManager, geofenceManager, calendarManager, connectionManager); } @Singleton diff --git a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java index f4807e56b..dae0c891f 100644 --- a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java +++ b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2021 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import java.util.Map; import io.netty.channel.ChannelHandler; import org.traccar.database.CalendarManager; +import org.traccar.database.ConnectionManager; import org.traccar.database.GeofenceManager; import org.traccar.database.IdentityManager; import org.traccar.model.Calendar; @@ -35,12 +36,15 @@ public class GeofenceEventHandler extends BaseEventHandler { private final IdentityManager identityManager; private final GeofenceManager geofenceManager; private final CalendarManager calendarManager; + private final ConnectionManager connectionManager; public GeofenceEventHandler( - IdentityManager identityManager, GeofenceManager geofenceManager, CalendarManager calendarManager) { + IdentityManager identityManager, GeofenceManager geofenceManager, CalendarManager calendarManager, + ConnectionManager connectionManager) { this.identityManager = identityManager; this.geofenceManager = geofenceManager; this.calendarManager = calendarManager; + this.connectionManager = connectionManager; } @Override @@ -63,6 +67,9 @@ public class GeofenceEventHandler extends BaseEventHandler { oldGeofences.removeAll(currentGeofences); device.setGeofenceIds(currentGeofences); + if (!oldGeofences.isEmpty() || !newGeofences.isEmpty()) { + connectionManager.updateDevice(device); + } Map events = new HashMap<>(); for (long geofenceId : oldGeofences) { -- cgit v1.2.3