aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/notification
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-07 18:04:24 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-07 18:04:24 -0700
commit104281f161f622df8fca0c65a5b9969ceb03c46f (patch)
treed9bc756c29a9088a762bb434c443fccbb1eb9e7e /src/main/java/org/traccar/notification
parentb745e3804950fefd24b38937c90c4d5c61219321 (diff)
downloadtrackermap-server-104281f161f622df8fca0c65a5b9969ceb03c46f.tar.gz
trackermap-server-104281f161f622df8fca0c65a5b9969ceb03c46f.tar.bz2
trackermap-server-104281f161f622df8fca0c65a5b9969ceb03c46f.zip
Extract user utils from reports
Diffstat (limited to 'src/main/java/org/traccar/notification')
-rw-r--r--src/main/java/org/traccar/notification/NotificationFormatter.java12
-rw-r--r--src/main/java/org/traccar/notification/TextTemplateFormatter.java9
2 files changed, 12 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/notification/NotificationFormatter.java b/src/main/java/org/traccar/notification/NotificationFormatter.java
index be90761b1..13f42a8b2 100644
--- a/src/main/java/org/traccar/notification/NotificationFormatter.java
+++ b/src/main/java/org/traccar/notification/NotificationFormatter.java
@@ -17,13 +17,14 @@
package org.traccar.notification;
import org.apache.velocity.VelocityContext;
+import org.traccar.helper.UserUtil;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Geofence;
import org.traccar.model.Maintenance;
import org.traccar.model.Position;
+import org.traccar.model.Server;
import org.traccar.model.User;
-import org.traccar.reports.common.ReportUtils;
import org.traccar.session.cache.CacheManager;
public final class NotificationFormatter {
@@ -34,17 +35,18 @@ public final class NotificationFormatter {
public static NotificationMessage formatMessage(
CacheManager cacheManager, User user, Event event, Position position, String templatePath) {
+ Server server = cacheManager.getServer();
Device device = cacheManager.getObject(Device.class, event.getDeviceId());
- VelocityContext velocityContext = TextTemplateFormatter.prepareContext(user);
+ VelocityContext velocityContext = TextTemplateFormatter.prepareContext(server, user);
velocityContext.put("device", device);
velocityContext.put("event", event);
if (position != null) {
velocityContext.put("position", position);
- velocityContext.put("speedUnit", ReportUtils.getSpeedUnit(user.getId()));
- velocityContext.put("distanceUnit", ReportUtils.getDistanceUnit(user.getId()));
- velocityContext.put("volumeUnit", ReportUtils.getVolumeUnit(user.getId()));
+ velocityContext.put("speedUnit", UserUtil.getSpeedUnit(server, user));
+ velocityContext.put("distanceUnit", UserUtil.getDistanceUnit(server, user));
+ velocityContext.put("volumeUnit", UserUtil.getVolumeUnit(server, user));
}
if (event.getGeofenceId() != 0) {
velocityContext.put("geofence", cacheManager.getObject(Geofence.class, event.getGeofenceId()));
diff --git a/src/main/java/org/traccar/notification/TextTemplateFormatter.java b/src/main/java/org/traccar/notification/TextTemplateFormatter.java
index 469de2d4a..06375afac 100644
--- a/src/main/java/org/traccar/notification/TextTemplateFormatter.java
+++ b/src/main/java/org/traccar/notification/TextTemplateFormatter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Anton Tananaev (anton@traccar.org)
+ * Copyright 2021 - 2022 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.
@@ -23,8 +23,9 @@ import org.apache.velocity.tools.generic.NumberTool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.Context;
+import org.traccar.helper.UserUtil;
+import org.traccar.model.Server;
import org.traccar.model.User;
-import org.traccar.reports.common.ReportUtils;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
@@ -38,13 +39,13 @@ public final class TextTemplateFormatter {
private TextTemplateFormatter() {
}
- public static VelocityContext prepareContext(User user) {
+ public static VelocityContext prepareContext(Server server, User user) {
VelocityContext velocityContext = new VelocityContext();
if (user != null) {
velocityContext.put("user", user);
- velocityContext.put("timezone", ReportUtils.getTimezone(user.getId()));
+ velocityContext.put("timezone", UserUtil.getTimezone(server, user));
}
velocityContext.put("webUrl", Context.getVelocityEngine().getProperty("web.url"));