diff options
author | Abyss777 <abyss@fox5.ru> | 2016-07-26 14:50:32 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2016-07-26 14:50:32 +0500 |
commit | 60c442ac19776f0e07fafd1db8a0b75f971fd40e (patch) | |
tree | c3a2c6f4264c48a19ef8f27de95208fbd6280363 /src | |
parent | 914abce63e9f85d13d0b6ee53ea55eb70643d71e (diff) | |
download | trackermap-server-60c442ac19776f0e07fafd1db8a0b75f971fd40e.tar.gz trackermap-server-60c442ac19776f0e07fafd1db8a0b75f971fd40e.tar.bz2 trackermap-server-60c442ac19776f0e07fafd1db8a0b75f971fd40e.zip |
Overspeed handler enhanced to use attributes
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/events/OverspeedEventHandler.java | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index 6c9b523f4..b2b1aeb5f 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -24,16 +24,19 @@ import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; +import org.traccar.model.Server; import org.traccar.helper.Log; import org.traccar.helper.UnitsConverter; public class OverspeedEventHandler extends BaseEventHandler { - private double globalSpeedLimit; + public static final String ATTRIBUTE_SPEED_LIMIT = "speedLimit"; + + private boolean checkGroups; private int suppressRepeated; public OverspeedEventHandler() { - globalSpeedLimit = UnitsConverter.knotsFromKph(Context.getConfig().getInteger("event.globalSpeedLimit", 0)); + checkGroups = Context.getConfig().getBoolean("event.overspeed.groupsEnabled"); suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60); } @@ -50,8 +53,40 @@ public class OverspeedEventHandler extends BaseEventHandler { Collection<Event> events = new ArrayList<>(); double speed = position.getSpeed(); + Double speedLimit = new Double(0); - if (globalSpeedLimit != 0 && speed > globalSpeedLimit) { + if (device.getAttributes().containsKey(ATTRIBUTE_SPEED_LIMIT)) { + speedLimit = Double.parseDouble((String) device.getAttributes().get(ATTRIBUTE_SPEED_LIMIT)); + } + if (speedLimit == 0 && checkGroups) { + long groupId = device.getGroupId(); + while (groupId != 0) { + if (Context.getDeviceManager().getGroupById(groupId).getAttributes() + .containsKey(ATTRIBUTE_SPEED_LIMIT)) { + speedLimit = Double.parseDouble((String) Context.getDeviceManager().getGroupById(groupId) + .getAttributes().get(ATTRIBUTE_SPEED_LIMIT)); + if (speedLimit != 0) { + break; + } + } + if (Context.getDeviceManager().getGroupById(groupId) != null) { + groupId = Context.getDeviceManager().getGroupById(groupId).getGroupId(); + } else { + groupId = 0; + } + } + } + if (speedLimit == 0) { + try { + Server server = Context.getDataManager().getServer(); + if (server.getAttributes().containsKey(ATTRIBUTE_SPEED_LIMIT)) { + speedLimit = Double.parseDouble((String) server.getAttributes().get(ATTRIBUTE_SPEED_LIMIT)); + } + } catch (SQLException error) { + Log.warning(error); + } + } + if (speedLimit != 0 && speed > UnitsConverter.knotsFromKph(speedLimit)) { try { if (Context.getDataManager().getLastEvents( position.getDeviceId(), Event.TYPE_DEVICE_OVERSPEED, suppressRepeated).isEmpty()) { |