From 15f0744893304a3f2a77d36734cdc2a2706286dd Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 27 Feb 2019 23:08:06 -0800 Subject: Minor refactoring --- .../traccar/handler/events/AlertEventHandler.java | 1 - .../traccar/handler/events/BaseEventHandler.java | 38 ++++++++++++++++++++++ .../handler/events/CommandResultEventHandler.java | 1 - .../traccar/handler/events/DriverEventHandler.java | 1 - .../handler/events/FuelDropEventHandler.java | 1 - .../handler/events/GeofenceEventHandler.java | 1 - .../handler/events/IgnitionEventHandler.java | 1 - .../handler/events/MaintenanceEventHandler.java | 1 - .../traccar/handler/events/MotionEventHandler.java | 1 - .../handler/events/OverspeedEventHandler.java | 1 - .../handler/events/TextMessageEventHandler.java | 37 --------------------- 11 files changed, 38 insertions(+), 46 deletions(-) create mode 100644 src/org/traccar/handler/events/BaseEventHandler.java delete mode 100644 src/org/traccar/handler/events/TextMessageEventHandler.java (limited to 'src/org/traccar/handler') diff --git a/src/org/traccar/handler/events/AlertEventHandler.java b/src/org/traccar/handler/events/AlertEventHandler.java index c6d61538b..09a6e2b6b 100644 --- a/src/org/traccar/handler/events/AlertEventHandler.java +++ b/src/org/traccar/handler/events/AlertEventHandler.java @@ -19,7 +19,6 @@ import java.util.Collections; import java.util.Map; import io.netty.channel.ChannelHandler; -import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Event; import org.traccar.model.Position; diff --git a/src/org/traccar/handler/events/BaseEventHandler.java b/src/org/traccar/handler/events/BaseEventHandler.java new file mode 100644 index 000000000..41f677f6c --- /dev/null +++ b/src/org/traccar/handler/events/BaseEventHandler.java @@ -0,0 +1,38 @@ +/* + * Copyright 2016 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.events; + +import java.util.Map; + +import org.traccar.BaseDataHandler; +import org.traccar.Context; +import org.traccar.model.Event; +import org.traccar.model.Position; + +public abstract class BaseEventHandler extends BaseDataHandler { + + @Override + protected Position handlePosition(Position position) { + Map events = analyzePosition(position); + if (events != null && Context.getNotificationManager() != null) { + Context.getNotificationManager().updateEvents(events); + } + return position; + } + + protected abstract Map analyzePosition(Position position); + +} diff --git a/src/org/traccar/handler/events/CommandResultEventHandler.java b/src/org/traccar/handler/events/CommandResultEventHandler.java index 3acddc1b9..cfe676653 100644 --- a/src/org/traccar/handler/events/CommandResultEventHandler.java +++ b/src/org/traccar/handler/events/CommandResultEventHandler.java @@ -19,7 +19,6 @@ import java.util.Collections; import java.util.Map; import io.netty.channel.ChannelHandler; -import org.traccar.BaseEventHandler; import org.traccar.model.Event; import org.traccar.model.Position; diff --git a/src/org/traccar/handler/events/DriverEventHandler.java b/src/org/traccar/handler/events/DriverEventHandler.java index ef73d6d2d..dbb980c89 100644 --- a/src/org/traccar/handler/events/DriverEventHandler.java +++ b/src/org/traccar/handler/events/DriverEventHandler.java @@ -20,7 +20,6 @@ import java.util.Collections; import java.util.Map; import io.netty.channel.ChannelHandler; -import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Event; import org.traccar.model.Position; diff --git a/src/org/traccar/handler/events/FuelDropEventHandler.java b/src/org/traccar/handler/events/FuelDropEventHandler.java index 7de3930ca..f13b8c7bb 100644 --- a/src/org/traccar/handler/events/FuelDropEventHandler.java +++ b/src/org/traccar/handler/events/FuelDropEventHandler.java @@ -16,7 +16,6 @@ package org.traccar.handler.events; import io.netty.channel.ChannelHandler; -import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.Event; diff --git a/src/org/traccar/handler/events/GeofenceEventHandler.java b/src/org/traccar/handler/events/GeofenceEventHandler.java index 3bddfe7a4..878331c84 100644 --- a/src/org/traccar/handler/events/GeofenceEventHandler.java +++ b/src/org/traccar/handler/events/GeofenceEventHandler.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Map; import io.netty.channel.ChannelHandler; -import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.database.GeofenceManager; import org.traccar.model.Calendar; diff --git a/src/org/traccar/handler/events/IgnitionEventHandler.java b/src/org/traccar/handler/events/IgnitionEventHandler.java index 4930ef901..7a83f45b7 100644 --- a/src/org/traccar/handler/events/IgnitionEventHandler.java +++ b/src/org/traccar/handler/events/IgnitionEventHandler.java @@ -20,7 +20,6 @@ import java.util.Collections; import java.util.Map; import io.netty.channel.ChannelHandler; -import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.Event; diff --git a/src/org/traccar/handler/events/MaintenanceEventHandler.java b/src/org/traccar/handler/events/MaintenanceEventHandler.java index e7f641431..80d9c0d91 100644 --- a/src/org/traccar/handler/events/MaintenanceEventHandler.java +++ b/src/org/traccar/handler/events/MaintenanceEventHandler.java @@ -20,7 +20,6 @@ import java.util.HashMap; import java.util.Map; import io.netty.channel.ChannelHandler; -import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Event; import org.traccar.model.Maintenance; diff --git a/src/org/traccar/handler/events/MotionEventHandler.java b/src/org/traccar/handler/events/MotionEventHandler.java index c03b394e5..5e88d34b5 100644 --- a/src/org/traccar/handler/events/MotionEventHandler.java +++ b/src/org/traccar/handler/events/MotionEventHandler.java @@ -20,7 +20,6 @@ import java.util.Collections; import java.util.Map; import io.netty.channel.ChannelHandler; -import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.DeviceState; diff --git a/src/org/traccar/handler/events/OverspeedEventHandler.java b/src/org/traccar/handler/events/OverspeedEventHandler.java index 567758de5..34344fb47 100644 --- a/src/org/traccar/handler/events/OverspeedEventHandler.java +++ b/src/org/traccar/handler/events/OverspeedEventHandler.java @@ -20,7 +20,6 @@ import java.util.Collections; import java.util.Map; import io.netty.channel.ChannelHandler; -import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.DeviceState; diff --git a/src/org/traccar/handler/events/TextMessageEventHandler.java b/src/org/traccar/handler/events/TextMessageEventHandler.java deleted file mode 100644 index b5e2c72b0..000000000 --- a/src/org/traccar/handler/events/TextMessageEventHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2017 Anton Tananaev (anton@traccar.org) - * Copyright 2017 Andrey Kunitsyn (andrey@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.events; - -import org.traccar.Context; -import org.traccar.model.Device; -import org.traccar.model.Event; - -public final class TextMessageEventHandler { - - private TextMessageEventHandler() { - } - - public static void handleTextMessage(String phone, String message) { - Device device = Context.getDeviceManager().getDeviceByPhone(phone); - if (device != null && Context.getNotificationManager() != null) { - Event event = new Event(Event.TYPE_TEXT_MESSAGE, device.getId()); - event.set("message", message); - Context.getNotificationManager().updateEvent(event, null); - } - } - -} -- cgit v1.2.3