aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r--src/main/java/org/traccar/handler/FilterHandler.java9
-rw-r--r--src/main/java/org/traccar/handler/GeofenceHandler.java52
-rw-r--r--src/main/java/org/traccar/handler/events/GeofenceEventHandler.java41
-rw-r--r--src/main/java/org/traccar/handler/events/OverspeedEventHandler.java4
4 files changed, 73 insertions, 33 deletions
diff --git a/src/main/java/org/traccar/handler/FilterHandler.java b/src/main/java/org/traccar/handler/FilterHandler.java
index 1d1c27b7a..9ff94deb0 100644
--- a/src/main/java/org/traccar/handler/FilterHandler.java
+++ b/src/main/java/org/traccar/handler/FilterHandler.java
@@ -48,6 +48,7 @@ public class FilterHandler extends ChannelInboundHandlerAdapter {
private final boolean filterInvalid;
private final boolean filterZero;
private final boolean filterDuplicate;
+ private final boolean filterOutdated;
private final long filterFuture;
private final long filterPast;
private final boolean filterApproximate;
@@ -69,6 +70,7 @@ public class FilterHandler extends ChannelInboundHandlerAdapter {
filterInvalid = config.getBoolean(Keys.FILTER_INVALID);
filterZero = config.getBoolean(Keys.FILTER_ZERO);
filterDuplicate = config.getBoolean(Keys.FILTER_DUPLICATE);
+ filterOutdated = config.getBoolean(Keys.FILTER_OUTDATED);
filterFuture = config.getLong(Keys.FILTER_FUTURE) * 1000;
filterPast = config.getLong(Keys.FILTER_PAST) * 1000;
filterAccuracy = config.getInteger(Keys.FILTER_ACCURACY);
@@ -115,6 +117,10 @@ public class FilterHandler extends ChannelInboundHandlerAdapter {
return false;
}
+ private boolean filterOutdated(Position position) {
+ return filterOutdated && position.getOutdated();
+ }
+
private boolean filterFuture(Position position) {
return filterFuture != 0 && position.getFixTime().getTime() > System.currentTimeMillis() + filterFuture;
}
@@ -189,6 +195,9 @@ public class FilterHandler extends ChannelInboundHandlerAdapter {
if (filterZero(position)) {
filterType.append("Zero ");
}
+ if (filterOutdated(position)) {
+ filterType.append("Outdated ");
+ }
if (filterFuture(position)) {
filterType.append("Future ");
}
diff --git a/src/main/java/org/traccar/handler/GeofenceHandler.java b/src/main/java/org/traccar/handler/GeofenceHandler.java
new file mode 100644
index 000000000..fe15cef8e
--- /dev/null
+++ b/src/main/java/org/traccar/handler/GeofenceHandler.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.handler;
+
+import io.netty.channel.ChannelHandler;
+import org.traccar.BaseDataHandler;
+import org.traccar.config.Config;
+import org.traccar.helper.model.GeofenceUtil;
+import org.traccar.model.Position;
+import org.traccar.session.cache.CacheManager;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import java.util.List;
+
+@Singleton
+@ChannelHandler.Sharable
+public class GeofenceHandler extends BaseDataHandler {
+
+ private final Config config;
+ private final CacheManager cacheManager;
+
+ @Inject
+ public GeofenceHandler(Config config, CacheManager cacheManager) {
+ this.config = config;
+ this.cacheManager = cacheManager;
+ }
+
+ @Override
+ protected Position handlePosition(Position position) {
+
+ List<Long> geofenceIds = GeofenceUtil.getCurrentGeofences(config, cacheManager, position);
+ if (!geofenceIds.isEmpty()) {
+ position.setGeofenceIds(geofenceIds);
+ }
+ return position;
+ }
+
+}
diff --git a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
index 9414f4b31..0ab9ca217 100644
--- a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2023 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.
@@ -17,20 +17,14 @@ package org.traccar.handler.events;
import io.netty.channel.ChannelHandler;
import org.traccar.config.Config;
-import org.traccar.helper.model.GeofenceUtil;
import org.traccar.helper.model.PositionUtil;
import org.traccar.model.Calendar;
-import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Geofence;
import org.traccar.model.Position;
import org.traccar.session.ConnectionManager;
import org.traccar.session.cache.CacheManager;
import org.traccar.storage.Storage;
-import org.traccar.storage.StorageException;
-import org.traccar.storage.query.Columns;
-import org.traccar.storage.query.Condition;
-import org.traccar.storage.query.Request;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -59,36 +53,21 @@ public class GeofenceEventHandler extends BaseEventHandler {
@Override
protected Map<Event, Position> analyzePosition(Position position) {
- Device device = cacheManager.getObject(Device.class, position.getDeviceId());
- if (device == null) {
- return null;
- }
- if (!PositionUtil.isLatest(cacheManager, position) || !position.getValid()) {
+ if (!PositionUtil.isLatest(cacheManager, position)) {
return null;
}
- List<Long> currentGeofences = GeofenceUtil.getCurrentGeofences(config, cacheManager, position);
List<Long> oldGeofences = new ArrayList<>();
- if (device.getGeofenceIds() != null) {
- oldGeofences.addAll(device.getGeofenceIds());
+ Position lastPosition = cacheManager.getPosition(position.getDeviceId());
+ if (lastPosition != null && lastPosition.getGeofenceIds() != null) {
+ oldGeofences.addAll(lastPosition.getGeofenceIds());
}
- List<Long> newGeofences = new ArrayList<>(currentGeofences);
- newGeofences.removeAll(oldGeofences);
- oldGeofences.removeAll(currentGeofences);
-
-
- if (!oldGeofences.isEmpty() || !newGeofences.isEmpty()) {
- device.setGeofenceIds(currentGeofences.isEmpty() ? null : currentGeofences);
-
- try {
- storage.updateObject(device, new Request(
- new Columns.Include("geofenceIds"),
- new Condition.Equals("id", device.getId())));
- } catch (StorageException e) {
- throw new RuntimeException("Update device geofences error", e);
- }
- connectionManager.updateDevice(true, device);
+ List<Long> newGeofences = new ArrayList<>();
+ if (position.getGeofenceIds() != null) {
+ newGeofences.addAll(position.getGeofenceIds());
+ newGeofences.removeAll(oldGeofences);
+ oldGeofences.removeAll(position.getGeofenceIds());
}
Map<Event, Position> events = new HashMap<>();
diff --git a/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java b/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java
index 4d6aa8857..40f1c7442 100644
--- a/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java
@@ -84,8 +84,8 @@ public class OverspeedEventHandler extends BaseEventHandler {
double geofenceSpeedLimit = 0;
long overspeedGeofenceId = 0;
- if (device.getGeofenceIds() != null) {
- for (long geofenceId : device.getGeofenceIds()) {
+ if (position.getGeofenceIds() != null) {
+ for (long geofenceId : position.getGeofenceIds()) {
Geofence geofence = cacheManager.getObject(Geofence.class, geofenceId);
if (geofence != null) {
double currentSpeedLimit = geofence.getDouble(Keys.EVENT_OVERSPEED_LIMIT.getKey());