aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BasePipelineFactory.java7
-rw-r--r--src/org/traccar/events/DriverEventHandler.java59
-rw-r--r--src/org/traccar/model/Event.java2
3 files changed, 68 insertions, 0 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 9f0824b6c..98a327220 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -30,6 +30,7 @@ import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.handler.logging.LoggingHandler;
import org.jboss.netty.handler.timeout.IdleStateHandler;
import org.traccar.events.CommandResultEventHandler;
+import org.traccar.events.DriverEventHandler;
import org.traccar.events.FuelDropEventHandler;
import org.traccar.events.GeofenceEventHandler;
import org.traccar.events.IgnitionEventHandler;
@@ -67,6 +68,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
private AlertEventHandler alertEventHandler;
private IgnitionEventHandler ignitionEventHandler;
private MaintenanceEventHandler maintenanceEventHandler;
+ private DriverEventHandler driverEventHandler;
private static final class OpenChannelHandler extends SimpleChannelHandler {
@@ -173,6 +175,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
alertEventHandler = new AlertEventHandler();
ignitionEventHandler = new IgnitionEventHandler();
maintenanceEventHandler = new MaintenanceEventHandler();
+ driverEventHandler = new DriverEventHandler();
}
}
@@ -270,6 +273,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
pipeline.addLast("MaintenanceEventHandler", maintenanceEventHandler);
}
+ if (driverEventHandler != null) {
+ pipeline.addLast("DriverEventHandler", driverEventHandler);
+ }
+
pipeline.addLast("mainHandler", new MainEventHandler());
return pipeline;
}
diff --git a/src/org/traccar/events/DriverEventHandler.java b/src/org/traccar/events/DriverEventHandler.java
new file mode 100644
index 000000000..9109373c7
--- /dev/null
+++ b/src/org/traccar/events/DriverEventHandler.java
@@ -0,0 +1,59 @@
+/*
+ * 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.events;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.traccar.BaseEventHandler;
+import org.traccar.Context;
+import org.traccar.model.Event;
+import org.traccar.model.Position;
+
+public class DriverEventHandler extends BaseEventHandler {
+
+ private boolean notRepeat;
+
+ public DriverEventHandler() {
+ notRepeat = Context.getConfig().getBoolean("event.driver.notRepeat");
+ }
+
+ @Override
+ protected Collection<Event> analyzePosition(Position position) {
+ if (!Context.getIdentityManager().isLatestPosition(position)) {
+ return null;
+ }
+ String driverUniqueId = position.getString(Position.KEY_DRIVER_UNIQUE_ID);
+ if (driverUniqueId != null) {
+ String oldDriverUniqueId = null;
+ if (notRepeat) {
+ Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ if (lastPosition != null) {
+ oldDriverUniqueId = lastPosition.getString(Position.KEY_DRIVER_UNIQUE_ID);
+ }
+ }
+ if (!driverUniqueId.equals(oldDriverUniqueId)
+ && !Context.getDriversManager().authorizeDriverByUniqueId(driverUniqueId, position.getDeviceId())) {
+ Event event = new Event(Event.TYPE_DRIVER_UNAUTHORIZED, position.getDeviceId(), position.getId());
+ event.set(Position.KEY_DRIVER_UNIQUE_ID, driverUniqueId);
+ return Collections.singleton(event);
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index 6a24d91c6..dd5358f75 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -61,6 +61,8 @@ public class Event extends Message {
public static final String TYPE_TEXT_MESSAGE = "textMessage";
+ public static final String TYPE_DRIVER_UNAUTHORIZED = "driverUnauthorized";
+
private Date serverTime;
public Date getServerTime() {