aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/events/GeofenceEventHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/events/GeofenceEventHandler.java')
-rw-r--r--src/org/traccar/events/GeofenceEventHandler.java26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java
index fbec932b1..31d82a81e 100644
--- a/src/org/traccar/events/GeofenceEventHandler.java
+++ b/src/org/traccar/events/GeofenceEventHandler.java
@@ -16,12 +16,14 @@
package org.traccar.events;
import java.util.ArrayList;
-import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
import org.traccar.database.GeofenceManager;
+import org.traccar.model.Calendar;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -35,8 +37,8 @@ public class GeofenceEventHandler extends BaseEventHandler {
}
@Override
- protected Collection<Event> analyzePosition(Position position) {
- Device device = Context.getIdentityManager().getDeviceById(position.getDeviceId());
+ protected Map<Event, Position> analyzePosition(Position position) {
+ Device device = Context.getIdentityManager().getById(position.getDeviceId());
if (device == null) {
return null;
}
@@ -55,23 +57,23 @@ public class GeofenceEventHandler extends BaseEventHandler {
device.setGeofenceIds(currentGeofences);
- Collection<Event> events = new ArrayList<>();
+ Map<Event, Position> events = new HashMap<>();
for (long geofenceId : newGeofences) {
- long calendarId = geofenceManager.getGeofence(geofenceId).getCalendarId();
- if (calendarId == 0 || Context.getCalendarManager().getCalendar(calendarId) == null
- || Context.getCalendarManager().getCalendar(calendarId).checkMoment(position.getFixTime())) {
+ long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
+ Calendar calendar = calendarId != 0 ? Context.getCalendarManager().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);
- events.add(event);
+ events.put(event, position);
}
}
for (long geofenceId : oldGeofences) {
- long calendarId = geofenceManager.getGeofence(geofenceId).getCalendarId();
- if (calendarId == 0 || Context.getCalendarManager().getCalendar(calendarId) == null
- || Context.getCalendarManager().getCalendar(calendarId).checkMoment(position.getFixTime())) {
+ long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
+ Calendar calendar = calendarId != 0 ? Context.getCalendarManager().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);
- events.add(event);
+ events.put(event, position);
}
}
return events;