diff options
author | Abyss777 <abyss@fox5.ru> | 2017-07-14 11:59:31 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2017-07-14 11:59:31 +0500 |
commit | c0cbde51aa75a5b2df58b11e76527ee703289541 (patch) | |
tree | 394e18d9e36c1423843de01a88e290a4d25e099c | |
parent | 9949cadcdf3f07a4590742e2f0303d82efb653f9 (diff) | |
download | trackermap-server-c0cbde51aa75a5b2df58b11e76527ee703289541.tar.gz trackermap-server-c0cbde51aa75a5b2df58b11e76527ee703289541.tar.bz2 trackermap-server-c0cbde51aa75a5b2df58b11e76527ee703289541.zip |
Implement driverChanged event instead of driverUnauthorized
-rw-r--r-- | setup/default.xml | 2 | ||||
-rw-r--r-- | src/org/traccar/database/DriversManager.java | 16 | ||||
-rw-r--r-- | src/org/traccar/events/DriverEventHandler.java | 19 | ||||
-rw-r--r-- | src/org/traccar/model/Event.java | 2 | ||||
-rw-r--r-- | templates/mail/driverChanged.vm (renamed from templates/mail/driverUnauthorized.vm) | 2 | ||||
-rw-r--r-- | templates/sms/driverChanged.vm | 6 | ||||
-rw-r--r-- | templates/sms/driverUnauthorized.vm | 6 |
7 files changed, 14 insertions, 39 deletions
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 </entry> - <entry key='database.selectDriverPermissions'> + <entry key='database.selectDriverPermissions'> SELECT userId, driverId FROM user_driver </entry> 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<Long> 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<Event> 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/driverUnauthorized.vm b/templates/mail/driverChanged.vm index 3d28266cd..ba1e68661 100644 --- a/templates/mail/driverUnauthorized.vm +++ b/templates/mail/driverChanged.vm @@ -1,4 +1,4 @@ -#set($subject = "$device.name: driver unauthorized") +#set($subject = "$device.name: driver has changed") <!DOCTYPE html> <html> <body> 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) |