aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/BasePipelineFactory.java8
-rw-r--r--src/org/traccar/database/DriversManager.java12
-rw-r--r--src/org/traccar/model/Position.java2
-rw-r--r--src/org/traccar/processing/PopulateDriverHandler.java45
-rw-r--r--src/org/traccar/protocol/AplicomProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java2
-rw-r--r--src/org/traccar/reports/ReportUtils.java16
-rw-r--r--src/org/traccar/reports/model/TripReport.java10
10 files changed, 100 insertions, 3 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index a6446dbaa..9f0824b6c 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -40,6 +40,7 @@ import org.traccar.events.AlertEventHandler;
import org.traccar.helper.Log;
import org.traccar.processing.ComputedAttributesHandler;
import org.traccar.processing.CopyAttributesHandler;
+import org.traccar.processing.PopulateDriverHandler;
import java.net.InetSocketAddress;
@@ -54,6 +55,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
private GeocoderHandler geocoderHandler;
private GeolocationHandler geolocationHandler;
private HemisphereHandler hemisphereHandler;
+ private PopulateDriverHandler populateDriverHandler;
private CopyAttributesHandler copyAttributesHandler;
private ComputedAttributesHandler computedAttributesHandler;
@@ -152,6 +154,8 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
hemisphereHandler = new HemisphereHandler();
}
+ populateDriverHandler = new PopulateDriverHandler();
+
if (Context.getConfig().getBoolean("processing.copyAttributes.enable")) {
copyAttributesHandler = new CopyAttributesHandler();
}
@@ -214,6 +218,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
pipeline.addLast("motion", motionHandler);
}
+ if (populateDriverHandler != null) {
+ pipeline.addLast("populateDriver", populateDriverHandler);
+ }
+
if (copyAttributesHandler != null) {
pipeline.addLast("copyAttributes", copyAttributesHandler);
}
diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java
index e89d59311..1744936e3 100644
--- a/src/org/traccar/database/DriversManager.java
+++ b/src/org/traccar/database/DriversManager.java
@@ -210,4 +210,16 @@ public class DriversManager {
}
return drivers;
}
+
+ public final boolean authorizeDriverByUniqueId(String driverUniqueId, long deviceId) {
+ if (driversByUniqueId.containsKey(driverUniqueId)) {
+ long chekingDriverId = getDriverByUniqueId(driverUniqueId).getId();
+ for (long driverId : getAllDeviceDrivers(deviceId)) {
+ if (chekingDriverId == driverId) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java
index 5835310ae..97b3f365f 100644
--- a/src/org/traccar/model/Position.java
+++ b/src/org/traccar/model/Position.java
@@ -81,6 +81,8 @@ public class Position extends Message {
public static final String KEY_RESULT = "result";
+ public static final String KEY_DRIVER_UNIQUE_ID = "driverUniqueId";
+
// Start with 1 not 0
public static final String PREFIX_TEMP = "temp";
public static final String PREFIX_ADC = "adc";
diff --git a/src/org/traccar/processing/PopulateDriverHandler.java b/src/org/traccar/processing/PopulateDriverHandler.java
new file mode 100644
index 000000000..339cc5548
--- /dev/null
+++ b/src/org/traccar/processing/PopulateDriverHandler.java
@@ -0,0 +1,45 @@
+/*
+ * 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.processing;
+
+import org.traccar.BaseDataHandler;
+import org.traccar.Context;
+import org.traccar.model.Position;
+
+public class PopulateDriverHandler extends BaseDataHandler {
+
+ private Position getLastPosition(long deviceId) {
+ if (Context.getIdentityManager() != null) {
+ return Context.getIdentityManager().getLastPosition(deviceId);
+ }
+ return null;
+ }
+
+ @Override
+ protected Position handlePosition(Position position) {
+ if (position.getAttributes().containsKey(Position.KEY_RFID)) {
+ position.set(Position.KEY_DRIVER_UNIQUE_ID, position.getString(Position.KEY_RFID));
+ } else {
+ Position last = getLastPosition(position.getDeviceId());
+ if (last != null && last.getAttributes().containsKey(Position.KEY_DRIVER_UNIQUE_ID)) {
+ position.set(Position.KEY_DRIVER_UNIQUE_ID, last.getString(Position.KEY_DRIVER_UNIQUE_ID));
+ }
+ }
+ return position;
+ }
+
+}
diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java
index eb8d77011..448cd94fc 100644
--- a/src/org/traccar/protocol/AplicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java
@@ -263,7 +263,8 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
}
if ((selector & 0x0200) != 0) {
- position.set(Position.KEY_RFID, (((long) buf.readUnsignedShort()) << 32) + buf.readUnsignedInt());
+ position.set(Position.KEY_RFID,
+ String.valueOf(((long) buf.readUnsignedShort()) << 32) + buf.readUnsignedInt());
}
if ((selector & 0x0400) != 0) {
diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
index 44e01d5e0..77e117262 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
@@ -253,7 +253,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
}
if (parser.hasNext()) {
- position.set(Position.KEY_RFID, parser.nextHexInt(0));
+ position.set(Position.KEY_RFID, String.valueOf(parser.nextHexInt(0)));
}
return position;
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index 15f6f40b8..20cd54b2f 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -128,6 +128,9 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
case "batt":
position.set(Position.KEY_BATTERY_LEVEL, Double.parseDouble(value));
break;
+ case "rfid":
+ position.set(Position.KEY_RFID, value);
+ break;
default:
try {
position.set(entry.getKey(), Double.parseDouble(value));
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 3f5b68f67..f1fd55d98 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -114,7 +114,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.PREFIX_TEMP + 3, readValue(buf, length, true) * 0.1);
break;
case 78:
- position.set(Position.KEY_RFID, readValue(buf, length, false));
+ position.set(Position.KEY_RFID, String.valueOf(readValue(buf, length, false)));
break;
case 182:
position.set(Position.KEY_HDOP, readValue(buf, length, false) * 0.1);
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index 71c567c29..92918b861 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -26,6 +26,7 @@ import org.jxls.transform.Transformer;
import org.jxls.transform.poi.PoiTransformer;
import org.jxls.util.TransformerFactory;
import org.traccar.Context;
+import org.traccar.model.Driver;
import org.traccar.model.Position;
import org.traccar.reports.model.BaseReport;
import org.traccar.reports.model.StopReport;
@@ -101,6 +102,20 @@ public final class ReportUtils {
return 0;
}
+ public static String findDriverName(Position firstPosition, Position lastPosition) {
+ String driverUniqueId = null;
+ if (firstPosition.getAttributes().containsKey(Position.KEY_DRIVER_UNIQUE_ID)) {
+ driverUniqueId = firstPosition.getString(Position.KEY_DRIVER_UNIQUE_ID);
+ } else if (lastPosition.getAttributes().containsKey(Position.KEY_DRIVER_UNIQUE_ID)) {
+ driverUniqueId = lastPosition.getString(Position.KEY_DRIVER_UNIQUE_ID);
+ }
+ if (driverUniqueId != null && Context.getDriversManager() != null) {
+ Driver driver = Context.getDriversManager().getDriverByUniqueId(driverUniqueId);
+ return driver != null ? driver.getName() : null;
+ }
+ return null;
+ }
+
public static org.jxls.common.Context initializeContext(long userId) {
org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext();
jxlsContext.putVar("distanceUnit", getDistanceUnit(userId));
@@ -175,6 +190,7 @@ public final class ReportUtils {
trip.setAverageSpeed(speedSum / (endIndex - startIndex));
trip.setMaxSpeed(speedMax);
trip.setSpentFuel(calculateFuel(startTrip, endTrip));
+ trip.setDriverName(findDriverName(startTrip, endTrip));
return trip;
}
diff --git a/src/org/traccar/reports/model/TripReport.java b/src/org/traccar/reports/model/TripReport.java
index efe556f79..0f23581b2 100644
--- a/src/org/traccar/reports/model/TripReport.java
+++ b/src/org/traccar/reports/model/TripReport.java
@@ -145,4 +145,14 @@ public class TripReport extends BaseReport {
public void setDuration(long duration) {
this.duration = duration;
}
+
+ private String driverName;
+
+ public String getDriverName() {
+ return driverName;
+ }
+
+ public void setDriverName(String driverName) {
+ this.driverName = driverName;
+ }
}