diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-04 10:38:49 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-04 10:38:49 -0700 |
commit | 8c12ded81c5dce295fcb229c566209d784f55356 (patch) | |
tree | 335f01a30f5c26dc1d5cf24c2c5dfded074a1cd1 /src/main/java/org/traccar/notification | |
parent | fd84b0dcb86208c2c9c64fbe067cf7d4324892ac (diff) | |
download | trackermap-server-8c12ded81c5dce295fcb229c566209d784f55356.tar.gz trackermap-server-8c12ded81c5dce295fcb229c566209d784f55356.tar.bz2 trackermap-server-8c12ded81c5dce295fcb229c566209d784f55356.zip |
Remove maintenance manager
Diffstat (limited to 'src/main/java/org/traccar/notification')
-rw-r--r-- | src/main/java/org/traccar/notification/EventForwarder.java | 20 | ||||
-rw-r--r-- | src/main/java/org/traccar/notification/NotificationFormatter.java | 21 |
2 files changed, 23 insertions, 18 deletions
diff --git a/src/main/java/org/traccar/notification/EventForwarder.java b/src/main/java/org/traccar/notification/EventForwarder.java index c908fedbd..b0494d74d 100644 --- a/src/main/java/org/traccar/notification/EventForwarder.java +++ b/src/main/java/org/traccar/notification/EventForwarder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2020 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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. @@ -18,12 +18,15 @@ package org.traccar.notification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.traccar.Context; +import org.traccar.Main; +import org.traccar.config.Config; import org.traccar.config.Keys; 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.session.cache.CacheManager; import javax.ws.rs.client.Entity; import javax.ws.rs.client.Invocation; @@ -39,9 +42,12 @@ public class EventForwarder { private final String url; private final String header; - public EventForwarder() { - url = Context.getConfig().getString(Keys.EVENT_FORWARD_URL); - header = Context.getConfig().getString(Keys.EVENT_FORWARD_HEADERS); + private final CacheManager cacheManager; + + public EventForwarder(Config config) { + url = config.getString(Keys.EVENT_FORWARD_URL); + header = config.getString(Keys.EVENT_FORWARD_HEADERS); + cacheManager = Main.getInjector().getInstance(CacheManager.class); } private static final String KEY_POSITION = "position"; @@ -83,18 +89,18 @@ public class EventForwarder { if (position != null) { data.put(KEY_POSITION, position); } - Device device = Context.getIdentityManager().getById(event.getDeviceId()); + Device device = cacheManager.getObject(Device.class, event.getDeviceId()); if (device != null) { data.put(KEY_DEVICE, device); } if (event.getGeofenceId() != 0) { - Geofence geofence = Context.getGeofenceManager().getById(event.getGeofenceId()); + Geofence geofence = cacheManager.getObject(Geofence.class, event.getGeofenceId()); if (geofence != null) { data.put(KEY_GEOFENCE, geofence); } } if (event.getMaintenanceId() != 0) { - Maintenance maintenance = Context.getMaintenancesManager().getById(event.getMaintenanceId()); + Maintenance maintenance = cacheManager.getObject(Maintenance.class, event.getMaintenanceId()); if (maintenance != null) { data.put(KEY_MAINTENANCE, maintenance); } diff --git a/src/main/java/org/traccar/notification/NotificationFormatter.java b/src/main/java/org/traccar/notification/NotificationFormatter.java index 9a6723a71..107426e06 100644 --- a/src/main/java/org/traccar/notification/NotificationFormatter.java +++ b/src/main/java/org/traccar/notification/NotificationFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2021 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org) * Copyright 2017 - 2018 Andrey Kunitsyn (andrey@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,19 +20,23 @@ import org.apache.velocity.VelocityContext; import org.traccar.Context; 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.User; import org.traccar.reports.ReportUtils; +import org.traccar.session.cache.CacheManager; public final class NotificationFormatter { private NotificationFormatter() { } - public static VelocityContext prepareContext(long userId, Event event, Position position) { + public static NotificationMessage formatMessage( + CacheManager cacheManager, long userId, Event event, Position position, String templatePath) { - User user = Context.getPermissionsManager().getUser(userId); - Device device = Context.getIdentityManager().getById(event.getDeviceId()); + User user = cacheManager.getObject(User.class, userId); + Device device = cacheManager.getObject(Device.class, event.getDeviceId()); VelocityContext velocityContext = TextTemplateFormatter.prepareContext(user); @@ -45,21 +49,16 @@ public final class NotificationFormatter { velocityContext.put("volumeUnit", ReportUtils.getVolumeUnit(userId)); } if (event.getGeofenceId() != 0) { - velocityContext.put("geofence", Context.getGeofenceManager().getById(event.getGeofenceId())); + velocityContext.put("geofence", cacheManager.getObject(Geofence.class, event.getGeofenceId())); } if (event.getMaintenanceId() != 0) { - velocityContext.put("maintenance", Context.getMaintenancesManager().getById(event.getMaintenanceId())); + velocityContext.put("maintenance", cacheManager.getObject(Maintenance.class, event.getMaintenanceId())); } String driverUniqueId = event.getString(Position.KEY_DRIVER_UNIQUE_ID); if (driverUniqueId != null) { velocityContext.put("driver", Context.getDriversManager().getDriverByUniqueId(driverUniqueId)); } - return velocityContext; - } - - public static NotificationMessage formatMessage(long userId, Event event, Position position, String templatePath) { - VelocityContext velocityContext = prepareContext(userId, event, position); return TextTemplateFormatter.formatMessage(velocityContext, event.getType(), templatePath); } |