diff options
Diffstat (limited to 'src/main/java/org/traccar/handler')
4 files changed, 25 insertions, 19 deletions
diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java index 4293bd1fc..d286866a5 100644 --- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java +++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java @@ -35,12 +35,14 @@ import org.traccar.session.cache.CacheManager; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Date; +import java.util.stream.Collectors; public class ComputedAttributesHandler extends BasePositionHandler { @@ -63,7 +65,7 @@ public class ComputedAttributesHandler extends BasePositionHandler { sandbox.allow(Math.class.getName()); List.of( Double.class, Float.class, Integer.class, Long.class, Short.class, - Character.class, Boolean.class, String.class, Byte.class) + Character.class, Boolean.class, String.class, Byte.class, Date.class) .forEach((type) -> sandbox.allow(type.getName())); features = new JexlFeatures() .localVar(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LOCAL_VARIABLES)) @@ -139,7 +141,9 @@ public class ComputedAttributesHandler extends BasePositionHandler { @Override public void handlePosition(Position position, Callback callback) { - Collection<Attribute> attributes = cacheManager.getDeviceObjects(position.getDeviceId(), Attribute.class); + var attributes = cacheManager.getDeviceObjects(position.getDeviceId(), Attribute.class).stream() + .sorted(Comparator.comparing(Attribute::getPriority).reversed()) + .collect(Collectors.toUnmodifiableList()); for (Attribute attribute : attributes) { if (attribute.getAttribute() != null) { Object result = null; diff --git a/src/main/java/org/traccar/handler/DatabaseHandler.java b/src/main/java/org/traccar/handler/DatabaseHandler.java index 5d96ebb34..4619e9d34 100644 --- a/src/main/java/org/traccar/handler/DatabaseHandler.java +++ b/src/main/java/org/traccar/handler/DatabaseHandler.java @@ -42,7 +42,7 @@ public class DatabaseHandler extends BasePositionHandler { try { position.setId(storage.addObject(position, new Request(new Columns.Exclude("id")))); - statisticsManager.messageStoredCount(position.getDeviceId()); + statisticsManager.registerMessageStored(position.getDeviceId(), position.getProtocol()); } catch (Exception error) { LOGGER.warn("Failed to store position", error); } diff --git a/src/main/java/org/traccar/handler/FilterHandler.java b/src/main/java/org/traccar/handler/FilterHandler.java index 796c302fb..700fdbc13 100644 --- a/src/main/java/org/traccar/handler/FilterHandler.java +++ b/src/main/java/org/traccar/handler/FilterHandler.java @@ -53,6 +53,7 @@ public class FilterHandler extends BasePositionHandler { private final int filterMaxSpeed; private final long filterMinPeriod; private final int filterDailyLimit; + private final long filterDailyLimitInterval; private final boolean filterRelative; private final long skipLimit; private final boolean skipAttributes; @@ -77,6 +78,7 @@ public class FilterHandler extends BasePositionHandler { filterMaxSpeed = config.getInteger(Keys.FILTER_MAX_SPEED); filterMinPeriod = config.getInteger(Keys.FILTER_MIN_PERIOD) * 1000L; filterDailyLimit = config.getInteger(Keys.FILTER_DAILY_LIMIT); + filterDailyLimitInterval = config.getInteger(Keys.FILTER_DAILY_LIMIT_INTERVAL) * 1000L; filterRelative = config.getBoolean(Keys.FILTER_RELATIVE); skipLimit = config.getLong(Keys.FILTER_SKIP_LIMIT) * 1000; skipAttributes = config.getBoolean(Keys.FILTER_SKIP_ATTRIBUTES_ENABLE); @@ -151,7 +153,7 @@ public class FilterHandler extends BasePositionHandler { if (filterMaxSpeed != 0 && last != null) { double distance = position.getDouble(Position.KEY_DISTANCE); double time = position.getFixTime().getTime() - last.getFixTime().getTime(); - return UnitsConverter.knotsFromMps(distance / (time / 1000)) > filterMaxSpeed; + return time > 0 && UnitsConverter.knotsFromMps(distance / (time / 1000)) > filterMaxSpeed; } return false; } @@ -164,9 +166,12 @@ public class FilterHandler extends BasePositionHandler { return false; } - private boolean filterDailyLimit(Position position) { - if (filterDailyLimit != 0) { - return statisticsManager.messageStoredCount(position.getDeviceId()) >= filterDailyLimit; + private boolean filterDailyLimit(Position position, Position last) { + if (filterDailyLimit != 0 + && statisticsManager.messageStoredCount(position.getDeviceId()) >= filterDailyLimit) { + long lastTime = last != null ? last.getFixTime().getTime() : 0; + long interval = position.getFixTime().getTime() - lastTime; + return filterDailyLimitInterval <= 0 || interval < filterDailyLimitInterval; } return false; } @@ -216,20 +221,18 @@ public class FilterHandler extends BasePositionHandler { if (filterApproximate(position)) { filterType.append("Approximate "); } - if (filterDailyLimit(position)) { - filterType.append("DailyLimit "); - } // filter out excessive data long deviceId = position.getDeviceId(); - if (filterDuplicate || filterStatic || filterDistance > 0 || filterMaxSpeed > 0 || filterMinPeriod > 0) { - Position preceding = null; + if (filterDuplicate || filterStatic + || filterDistance > 0 || filterMaxSpeed > 0 || filterMinPeriod > 0 || filterDailyLimit > 0) { + Position preceding; if (filterRelative) { try { Date newFixTime = position.getFixTime(); preceding = getPrecedingPosition(deviceId, newFixTime); } catch (StorageException e) { - LOGGER.warn("Error retrieving preceding position; fallbacking to last received position.", e); + LOGGER.warn("Error retrieving preceding position; fall backing to last received position.", e); preceding = cacheManager.getPosition(deviceId); } } else { @@ -250,6 +253,9 @@ public class FilterHandler extends BasePositionHandler { if (filterMinPeriod(position, preceding)) { filterType.append("MinPeriod "); } + if (filterDailyLimit(position, preceding)) { + filterType.append("DailyLimit "); + } } Device device = cacheManager.getObject(Device.class, deviceId); diff --git a/src/main/java/org/traccar/handler/GeocoderHandler.java b/src/main/java/org/traccar/handler/GeocoderHandler.java index b84237856..3744700da 100644 --- a/src/main/java/org/traccar/handler/GeocoderHandler.java +++ b/src/main/java/org/traccar/handler/GeocoderHandler.java @@ -43,11 +43,7 @@ public class GeocoderHandler extends BasePositionHandler { @Override public void handlePosition(Position position, Callback callback) { - if (!ignorePositions) { - callback.processed(false); - } - - if (processInvalidPositions || position.getValid()) { + if (!ignorePositions && (processInvalidPositions || position.getValid())) { if (reuseDistance != 0) { Position lastPosition = cacheManager.getPosition(position.getDeviceId()); if (lastPosition != null && lastPosition.getAddress() != null |