From a54bd7f41229a0244c2a44fc571fc70feebe13a0 Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Fri, 14 Nov 2014 15:07:44 -0500 Subject: Added option to choose if one ReverseGeoCodes invalid positions --- src/org/traccar/BasePipelineFactory.java | 9 ++++++++- src/org/traccar/ReverseGeocoderHandler.java | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 83207b91f..aba568de6 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -36,6 +36,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { private final ReverseGeocoder reverseGeocoder; private FilterHandler filterHandler; private Integer resetDelay; + private Boolean processInvalidPositions; /** * Open channel handler @@ -100,6 +101,12 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { if (enableFilter != null && Boolean.valueOf(enableFilter)) { filterHandler = new FilterHandler(serverManager); } + + if (reverseGeocoder != null) { + // Default behavior is to process invalid positions (i.e., the "null" case) + String invalidPositions = serverManager.getProperties().getProperty("geocode.processInvalidPositions"); + processInvalidPositions = (invalidPositions == null || Boolean.valueOf(invalidPositions)); + } } protected DataManager getDataManager() { @@ -123,7 +130,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { pipeline.addLast("filter", filterHandler); } if (reverseGeocoder != null) { - pipeline.addLast("geocoder", new ReverseGeocoderHandler(reverseGeocoder)); + pipeline.addLast("geocoder", new ReverseGeocoderHandler(reverseGeocoder, processInvalidPositions)); } pipeline.addLast("handler", new TrackerEventHandler(dataManager)); return pipeline; diff --git a/src/org/traccar/ReverseGeocoderHandler.java b/src/org/traccar/ReverseGeocoderHandler.java index 8bdd7ebfc..6d77ed253 100644 --- a/src/org/traccar/ReverseGeocoderHandler.java +++ b/src/org/traccar/ReverseGeocoderHandler.java @@ -26,9 +26,11 @@ import org.traccar.model.Position; public class ReverseGeocoderHandler extends OneToOneDecoder { private final ReverseGeocoder geocoder; + private final boolean processInvalidPositions; - public ReverseGeocoderHandler(ReverseGeocoder geocoder) { + public ReverseGeocoderHandler(ReverseGeocoder geocoder, boolean processInvalidPositions ) { this.geocoder = geocoder; + this.processInvalidPositions = processInvalidPositions; } @Override @@ -39,13 +41,18 @@ public class ReverseGeocoderHandler extends OneToOneDecoder { if (geocoder != null) { if (msg instanceof Position) { Position position = (Position) msg; - position.setAddress(geocoder.getAddress( - position.getLatitude(), position.getLongitude())); + + if (processInvalidPositions || position.getValid()) { + position.setAddress(geocoder.getAddress( + position.getLatitude(), position.getLongitude())); + } } else if (msg instanceof List) { List positions = (List) msg; for (Position position : positions) { - position.setAddress(geocoder.getAddress( - position.getLatitude(), position.getLongitude())); + if (processInvalidPositions || position.getValid()) { + position.setAddress(geocoder.getAddress( + position.getLatitude(), position.getLongitude())); + } } } } -- cgit v1.2.3 From cee5be49edbcef85e9eb7072a9b6723e2474c9cf Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Fri, 14 Nov 2014 21:04:05 -0500 Subject: Removed unused import --- src/org/traccar/ReverseGeocoderHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/org/traccar/ReverseGeocoderHandler.java b/src/org/traccar/ReverseGeocoderHandler.java index 6d77ed253..7a3372dff 100644 --- a/src/org/traccar/ReverseGeocoderHandler.java +++ b/src/org/traccar/ReverseGeocoderHandler.java @@ -18,7 +18,6 @@ package org.traccar; import java.util.List; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.geocode.ReverseGeocoder; import org.traccar.model.Position; -- cgit v1.2.3