aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-09-15 23:13:16 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-09-15 23:13:16 -0700
commit4fb9eba760b571d86fff4c1b0f645a7c6d4fbe16 (patch)
treeccd214a66b56dc72dd07a8fb2d8b95e9856329f9
parent1a40dfa1fc286f03ab4ce4468984a226e68afe0c (diff)
downloadtraccar-server-4fb9eba760b571d86fff4c1b0f645a7c6d4fbe16.tar.gz
traccar-server-4fb9eba760b571d86fff4c1b0f645a7c6d4fbe16.tar.bz2
traccar-server-4fb9eba760b571d86fff4c1b0f645a7c6d4fbe16.zip
Update when geofences change
-rw-r--r--src/main/java/org/traccar/MainModule.java11
-rw-r--r--src/main/java/org/traccar/handler/events/GeofenceEventHandler.java11
2 files changed, 18 insertions, 4 deletions
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;
@@ -106,6 +107,11 @@ public class MainModule extends AbstractModule {
}
@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<Event, Position> events = new HashMap<>();
for (long geofenceId : oldGeofences) {