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 --- setup/default.xml | 2 +- src/org/traccar/database/DriversManager.java | 16 ---------------- src/org/traccar/events/DriverEventHandler.java | 19 +++++-------------- src/org/traccar/model/Event.java | 2 +- templates/mail/driverChanged.vm | 10 ++++++++++ templates/mail/driverUnauthorized.vm | 10 ---------- templates/sms/driverChanged.vm | 6 ++++++ templates/sms/driverUnauthorized.vm | 6 ------ 8 files changed, 23 insertions(+), 48 deletions(-) create mode 100644 templates/mail/driverChanged.vm delete mode 100644 templates/mail/driverUnauthorized.vm create mode 100644 templates/sms/driverChanged.vm delete mode 100644 templates/sms/driverUnauthorized.vm diff --git a/setup/default.xml b/setup/default.xml index 4a408bf30..04530104a 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -452,7 +452,7 @@ DELETE FROM drivers WHERE id = :id - + SELECT userId, driverId FROM user_driver 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; diff --git a/templates/mail/driverChanged.vm b/templates/mail/driverChanged.vm new file mode 100644 index 000000000..ba1e68661 --- /dev/null +++ b/templates/mail/driverChanged.vm @@ -0,0 +1,10 @@ +#set($subject = "$device.name: driver has changed") + + + +Device: $device.name
+Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.serverTime, $locale, $timezone)
+Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
+Driver: #{if}($driver)$driver.name#{else}$event.getString("driverUniqueId")#{end} + + diff --git a/templates/mail/driverUnauthorized.vm b/templates/mail/driverUnauthorized.vm deleted file mode 100644 index 3d28266cd..000000000 --- a/templates/mail/driverUnauthorized.vm +++ /dev/null @@ -1,10 +0,0 @@ -#set($subject = "$device.name: driver unauthorized") - - - -Device: $device.name
-Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.serverTime, $locale, $timezone)
-Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
-Driver: #{if}($driver)$driver.name#{else}$event.getString("driverUniqueId")#{end} - - diff --git a/templates/sms/driverChanged.vm b/templates/sms/driverChanged.vm new file mode 100644 index 000000000..50849df7c --- /dev/null +++ b/templates/sms/driverChanged.vm @@ -0,0 +1,6 @@ +#if($driver) +#set($driverName = $driver.name) +#else +#set($driverName = $event.getString("driverUniqueId")) +#end +Driver $driverName has changed in $device.name at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.serverTime, $locale, $timezone) diff --git a/templates/sms/driverUnauthorized.vm b/templates/sms/driverUnauthorized.vm deleted file mode 100644 index 52c819eb8..000000000 --- a/templates/sms/driverUnauthorized.vm +++ /dev/null @@ -1,6 +0,0 @@ -#if($driver) -#set($driverName = $driver.name) -#else -#set($driverName = $event.getString("driverUniqueId")) -#end -$driverName is unauthorized for $device.name at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.serverTime, $locale, $timezone) -- cgit v1.2.3