aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/notification/NotificationFormatter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/notification/NotificationFormatter.java')
-rw-r--r--src/main/java/org/traccar/notification/NotificationFormatter.java13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/notification/NotificationFormatter.java b/src/main/java/org/traccar/notification/NotificationFormatter.java
index 9ee3b97b6..7685eac0d 100644
--- a/src/main/java/org/traccar/notification/NotificationFormatter.java
+++ b/src/main/java/org/traccar/notification/NotificationFormatter.java
@@ -19,16 +19,18 @@ package org.traccar.notification;
import org.apache.velocity.VelocityContext;
import org.traccar.helper.model.UserUtil;
import org.traccar.model.Device;
+import org.traccar.model.Driver;
import org.traccar.model.Event;
import org.traccar.model.Geofence;
import org.traccar.model.Maintenance;
+import org.traccar.model.Notification;
import org.traccar.model.Position;
import org.traccar.model.Server;
import org.traccar.model.User;
import org.traccar.session.cache.CacheManager;
-import javax.inject.Inject;
-import javax.inject.Singleton;
+import jakarta.inject.Inject;
+import jakarta.inject.Singleton;
@Singleton
public class NotificationFormatter {
@@ -43,13 +45,15 @@ public class NotificationFormatter {
this.textTemplateFormatter = textTemplateFormatter;
}
- public NotificationMessage formatMessage(User user, Event event, Position position, String templatePath) {
+ public NotificationMessage formatMessage(
+ Notification notification, User user, Event event, Position position, String templatePath) {
Server server = cacheManager.getServer();
Device device = cacheManager.getObject(Device.class, event.getDeviceId());
VelocityContext velocityContext = textTemplateFormatter.prepareContext(server, user);
+ velocityContext.put("notification", notification);
velocityContext.put("device", device);
velocityContext.put("event", event);
if (position != null) {
@@ -66,7 +70,8 @@ public class NotificationFormatter {
}
String driverUniqueId = event.getString(Position.KEY_DRIVER_UNIQUE_ID);
if (driverUniqueId != null) {
- velocityContext.put("driver", cacheManager.findDriverByUniqueId(device.getId(), driverUniqueId));
+ velocityContext.put("driver", cacheManager.getDeviceObjects(device.getId(), Driver.class).stream()
+ .filter(driver -> driver.getUniqueId().equals(driverUniqueId)).findFirst().orElse(null));
}
return textTemplateFormatter.formatMessage(velocityContext, event.getType(), templatePath);