diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-11 08:28:41 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-11 08:28:41 -0700 |
commit | a401b40ee3b69d5679031a1e1d7287a0a56f4160 (patch) | |
tree | 30b0a1dfdc6b396dcb12947f19307b749e531446 /src/main/java/org/traccar/notification/NotificationFormatter.java | |
parent | 5b269c0e309b70866ad167fb148eafcbad5a8b26 (diff) | |
download | trackermap-server-a401b40ee3b69d5679031a1e1d7287a0a56f4160.tar.gz trackermap-server-a401b40ee3b69d5679031a1e1d7287a0a56f4160.tar.bz2 trackermap-server-a401b40ee3b69d5679031a1e1d7287a0a56f4160.zip |
Inject velocity engine
Diffstat (limited to 'src/main/java/org/traccar/notification/NotificationFormatter.java')
-rw-r--r-- | src/main/java/org/traccar/notification/NotificationFormatter.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/notification/NotificationFormatter.java b/src/main/java/org/traccar/notification/NotificationFormatter.java index 2d3b90412..fa244d9b4 100644 --- a/src/main/java/org/traccar/notification/NotificationFormatter.java +++ b/src/main/java/org/traccar/notification/NotificationFormatter.java @@ -27,18 +27,26 @@ import org.traccar.model.Server; import org.traccar.model.User; import org.traccar.session.cache.CacheManager; -public final class NotificationFormatter { +import javax.inject.Inject; - private NotificationFormatter() { +public class NotificationFormatter { + + private final CacheManager cacheManager; + private final TextTemplateFormatter textTemplateFormatter; + + @Inject + public NotificationFormatter( + CacheManager cacheManager, TextTemplateFormatter textTemplateFormatter) { + this.cacheManager = cacheManager; + this.textTemplateFormatter = textTemplateFormatter; } - public static NotificationMessage formatMessage( - CacheManager cacheManager, User user, Event event, Position position, String templatePath) { + public NotificationMessage formatMessage(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 velocityContext = textTemplateFormatter.prepareContext(server, user); velocityContext.put("device", device); velocityContext.put("event", event); @@ -59,7 +67,7 @@ public final class NotificationFormatter { velocityContext.put("driver", cacheManager.findDriverByUniqueId(device.getId(), driverUniqueId)); } - return TextTemplateFormatter.formatMessage(velocityContext, event.getType(), templatePath); + return textTemplateFormatter.formatMessage(velocityContext, event.getType(), templatePath); } } |