aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-05-09 07:51:41 -0700
committerAnton Tananaev <anton@traccar.org>2023-05-09 07:51:41 -0700
commit1e8c232e37d0f041a8518cb4790322965bdd6fd5 (patch)
tree196e337fe5be996a2412cf261d0788e3afe46169 /src
parent680fe003a7cc9da354a989936d8f7f07580110bb (diff)
downloadtrackermap-server-1e8c232e37d0f041a8518cb4790322965bdd6fd5.tar.gz
trackermap-server-1e8c232e37d0f041a8518cb4790322965bdd6fd5.tar.bz2
trackermap-server-1e8c232e37d0f041a8518cb4790322965bdd6fd5.zip
Handle missing geofences
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/handler/events/GeofenceEventHandler.java27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
index 0ab9ca217..096f71373 100644
--- a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
@@ -16,15 +16,12 @@
package org.traccar.handler.events;
import io.netty.channel.ChannelHandler;
-import org.traccar.config.Config;
import org.traccar.helper.model.PositionUtil;
import org.traccar.model.Calendar;
import org.traccar.model.Event;
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 javax.inject.Inject;
import javax.inject.Singleton;
@@ -37,18 +34,11 @@ import java.util.Map;
@ChannelHandler.Sharable
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, Storage storage) {
- this.config = config;
+ public GeofenceEventHandler(CacheManager cacheManager) {
this.cacheManager = cacheManager;
- this.connectionManager = connectionManager;
- this.storage = storage;
}
@Override
@@ -72,12 +62,15 @@ public class GeofenceEventHandler extends BaseEventHandler {
Map<Event, Position> events = new HashMap<>();
for (long geofenceId : oldGeofences) {
- long calendarId = cacheManager.getObject(Geofence.class, geofenceId).getCalendarId();
- Calendar calendar = calendarId != 0 ? cacheManager.getObject(Calendar.class, calendarId) : null;
- if (calendar == null || calendar.checkMoment(position.getFixTime())) {
- Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position);
- event.setGeofenceId(geofenceId);
- events.put(event, position);
+ Geofence geofence = cacheManager.getObject(Geofence.class, geofenceId);
+ if (geofence != null) {
+ long calendarId = geofence.getCalendarId();
+ Calendar calendar = calendarId != 0 ? cacheManager.getObject(Calendar.class, calendarId) : null;
+ if (calendar == null || calendar.checkMoment(position.getFixTime())) {
+ Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position);
+ event.setGeofenceId(geofenceId);
+ events.put(event, position);
+ }
}
}
for (long geofenceId : newGeofences) {