diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-09 16:11:16 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-09 16:11:16 -0800 |
commit | addbd4b58d959a7996af7631dd3449ac779b027f (patch) | |
tree | a1814e463c07a93c359986d1e25db83df2f695b7 /src/org/traccar/handler/events | |
parent | e3668177e4cb989b596ed7b2eef71eb348860736 (diff) | |
download | trackermap-server-addbd4b58d959a7996af7631dd3449ac779b027f.tar.gz trackermap-server-addbd4b58d959a7996af7631dd3449ac779b027f.tar.bz2 trackermap-server-addbd4b58d959a7996af7631dd3449ac779b027f.zip |
Refactor geofence event handler
Diffstat (limited to 'src/org/traccar/handler/events')
-rw-r--r-- | src/org/traccar/handler/events/GeofenceEventHandler.java | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/org/traccar/handler/events/GeofenceEventHandler.java b/src/org/traccar/handler/events/GeofenceEventHandler.java index 878331c84..067c97957 100644 --- a/src/org/traccar/handler/events/GeofenceEventHandler.java +++ b/src/org/traccar/handler/events/GeofenceEventHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2019 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. @@ -21,8 +21,9 @@ import java.util.List; import java.util.Map; import io.netty.channel.ChannelHandler; -import org.traccar.Context; +import org.traccar.database.CalendarManager; import org.traccar.database.GeofenceManager; +import org.traccar.database.IdentityManager; import org.traccar.model.Calendar; import org.traccar.model.Device; import org.traccar.model.Event; @@ -31,19 +32,24 @@ import org.traccar.model.Position; @ChannelHandler.Sharable public class GeofenceEventHandler extends BaseEventHandler { - private GeofenceManager geofenceManager; + private final IdentityManager identityManager; + private final GeofenceManager geofenceManager; + private final CalendarManager calendarManager; - public GeofenceEventHandler() { - geofenceManager = Context.getGeofenceManager(); + public GeofenceEventHandler( + IdentityManager identityManager, GeofenceManager geofenceManager, CalendarManager calendarManager) { + this.identityManager = identityManager; + this.geofenceManager = geofenceManager; + this.calendarManager = calendarManager; } @Override protected Map<Event, Position> analyzePosition(Position position) { - Device device = Context.getIdentityManager().getById(position.getDeviceId()); + Device device = identityManager.getById(position.getDeviceId()); if (device == null) { return null; } - if (!Context.getIdentityManager().isLatestPosition(position) || !position.getValid()) { + if (!identityManager.isLatestPosition(position) || !position.getValid()) { return null; } @@ -61,7 +67,7 @@ public class GeofenceEventHandler extends BaseEventHandler { Map<Event, Position> events = new HashMap<>(); for (long geofenceId : oldGeofences) { long calendarId = geofenceManager.getById(geofenceId).getCalendarId(); - Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null; + Calendar calendar = calendarId != 0 ? calendarManager.getById(calendarId) : null; if (calendar == null || calendar.checkMoment(position.getFixTime())) { Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId()); event.setGeofenceId(geofenceId); @@ -70,7 +76,7 @@ public class GeofenceEventHandler extends BaseEventHandler { } for (long geofenceId : newGeofences) { long calendarId = geofenceManager.getById(geofenceId).getCalendarId(); - Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null; + Calendar calendar = calendarId != 0 ? calendarManager.getById(calendarId) : null; if (calendar == null || calendar.checkMoment(position.getFixTime())) { Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId()); event.setGeofenceId(geofenceId); @@ -79,4 +85,5 @@ public class GeofenceEventHandler extends BaseEventHandler { } return events; } + } |