aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-02-24 12:12:19 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-02-24 12:12:19 -0800
commita8566c997d27bf22ee0debad7b9b8c2db9325a43 (patch)
treeb6c272d45342781c72fa5c3b4fd6434c482c6f42 /src
parent6d98e878f9ccd5b49a97ce7c04bbc4178e482fff (diff)
downloadtrackermap-server-a8566c997d27bf22ee0debad7b9b8c2db9325a43.tar.gz
trackermap-server-a8566c997d27bf22ee0debad7b9b8c2db9325a43.tar.bz2
trackermap-server-a8566c997d27bf22ee0debad7b9b8c2db9325a43.zip
Refactor hemisphere handler
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BasePipelineFactory.java9
-rw-r--r--src/org/traccar/MainModule.java10
-rw-r--r--src/org/traccar/config/Keys.java14
-rw-r--r--src/org/traccar/handler/HemisphereHandler.java (renamed from src/org/traccar/HemisphereHandler.java)13
4 files changed, 34 insertions, 12 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index b993e0741..082d666ac 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -39,6 +39,7 @@ import org.traccar.handler.CopyAttributesHandler;
import org.traccar.handler.DistanceHandler;
import org.traccar.handler.FilterHandler;
import org.traccar.handler.GeolocationHandler;
+import org.traccar.handler.HemisphereHandler;
import org.traccar.handler.NetworkMessageHandler;
import org.traccar.handler.OpenChannelHandler;
import org.traccar.handler.RemoteAddressHandler;
@@ -56,7 +57,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
private EngineHoursHandler engineHoursHandler;
private MotionHandler motionHandler;
private GeocoderHandler geocoderHandler;
- private HemisphereHandler hemisphereHandler;
private CopyAttributesHandler copyAttributesHandler;
private ComputedAttributesHandler computedAttributesHandler;
@@ -90,11 +90,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
engineHoursHandler = new EngineHoursHandler();
}
- if (Context.getConfig().hasKey("location.latitudeHemisphere")
- || Context.getConfig().hasKey("location.longitudeHemisphere")) {
- hemisphereHandler = new HemisphereHandler();
- }
-
if (Context.getConfig().getBoolean("processing.copyAttributes.enable")) {
copyAttributesHandler = new CopyAttributesHandler();
}
@@ -166,7 +161,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
addHandlers(
pipeline,
Main.getInjector().getInstance(GeolocationHandler.class),
- hemisphereHandler,
+ Main.getInjector().getInstance(HemisphereHandler.class),
Main.getInjector().getInstance(DistanceHandler.class),
Main.getInjector().getInstance(RemoteAddressHandler.class));
diff --git a/src/org/traccar/MainModule.java b/src/org/traccar/MainModule.java
index 3b9bbe4b6..0e5c7d858 100644
--- a/src/org/traccar/MainModule.java
+++ b/src/org/traccar/MainModule.java
@@ -32,6 +32,7 @@ import org.traccar.geolocation.UnwiredGeolocationProvider;
import org.traccar.handler.DistanceHandler;
import org.traccar.handler.FilterHandler;
import org.traccar.handler.GeolocationHandler;
+import org.traccar.handler.HemisphereHandler;
import org.traccar.handler.RemoteAddressHandler;
import javax.annotation.Nullable;
@@ -108,6 +109,15 @@ public class MainModule extends AbstractModule {
@Singleton
@Provides
+ public static HemisphereHandler provideHemisphereHandler(Config config) {
+ if (config.hasKey(Keys.LOCATION_LATITUDE_HEMISPHERE) || config.hasKey(Keys.LOCATION_LONGITUDE_HEMISPHERE)) {
+ return new HemisphereHandler(config);
+ }
+ return null;
+ }
+
+ @Singleton
+ @Provides
public static RemoteAddressHandler provideRemoteAddressHandler(Config config) {
if (config.getBoolean(Keys.PROCESSING_REMOTE_ADDRESS_ENABLE)) {
return new RemoteAddressHandler();
diff --git a/src/org/traccar/config/Keys.java b/src/org/traccar/config/Keys.java
index 9347341b0..fddc70bba 100644
--- a/src/org/traccar/config/Keys.java
+++ b/src/org/traccar/config/Keys.java
@@ -213,6 +213,20 @@ public final class Keys {
public static final ConfigKey GEOLOCATION_PROCESS_INVALID_POSITIONS = new ConfigKey(
"geolocation.processInvalidPositions", Boolean.class);
+ /**
+ * Override latitude sign / hemisphere. Useful in cases where value is incorrect because of device bug. Value can be
+ * N for North or S for South.
+ */
+ public static final ConfigKey LOCATION_LATITUDE_HEMISPHERE = new ConfigKey(
+ "location.latitudeHemisphere", Boolean.class);
+
+ /**
+ * Override longitude sign / hemisphere. Useful in cases where value is incorrect because of device bug. Value can
+ * be E for East or W for West.
+ */
+ public static final ConfigKey LOCATION_LONGITUDE_HEMISPHERE = new ConfigKey(
+ "location.longitudeHemisphere", Boolean.class);
+
private Keys() {
}
diff --git a/src/org/traccar/HemisphereHandler.java b/src/org/traccar/handler/HemisphereHandler.java
index d1bcd340b..aff3d8a64 100644
--- a/src/org/traccar/HemisphereHandler.java
+++ b/src/org/traccar/handler/HemisphereHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2019 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.
@@ -13,9 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.traccar;
+package org.traccar.handler;
import io.netty.channel.ChannelHandler;
+import org.traccar.BaseDataHandler;
+import org.traccar.config.Config;
+import org.traccar.config.Keys;
import org.traccar.model.Position;
@ChannelHandler.Sharable
@@ -24,8 +27,8 @@ public class HemisphereHandler extends BaseDataHandler {
private int latitudeFactor;
private int longitudeFactor;
- public HemisphereHandler() {
- String latitudeHemisphere = Context.getConfig().getString("location.latitudeHemisphere");
+ public HemisphereHandler(Config config) {
+ String latitudeHemisphere = config.getString(Keys.LOCATION_LATITUDE_HEMISPHERE);
if (latitudeHemisphere != null) {
if (latitudeHemisphere.equalsIgnoreCase("N")) {
latitudeFactor = 1;
@@ -33,7 +36,7 @@ public class HemisphereHandler extends BaseDataHandler {
latitudeFactor = -1;
}
}
- String longitudeHemisphere = Context.getConfig().getString("location.longitudeHemisphere");
+ String longitudeHemisphere = config.getString(Keys.LOCATION_LATITUDE_HEMISPHERE);
if (longitudeHemisphere != null) {
if (longitudeHemisphere.equalsIgnoreCase("E")) {
longitudeFactor = 1;