aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-07-13 10:05:57 +0500
committerAbyss777 <abyss@fox5.ru>2017-07-13 10:05:57 +0500
commite776aa3351535f78c60ab9502dd1154e2b973227 (patch)
treeb19a69b83975aceca5ffa854da5181e62221fc0e /src/org
parent74471c1fbbb7e8a09a6958fa88930a2905b4a3eb (diff)
downloadtraccar-server-e776aa3351535f78c60ab9502dd1154e2b973227.tar.gz
traccar-server-e776aa3351535f78c60ab9502dd1154e2b973227.tar.bz2
traccar-server-e776aa3351535f78c60ab9502dd1154e2b973227.zip
- Save both driver name and driver unique id in trip report
- Map user and driver objects to notification templates - Add driverUnauthorized templates
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/notification/NotificationFormatter.java7
-rw-r--r--src/org/traccar/reports/ReportUtils.java17
-rw-r--r--src/org/traccar/reports/model/TripReport.java10
3 files changed, 28 insertions, 6 deletions
diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java
index 96337ecaa..a30023fdc 100644
--- a/src/org/traccar/notification/NotificationFormatter.java
+++ b/src/org/traccar/notification/NotificationFormatter.java
@@ -30,6 +30,7 @@ import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import org.traccar.model.User;
import org.traccar.reports.ReportUtils;
public final class NotificationFormatter {
@@ -38,9 +39,11 @@ public final class NotificationFormatter {
}
public static VelocityContext prepareContext(long userId, Event event, Position position) {
+ User user = Context.getPermissionsManager().getUser(userId);
Device device = Context.getIdentityManager().getDeviceById(event.getDeviceId());
VelocityContext velocityContext = new VelocityContext();
+ velocityContext.put("user", user);
velocityContext.put("device", device);
velocityContext.put("event", event);
if (position != null) {
@@ -50,6 +53,10 @@ public final class NotificationFormatter {
if (event.getGeofenceId() != 0) {
velocityContext.put("geofence", Context.getGeofenceManager().getGeofence(event.getGeofenceId()));
}
+ String driverUniqueId = event.getString(Position.KEY_DRIVER_UNIQUE_ID);
+ if (driverUniqueId != null) {
+ velocityContext.put("driver", Context.getDriversManager().getDriverByUniqueId(driverUniqueId));
+ }
velocityContext.put("webUrl", Context.getVelocityEngine().getProperty("web.url"));
velocityContext.put("dateTool", new DateTool());
velocityContext.put("numberTool", new NumberTool());
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index 92918b861..3a177300b 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -102,16 +102,19 @@ public final class ReportUtils {
return 0;
}
- public static String findDriverName(Position firstPosition, Position lastPosition) {
- String driverUniqueId = null;
+ public static String findDriver(Position firstPosition, Position lastPosition) {
if (firstPosition.getAttributes().containsKey(Position.KEY_DRIVER_UNIQUE_ID)) {
- driverUniqueId = firstPosition.getString(Position.KEY_DRIVER_UNIQUE_ID);
+ return 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);
+ return lastPosition.getString(Position.KEY_DRIVER_UNIQUE_ID);
}
+ return null;
+ }
+
+ public static String findDriverName(String driverUniqueId) {
if (driverUniqueId != null && Context.getDriversManager() != null) {
Driver driver = Context.getDriversManager().getDriverByUniqueId(driverUniqueId);
- return driver != null ? driver.getName() : null;
+ return driver != null ? driver.getName() : driverUniqueId;
}
return null;
}
@@ -190,7 +193,9 @@ public final class ReportUtils {
trip.setAverageSpeed(speedSum / (endIndex - startIndex));
trip.setMaxSpeed(speedMax);
trip.setSpentFuel(calculateFuel(startTrip, endTrip));
- trip.setDriverName(findDriverName(startTrip, endTrip));
+
+ trip.setDriverUniqueId(findDriver(startTrip, endTrip));
+ trip.setDriverName(findDriverName(trip.getDriverUniqueId()));
return trip;
}
diff --git a/src/org/traccar/reports/model/TripReport.java b/src/org/traccar/reports/model/TripReport.java
index 0f23581b2..42a4240b7 100644
--- a/src/org/traccar/reports/model/TripReport.java
+++ b/src/org/traccar/reports/model/TripReport.java
@@ -146,6 +146,16 @@ public class TripReport extends BaseReport {
this.duration = duration;
}
+ private String driverUniqueId;
+
+ public String getDriverUniqueId() {
+ return driverUniqueId;
+ }
+
+ public void setDriverUniqueId(String driverUniqueId) {
+ this.driverUniqueId = driverUniqueId;
+ }
+
private String driverName;
public String getDriverName() {