diff options
-rw-r--r-- | src/main/java/org/traccar/Context.java | 6 | ||||
-rw-r--r-- | src/main/java/org/traccar/config/Config.java | 12 | ||||
-rw-r--r-- | src/main/java/org/traccar/config/Keys.java | 19 | ||||
-rw-r--r-- | src/main/java/org/traccar/model/Geofence.java | 3 |
4 files changed, 29 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/Context.java b/src/main/java/org/traccar/Context.java index 2fb6998b8..340cdb6a5 100644 --- a/src/main/java/org/traccar/Context.java +++ b/src/main/java/org/traccar/Context.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2020 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -257,8 +257,8 @@ public final class Context { config.getLong("report.trip.minimalParkingDuration", 300) * 1000, config.getLong("report.trip.minimalNoDataDuration", 3600) * 1000, config.getBoolean("report.trip.useIgnition"), - config.getBoolean("event.motion.processInvalidPositions"), - config.getDouble("event.motion.speedThreshold", 0.01)); + config.getBoolean(Keys.EVENT_MOTION_PROCESS_INVALID_POSITIONS), + config.getDouble(Keys.EVENT_MOTION_SPEED_THRESHOLD, 0.01)); } private static class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> { diff --git a/src/main/java/org/traccar/config/Config.java b/src/main/java/org/traccar/config/Config.java index 77184a528..1231918c6 100644 --- a/src/main/java/org/traccar/config/Config.java +++ b/src/main/java/org/traccar/config/Config.java @@ -15,6 +15,8 @@ */ package org.traccar.config; +import com.google.common.annotations.VisibleForTesting; + import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -133,18 +135,14 @@ public class Config { } public double getDouble(ConfigKey key) { - return getDouble(key.getKey(), 0.0); + return getDouble(key, 0.0); } public double getDouble(ConfigKey key, double defaultValue) { - return getDouble(key.getKey(), defaultValue); - } - - @Deprecated - public double getDouble(String key, double defaultValue) { - return hasKey(key) ? Double.parseDouble(getString(key)) : defaultValue; + return hasKey(key.getKey()) ? Double.parseDouble(getString(key.getKey())) : defaultValue; } + @VisibleForTesting public void setString(ConfigKey key, String value) { properties.put(key.getKey(), value); } diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 206295499..c8d3f4ccc 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -70,6 +70,25 @@ public final class Keys { "event.ignoreDuplicateAlerts", Boolean.class); /** + * If set to true, invalid positions will be considered for motion logic. + */ + public static final ConfigKey EVENT_MOTION_PROCESS_INVALID_POSITIONS = new ConfigKey( + "event.motion.processInvalidPositions", Boolean.class); + + /** + * If the speed is above specified value, the object is considered to be in motion. Default value is 0.01 knots. + */ + public static final ConfigKey EVENT_MOTION_SPEED_THRESHOLD = new ConfigKey( + "event.motion.speedThreshold", Double.class); + + /** + * Global polyline geofence distance. Within that distance from the polyline, point is considered within the + * geofence. Each individual geofence can also has 'polylineDistance' attribute which will take precedence. + */ + public static final ConfigKey GEOFENCE_POLYLINE_DISTANCE = new ConfigKey( + "geofence.polylineDistance", Double.class); + + /** * List of external handler classes to use in Netty pipeline. */ public static final ConfigKey EXTRA_HANDLERS = new ConfigKey( diff --git a/src/main/java/org/traccar/model/Geofence.java b/src/main/java/org/traccar/model/Geofence.java index 8560d22e9..835ea7c22 100644 --- a/src/main/java/org/traccar/model/Geofence.java +++ b/src/main/java/org/traccar/model/Geofence.java @@ -18,6 +18,7 @@ package org.traccar.model; import java.text.ParseException; import org.traccar.Context; +import org.traccar.config.Keys; import org.traccar.database.QueryIgnore; import org.traccar.geofence.GeofenceCircle; import org.traccar.geofence.GeofenceGeometry; @@ -67,7 +68,7 @@ public class Geofence extends ScheduledModel { } else if (area.startsWith("LINESTRING")) { final double distance = getDouble("polylineDistance"); geometry = new GeofencePolyline(area, distance > 0 ? distance - : Context.getConfig().getDouble("geofence.polylineDistance", 25)); + : Context.getConfig().getDouble(Keys.GEOFENCE_POLYLINE_DISTANCE, 25)); } else { throw new ParseException("Unknown geometry type", 0); } |