aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debug.xml106
-rw-r--r--setup/docker/Dockerfile2
-rw-r--r--src/org/traccar/FilterHandler.java102
-rw-r--r--test/org/traccar/FilterHandlerTest.java12
4 files changed, 138 insertions, 84 deletions
diff --git a/debug.xml b/debug.xml
index 3afe59253..ad9e346c1 100644
--- a/debug.xml
+++ b/debug.xml
@@ -97,7 +97,7 @@
<entry key='database.positionsHistoryDays'>7</entry>
<entry key='database.selectServers'>
- SELECT * FROM server;
+ SELECT * FROM server
</entry>
<entry key='database.updateServer'>
@@ -114,21 +114,21 @@
zoom = :zoom,
twelveHourFormat = :twelveHourFormat,
attributes = :attributes
- WHERE id = :id;
+ WHERE id = :id
</entry>
<entry key='database.loginUser'>
SELECT * FROM users
- WHERE email = :email;
+ WHERE email = :email
</entry>
<entry key='database.selectUsersAll'>
- SELECT * FROM users;
+ SELECT * FROM users
</entry>
<entry key='database.insertUser'>
INSERT INTO users (name, email, hashedPassword, salt, admin, map, distanceUnit, speedUnit, latitude, longitude, zoom, twelveHourFormat, attributes)
- VALUES (:name, :email, :hashedPassword, :salt, :admin, :map, :distanceUnit, :speedUnit, :latitude, :longitude, :zoom, :twelveHourFormat, :attributes);
+ VALUES (:name, :email, :hashedPassword, :salt, :admin, :map, :distanceUnit, :speedUnit, :latitude, :longitude, :zoom, :twelveHourFormat, :attributes)
</entry>
<entry key='database.updateUser'>
@@ -144,101 +144,101 @@
zoom = :zoom,
twelveHourFormat = :twelveHourFormat,
attributes = :attributes
- WHERE id = :id;
+ WHERE id = :id
</entry>
<entry key='database.updateUserPassword'>
- UPDATE users SET hashedPassword = :hashedPassword, salt = :salt WHERE id = :id;
+ UPDATE users SET hashedPassword = :hashedPassword, salt = :salt WHERE id = :id
</entry>
<entry key='database.deleteUser'>
- DELETE FROM users WHERE id = :id;
+ DELETE FROM users WHERE id = :id
</entry>
<entry key='database.selectDevicePermissions'>
- SELECT userId, deviceId FROM user_device;
+ SELECT userId, deviceId FROM user_device
</entry>
<entry key='database.selectGroupPermissions'>
- SELECT userId, groupId FROM user_group;
+ SELECT userId, groupId FROM user_group
</entry>
<entry key='database.selectDevicesAll'>
- SELECT * FROM devices;
+ SELECT * FROM devices
</entry>
<entry key='database.insertDevice'>
- INSERT INTO devices (name, uniqueId, groupId, attributes) VALUES (:name, :uniqueId, :groupId, :attributes);
+ INSERT INTO devices (name, uniqueId, groupId, attributes) VALUES (:name, :uniqueId, :groupId, :attributes)
</entry>
<entry key='database.updateDevice'>
- UPDATE devices SET name = :name, uniqueId = :uniqueId, groupId = :groupId, attributes = :attributes WHERE id = :id;
+ UPDATE devices SET name = :name, uniqueId = :uniqueId, groupId = :groupId, attributes = :attributes WHERE id = :id
</entry>
<entry key='database.updateDeviceStatus'>
- UPDATE devices SET lastUpdate = :lastUpdate WHERE id = :id;
+ UPDATE devices SET lastUpdate = :lastUpdate WHERE id = :id
</entry>
<entry key='database.deleteDevice'>
- DELETE FROM devices WHERE id = :id;
+ DELETE FROM devices WHERE id = :id
</entry>
<entry key='database.linkDevice'>
- INSERT INTO user_device (userId, deviceId) VALUES (:userId, :deviceId);
+ INSERT INTO user_device (userId, deviceId) VALUES (:userId, :deviceId)
</entry>
<entry key='database.unlinkDevice'>
- DELETE FROM user_device WHERE userId = :userId AND deviceId = :deviceId;
+ DELETE FROM user_device WHERE userId = :userId AND deviceId = :deviceId
</entry>
<entry key='database.selectGroupsAll'>
- SELECT * FROM groups;
+ SELECT * FROM groups
</entry>
<entry key='database.insertGroup'>
- INSERT INTO groups (name, groupId, attributes) VALUES (:name, :groupId, :attributes);
+ INSERT INTO groups (name, groupId, attributes) VALUES (:name, :groupId, :attributes)
</entry>
<entry key='database.updateGroup'>
- UPDATE groups SET name = :name, groupId = :groupId, attributes = :attributes WHERE id = :id;
+ UPDATE groups SET name = :name, groupId = :groupId, attributes = :attributes WHERE id = :id
</entry>
<entry key='database.deleteGroup'>
- DELETE FROM groups WHERE id = :id;
+ DELETE FROM groups WHERE id = :id
</entry>
<entry key='database.linkGroup'>
- INSERT INTO user_group (userId, groupId) VALUES (:userId, :groupId);
+ INSERT INTO user_group (userId, groupId) VALUES (:userId, :groupId)
</entry>
<entry key='database.unlinkGroup'>
- DELETE FROM user_group WHERE userId = :userId AND groupId = :groupId;
+ DELETE FROM user_group WHERE userId = :userId AND groupId = :groupId
</entry>
<entry key='database.selectPositions'>
- SELECT * FROM positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime;
+ SELECT * FROM positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime
</entry>
<entry key='database.insertPosition'>
INSERT INTO positions (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, attributes)
- VALUES (:deviceId, :protocol, :now, :deviceTime, :fixTime, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :attributes);
+ VALUES (:deviceId, :protocol, :now, :deviceTime, :fixTime, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :attributes)
</entry>
<entry key='database.selectLatestPositions'>
- SELECT * FROM positions WHERE id IN (SELECT positionId FROM devices);
+ SELECT * FROM positions WHERE id IN (SELECT positionId FROM devices)
</entry>
<entry key='database.updateLatestPosition'>
- UPDATE devices SET positionId = :id WHERE id = :deviceId;
+ UPDATE devices SET positionId = :id WHERE id = :deviceId
</entry>
<entry key='database.selectEvent'>
- SELECT * FROM events WHERE id = :id;
+ SELECT * FROM events WHERE id = :id
</entry>
<entry key='database.insertEvent'>
INSERT INTO events (type, serverTime, deviceId, positionId, geofenceId, attributes)
- VALUES (:type, :serverTime, :deviceId, :positionId, :geofenceId, :attributes);
+ VALUES (:type, :serverTime, :deviceId, :positionId, :geofenceId, :attributes)
</entry>
<entry key='database.selectEvents'>
@@ -246,12 +246,12 @@
</entry>
<entry key='database.selectGeofencesAll'>
- SELECT * FROM geofences;
+ SELECT * FROM geofences
</entry>
<entry key='database.insertGeofence'>
INSERT INTO geofences (name, description, area, attributes)
- VALUES (:name, :description, :area, :attributes);
+ VALUES (:name, :description, :area, :attributes)
</entry>
<entry key='database.updateGeofence'>
@@ -260,56 +260,56 @@
description = :description,
area = :area,
attributes = :attributes
- WHERE id = :id;
+ WHERE id = :id
</entry>
<entry key='database.deleteGeofence'>
- DELETE FROM geofences WHERE id = :id;
+ DELETE FROM geofences WHERE id = :id
</entry>
<entry key='database.selectGeofencePermissions'>
- SELECT userId, geofenceId FROM user_geofence;
+ SELECT userId, geofenceId FROM user_geofence
</entry>
<entry key='database.linkGeofence'>
- INSERT INTO user_geofence (userId, geofenceId) VALUES (:userId, :geofenceId);
+ INSERT INTO user_geofence (userId, geofenceId) VALUES (:userId, :geofenceId)
</entry>
<entry key='database.unlinkGeofence'>
- DELETE FROM user_geofence WHERE userId = :userId AND geofenceId = :geofenceId;
+ DELETE FROM user_geofence WHERE userId = :userId AND geofenceId = :geofenceId
</entry>
<entry key='database.selectGroupGeofences'>
- SELECT groupId, geofenceId FROM group_geofence;
+ SELECT groupId, geofenceId FROM group_geofence
</entry>
<entry key='database.linkGroupGeofence'>
- INSERT INTO group_geofence (groupId, geofenceId) VALUES (:groupId, :geofenceId);
+ INSERT INTO group_geofence (groupId, geofenceId) VALUES (:groupId, :geofenceId)
</entry>
<entry key='database.unlinkGroupGeofence'>
- DELETE FROM group_geofence WHERE groupId = :groupId AND geofenceId = :geofenceId;
+ DELETE FROM group_geofence WHERE groupId = :groupId AND geofenceId = :geofenceId
</entry>
<entry key='database.selectDeviceGeofences'>
- SELECT deviceId, geofenceId FROM device_geofence;
+ SELECT deviceId, geofenceId FROM device_geofence
</entry>
<entry key='database.linkDeviceGeofence'>
- INSERT INTO device_geofence (deviceId, geofenceId) VALUES (:deviceId, :geofenceId);
+ INSERT INTO device_geofence (deviceId, geofenceId) VALUES (:deviceId, :geofenceId)
</entry>
<entry key='database.unlinkDeviceGeofence'>
- DELETE FROM device_geofence WHERE deviceId = :deviceId AND geofenceId = :geofenceId;
+ DELETE FROM device_geofence WHERE deviceId = :deviceId AND geofenceId = :geofenceId
</entry>
<entry key='database.selectNotifications'>
- SELECT * FROM notifications;
+ SELECT * FROM notifications
</entry>
<entry key='database.insertNotification'>
INSERT INTO notifications (userId, type, attributes)
- VALUES (:userId, :type, :attributes);
+ VALUES (:userId, :type, :attributes)
</entry>
<entry key='database.updateNotification'>
@@ -317,24 +317,24 @@
userId = :userId,
type = :type,
attributes = :attributes
- WHERE id = :id;
+ WHERE id = :id
</entry>
<entry key='database.deleteNotification'>
- DELETE FROM notifications WHERE id = :id;
+ DELETE FROM notifications WHERE id = :id
</entry>
<entry key='database.deletePositions'>
- DELETE FROM positions WHERE serverTime &lt; :serverTime AND id NOT IN (SELECT positionId FROM devices);
+ DELETE FROM positions WHERE serverTime &lt; :serverTime AND id NOT IN (SELECT positionId FROM devices)
</entry>
<entry key='database.selectAttributeAliases'>
- SELECT * FROM attribute_aliases;
+ SELECT * FROM attribute_aliases
</entry>
<entry key='database.insertAttributeAlias'>
INSERT INTO attribute_aliases (deviceId, attribute, alias)
- VALUES (:deviceId, :attribute, :alias);
+ VALUES (:deviceId, :attribute, :alias)
</entry>
<entry key='database.updateAttributeAlias'>
@@ -342,20 +342,20 @@
deviceId = :deviceId,
attribute = :attribute,
alias = :alias
- WHERE id = :id;
+ WHERE id = :id
</entry>
<entry key='database.deleteAttributeAlias'>
- DELETE FROM attribute_aliases WHERE id = :id;
+ DELETE FROM attribute_aliases WHERE id = :id
</entry>
<entry key='database.selectStatistics'>
- SELECT * FROM statistics WHERE captureTime BETWEEN :from AND :to ORDER BY captureTime;
+ SELECT * FROM statistics WHERE captureTime BETWEEN :from AND :to ORDER BY captureTime
</entry>
<entry key='database.insertStatistics'>
INSERT INTO statistics (captureTime, activeUsers, activeDevices, requests, messagesReceived, messagesStored, attributes)
- VALUES (:captureTime, :activeUsers, :activeDevices, :requests, :messagesReceived, :messagesStored, :attributes);
+ VALUES (:captureTime, :activeUsers, :activeDevices, :requests, :messagesReceived, :messagesStored, :attributes)
</entry>
<!-- PROTOCOL CONFIG -->
diff --git a/setup/docker/Dockerfile b/setup/docker/Dockerfile
index a39cad79c..40b650be1 100644
--- a/setup/docker/Dockerfile
+++ b/setup/docker/Dockerfile
@@ -2,6 +2,8 @@ FROM java:8-alpine
MAINTAINER Danilo Recchia <danilo.recchia@vortus.solutions>
+USER root
+
RUN apk upgrade --update && \
apk add --update curl bash && \
rm -rf /var/cache/apk/* && \
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java
index 5315bad9e..83d79a3c0 100644
--- a/src/org/traccar/FilterHandler.java
+++ b/src/org/traccar/FilterHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,37 +23,59 @@ public class FilterHandler extends BaseDataHandler {
private static final long FILTER_FUTURE_LIMIT = 5 * 60 * 1000;
- private final boolean filterInvalid;
- private final boolean filterZero;
- private final boolean filterDuplicate;
- private final boolean filterFuture;
- private final boolean filterApproximate;
- private final int filterDistance;
- private final long filterLimit;
-
- public FilterHandler(
- boolean filterInvalid, boolean filterZero, boolean filterDuplicate, boolean filterFuture,
- boolean filterApproximate, int filterDistance, long filterLimit) {
+ private boolean filterInvalid;
+ private boolean filterZero;
+ private boolean filterDuplicate;
+ private boolean filterFuture;
+ private boolean filterApproximate;
+ private boolean filterStatic;
+ private int filterDistance;
+ private long filterLimit;
+ public void setFilterInvalid(boolean filterInvalid) {
this.filterInvalid = filterInvalid;
+ }
+
+ public void setFilterZero(boolean filterZero) {
this.filterZero = filterZero;
+ }
+
+ public void setFilterDuplicate(boolean filterDuplicate) {
this.filterDuplicate = filterDuplicate;
- this.filterDistance = filterDistance;
+ }
+
+ public void setFilterFuture(boolean filterFuture) {
this.filterFuture = filterFuture;
+ }
+
+ public void setFilterApproximate(boolean filterApproximate) {
this.filterApproximate = filterApproximate;
+ }
+
+ public void setFilterStatic(boolean filterStatic) {
+ this.filterStatic = filterStatic;
+ }
+
+ public void setFilterDistance(int filterDistance) {
+ this.filterDistance = filterDistance;
+ }
+
+ public void setFilterLimit(long filterLimit) {
this.filterLimit = filterLimit;
}
public FilterHandler() {
Config config = Context.getConfig();
-
- filterInvalid = config.getBoolean("filter.invalid");
- filterZero = config.getBoolean("filter.zero");
- filterDuplicate = config.getBoolean("filter.duplicate");
- filterFuture = config.getBoolean("filter.future");
- filterApproximate = config.getBoolean("filter.approximate");
- filterDistance = config.getInteger("filter.distance");
- filterLimit = config.getLong("filter.limit") * 1000;
+ if (config != null) {
+ filterInvalid = config.getBoolean("filter.invalid");
+ filterZero = config.getBoolean("filter.zero");
+ filterDuplicate = config.getBoolean("filter.duplicate");
+ filterFuture = config.getBoolean("filter.future");
+ filterApproximate = config.getBoolean("filter.approximate");
+ filterStatic = config.getBoolean("filter.static");
+ filterDistance = config.getInteger("filter.distance");
+ filterLimit = config.getLong("filter.limit") * 1000;
+ }
}
private Position getLastPosition(long deviceId) {
@@ -93,6 +115,10 @@ public class FilterHandler extends BaseDataHandler {
return filterApproximate && approximate != null && approximate;
}
+ private boolean filterStatic(Position position) {
+ return filterStatic && position.getSpeed() == 0.0;
+ }
+
private boolean filterDistance(Position position) {
if (filterDistance != 0) {
Position last = getLastPosition(position.getDeviceId());
@@ -122,20 +148,38 @@ public class FilterHandler extends BaseDataHandler {
}
}
- private boolean filter(Position p) {
+ private boolean filter(Position position) {
- boolean result = filterInvalid(p) || filterZero(p) || filterDuplicate(p)
- || filterFuture(p) || filterApproximate(p) || filterDistance(p);
+ StringBuilder filterType = new StringBuilder();
- if (filterLimit(p)) {
- result = false;
+ if (filterInvalid(position)) {
+ filterType.append("Invalid ");
+ }
+ if (filterZero(position)) {
+ filterType.append("Zero ");
+ }
+ if (filterDuplicate(position)) {
+ filterType.append("Duplicate ");
+ }
+ if (filterFuture(position)) {
+ filterType.append("Future ");
+ }
+ if (filterApproximate(position)) {
+ filterType.append("Approximate ");
+ }
+ if (filterStatic(position)) {
+ filterType.append("Static ");
+ }
+ if (filterDistance(position)) {
+ filterType.append("Distance ");
}
- if (result) {
- Log.info("Position filtered from " + p.getDeviceId());
+ if (filterType.length() > 0 && !filterLimit(position)) {
+ Log.info("Position filtered by " + filterType.toString() + "filters from " + position.getDeviceId());
+ return true;
}
- return result;
+ return false;
}
@Override
diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java
index b1e4fcb16..bb7e69dc0 100644
--- a/test/org/traccar/FilterHandlerTest.java
+++ b/test/org/traccar/FilterHandlerTest.java
@@ -15,8 +15,16 @@ public class FilterHandlerTest {
@Before
public void setUp() {
- filtingHandler = new FilterHandler(true, true, true, true, true, 10, 10);
- passingHandler = new FilterHandler(false, false, false, false, false, 0, 0);
+ passingHandler = new FilterHandler();
+ filtingHandler = new FilterHandler();
+ filtingHandler.setFilterInvalid(true);
+ filtingHandler.setFilterZero(true);
+ filtingHandler.setFilterDuplicate(true);
+ filtingHandler.setFilterFuture(true);
+ filtingHandler.setFilterApproximate(true);
+ filtingHandler.setFilterStatic(true);
+ filtingHandler.setFilterDistance(10);
+ filtingHandler.setFilterLimit(10);
}
@After