From c0cbde51aa75a5b2df58b11e76527ee703289541 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 14 Jul 2017 11:59:31 +0500 Subject: Implement driverChanged event instead of driverUnauthorized --- src/org/traccar/database/DriversManager.java | 16 ---------------- src/org/traccar/events/DriverEventHandler.java | 19 +++++-------------- src/org/traccar/model/Event.java | 2 +- 3 files changed, 6 insertions(+), 31 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java index cba2e14c1..e89d59311 100644 --- a/src/org/traccar/database/DriversManager.java +++ b/src/org/traccar/database/DriversManager.java @@ -210,20 +210,4 @@ public class DriversManager { } return drivers; } - - public final boolean authorizeDriverByUniqueId(String driverUniqueId, long deviceId) { - if (driversByUniqueId.containsKey(driverUniqueId)) { - long chekingDriverId = getDriverByUniqueId(driverUniqueId).getId(); - Set deviceDrivers = getAllDeviceDrivers(deviceId); - if (deviceDrivers.isEmpty()) { - return true; - } - for (long driverId : deviceDrivers) { - if (chekingDriverId == driverId) { - return true; - } - } - } - return false; - } } diff --git a/src/org/traccar/events/DriverEventHandler.java b/src/org/traccar/events/DriverEventHandler.java index 9109373c7..eb5f2a301 100644 --- a/src/org/traccar/events/DriverEventHandler.java +++ b/src/org/traccar/events/DriverEventHandler.java @@ -26,12 +26,6 @@ import org.traccar.model.Position; public class DriverEventHandler extends BaseEventHandler { - private boolean notRepeat; - - public DriverEventHandler() { - notRepeat = Context.getConfig().getBoolean("event.driver.notRepeat"); - } - @Override protected Collection analyzePosition(Position position) { if (!Context.getIdentityManager().isLatestPosition(position)) { @@ -40,15 +34,12 @@ public class DriverEventHandler extends BaseEventHandler { String driverUniqueId = position.getString(Position.KEY_DRIVER_UNIQUE_ID); if (driverUniqueId != null) { String oldDriverUniqueId = null; - if (notRepeat) { - Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); - if (lastPosition != null) { - oldDriverUniqueId = lastPosition.getString(Position.KEY_DRIVER_UNIQUE_ID); - } + Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); + if (lastPosition != null) { + oldDriverUniqueId = lastPosition.getString(Position.KEY_DRIVER_UNIQUE_ID); } - if (!driverUniqueId.equals(oldDriverUniqueId) - && !Context.getDriversManager().authorizeDriverByUniqueId(driverUniqueId, position.getDeviceId())) { - Event event = new Event(Event.TYPE_DRIVER_UNAUTHORIZED, position.getDeviceId(), position.getId()); + if (!driverUniqueId.equals(oldDriverUniqueId)) { + Event event = new Event(Event.TYPE_DRIVER_CHANGED, position.getDeviceId(), position.getId()); event.set(Position.KEY_DRIVER_UNIQUE_ID, driverUniqueId); return Collections.singleton(event); } diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java index dd5358f75..2d836abeb 100644 --- a/src/org/traccar/model/Event.java +++ b/src/org/traccar/model/Event.java @@ -61,7 +61,7 @@ public class Event extends Message { public static final String TYPE_TEXT_MESSAGE = "textMessage"; - public static final String TYPE_DRIVER_UNAUTHORIZED = "driverUnauthorized"; + public static final String TYPE_DRIVER_CHANGED = "driverChanged"; private Date serverTime; -- cgit v1.2.3