aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-01 10:16:42 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-01 10:16:42 +1300
commit9034cd07e95320a37a0f788ee6eaa546af5f4df1 (patch)
tree1e991b7b3682a07d22d9f1e138608024af963e66
parentf16ce106253ce3a857efbe4cd7b65f76c77d6364 (diff)
downloadtraccar-server-9034cd07e95320a37a0f788ee6eaa546af5f4df1.tar.gz
traccar-server-9034cd07e95320a37a0f788ee6eaa546af5f4df1.tar.bz2
traccar-server-9034cd07e95320a37a0f788ee6eaa546af5f4df1.zip
Implemenet future message filtering
-rw-r--r--src/org/traccar/FilterHandler.java15
-rw-r--r--test/org/traccar/FilterHandlerTest.java9
2 files changed, 21 insertions, 3 deletions
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java
index c601016b4..e24de487f 100644
--- a/src/org/traccar/FilterHandler.java
+++ b/src/org/traccar/FilterHandler.java
@@ -19,18 +19,24 @@ import org.traccar.helper.DistanceCalculator;
import org.traccar.helper.Log;
import org.traccar.model.Position;
+import java.util.Date;
+
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 int filterDistance;
private final long filterLimit;
-
+
public FilterHandler(
boolean filterInvalid,
boolean filterZero,
boolean filterDuplicate,
+ boolean filterFuture,
int filterDistance,
long filterLimit) {
@@ -38,6 +44,7 @@ public class FilterHandler extends BaseDataHandler {
this.filterZero = filterZero;
this.filterDuplicate = filterDuplicate;
this.filterDistance = filterDistance;
+ this.filterFuture = filterFuture;
this.filterLimit = filterLimit;
}
@@ -47,6 +54,7 @@ public class FilterHandler extends BaseDataHandler {
filterInvalid = config.getBoolean("filter.invalid");
filterZero = config.getBoolean("filter.zero");
filterDuplicate = config.getBoolean("filter.duplicate");
+ filterFuture = config.getBoolean("filter.future");
filterDistance = config.getInteger("filter.distance");
filterLimit = config.getLong("filter.limit") * 1000;
}
@@ -80,6 +88,10 @@ public class FilterHandler extends BaseDataHandler {
return false;
}
}
+
+ private boolean filterFuture(Position position) {
+ return filterFuture && (position.getFixTime().getTime() > System.currentTimeMillis() + FILTER_FUTURE_LIMIT);
+ }
private boolean filterDistance(Position position) {
if (filterDistance != 0) {
@@ -116,6 +128,7 @@ public class FilterHandler extends BaseDataHandler {
filterInvalid(p) ||
filterZero(p) ||
filterDuplicate(p) ||
+ filterFuture(p) ||
filterDistance(p);
if (filterLimit(p)) {
diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java
index ee5ddd396..f860c489f 100644
--- a/test/org/traccar/FilterHandlerTest.java
+++ b/test/org/traccar/FilterHandlerTest.java
@@ -15,8 +15,8 @@ public class FilterHandlerTest {
@Before
public void setUp() {
- filtingHandler = new FilterHandler(true, true, true, 10, 10);
- passingHandler = new FilterHandler(false, false, false, 0, 0);
+ filtingHandler = new FilterHandler(true, true, true, true, 10, 10);
+ passingHandler = new FilterHandler(false, false, false, false, 0, 0);
}
@After
@@ -55,6 +55,11 @@ public class FilterHandlerTest {
assertNotNull(filtingHandler.decode(null, null, position));
assertNotNull(passingHandler.decode(null, null, position));
+ position = createPosition(0, new Date(Long.MAX_VALUE), true, 10, 10, 10, 10, 10);
+
+ assertNull(filtingHandler.decode(null, null, position));
+ assertNotNull(passingHandler.decode(null, null, position));
+
position = createPosition(0, new Date(), false, 10, 10, 10, 10, 10);
assertNull(filtingHandler.decode(null, null, position));