aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/notificators
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-11 08:28:41 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-11 08:28:41 -0700
commita401b40ee3b69d5679031a1e1d7287a0a56f4160 (patch)
tree30b0a1dfdc6b396dcb12947f19307b749e531446 /src/main/java/org/traccar/notificators
parent5b269c0e309b70866ad167fb148eafcbad5a8b26 (diff)
downloadtrackermap-server-a401b40ee3b69d5679031a1e1d7287a0a56f4160.tar.gz
trackermap-server-a401b40ee3b69d5679031a1e1d7287a0a56f4160.tar.bz2
trackermap-server-a401b40ee3b69d5679031a1e1d7287a0a56f4160.zip
Inject velocity engine
Diffstat (limited to 'src/main/java/org/traccar/notificators')
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorFirebase.java14
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorMail.java11
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorPushover.java9
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorSms.java12
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorTelegram.java9
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorTraccar.java6
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorWeb.java9
7 files changed, 31 insertions, 39 deletions
diff --git a/src/main/java/org/traccar/notificators/NotificatorFirebase.java b/src/main/java/org/traccar/notificators/NotificatorFirebase.java
index 3f1667568..5787b7ef2 100644
--- a/src/main/java/org/traccar/notificators/NotificatorFirebase.java
+++ b/src/main/java/org/traccar/notificators/NotificatorFirebase.java
@@ -23,7 +23,6 @@ import org.traccar.model.Event;
import org.traccar.model.Position;
import org.traccar.model.User;
import org.traccar.notification.NotificationFormatter;
-import org.traccar.session.cache.CacheManager;
import javax.inject.Inject;
import javax.ws.rs.client.Client;
@@ -31,7 +30,7 @@ import javax.ws.rs.client.Entity;
public class NotificatorFirebase implements Notificator {
- private final CacheManager cacheManager;
+ private final NotificationFormatter notificationFormatter;
private final Client client;
private final String url;
@@ -54,14 +53,15 @@ public class NotificatorFirebase implements Notificator {
}
@Inject
- public NotificatorFirebase(Config config, CacheManager cacheManager, Client client) {
+ public NotificatorFirebase(Config config, NotificationFormatter notificationFormatter, Client client) {
this(
- cacheManager, client, "https://fcm.googleapis.com/fcm/send",
+ notificationFormatter, client, "https://fcm.googleapis.com/fcm/send",
config.getString(Keys.NOTIFICATOR_FIREBASE_KEY));
}
- protected NotificatorFirebase(CacheManager cacheManager, Client client, String url, String key) {
- this.cacheManager = cacheManager;
+ protected NotificatorFirebase(
+ NotificationFormatter notificationFormatter, Client client, String url, String key) {
+ this.notificationFormatter = notificationFormatter;
this.client = client;
this.url = url;
this.key = key;
@@ -71,7 +71,7 @@ public class NotificatorFirebase implements Notificator {
public void send(User user, Event event, Position position) {
if (user.getAttributes().containsKey("notificationTokens")) {
- var shortMessage = NotificationFormatter.formatMessage(cacheManager, user, event, position, "short");
+ var shortMessage = notificationFormatter.formatMessage(user, event, position, "short");
Notification notification = new Notification();
notification.title = shortMessage.getSubject();
diff --git a/src/main/java/org/traccar/notificators/NotificatorMail.java b/src/main/java/org/traccar/notificators/NotificatorMail.java
index fe8d69af2..647832166 100644
--- a/src/main/java/org/traccar/notificators/NotificatorMail.java
+++ b/src/main/java/org/traccar/notificators/NotificatorMail.java
@@ -20,10 +20,8 @@ import org.traccar.database.MailManager;
import org.traccar.model.Event;
import org.traccar.model.Position;
import org.traccar.model.User;
-import org.traccar.notification.NotificationMessage;
import org.traccar.notification.MessageException;
import org.traccar.notification.NotificationFormatter;
-import org.traccar.session.cache.CacheManager;
import javax.inject.Inject;
import javax.mail.MessagingException;
@@ -31,19 +29,18 @@ import javax.mail.MessagingException;
public class NotificatorMail implements Notificator {
private final MailManager mailManager;
- private final CacheManager cacheManager;
+ private final NotificationFormatter notificationFormatter;
@Inject
- public NotificatorMail(MailManager mailManager, CacheManager cacheManager) {
+ public NotificatorMail(MailManager mailManager, NotificationFormatter notificationFormatter) {
this.mailManager = mailManager;
- this.cacheManager = cacheManager;
+ this.notificationFormatter = notificationFormatter;
}
@Override
public void send(User user, Event event, Position position) throws MessageException {
try {
- NotificationMessage fullMessage = NotificationFormatter.formatMessage(
- cacheManager, user, event, position, "full");
+ var fullMessage = notificationFormatter.formatMessage(user, event, position, "full");
mailManager.sendMessage(user, fullMessage.getSubject(), fullMessage.getBody());
} catch (MessagingException e) {
throw new MessageException(e);
diff --git a/src/main/java/org/traccar/notificators/NotificatorPushover.java b/src/main/java/org/traccar/notificators/NotificatorPushover.java
index 2ac489dd6..32ceae780 100644
--- a/src/main/java/org/traccar/notificators/NotificatorPushover.java
+++ b/src/main/java/org/traccar/notificators/NotificatorPushover.java
@@ -22,7 +22,6 @@ import org.traccar.model.Event;
import org.traccar.model.Position;
import org.traccar.model.User;
import org.traccar.notification.NotificationFormatter;
-import org.traccar.session.cache.CacheManager;
import javax.inject.Inject;
import javax.ws.rs.client.Client;
@@ -30,7 +29,7 @@ import javax.ws.rs.client.Entity;
public class NotificatorPushover implements Notificator {
- private final CacheManager cacheManager;
+ private final NotificationFormatter notificationFormatter;
private final Client client;
private final String url;
@@ -51,8 +50,8 @@ public class NotificatorPushover implements Notificator {
}
@Inject
- public NotificatorPushover(Config config, CacheManager cacheManager, Client client) {
- this.cacheManager = cacheManager;
+ public NotificatorPushover(Config config, NotificationFormatter notificationFormatter, Client client) {
+ this.notificationFormatter = notificationFormatter;
this.client = client;
url = "https://api.pushover.net/1/messages.json";
token = config.getString(Keys.NOTIFICATOR_PUSHOVER_TOKEN);
@@ -70,7 +69,7 @@ public class NotificatorPushover implements Notificator {
device = user.getString("notificator.pushover.device").replaceAll(" *, *", ",");
}
- var shortMessage = NotificationFormatter.formatMessage(cacheManager, user, event, position, "short");
+ var shortMessage = notificationFormatter.formatMessage(user, event, position, "short");
Message message = new Message();
message.token = token;
diff --git a/src/main/java/org/traccar/notificators/NotificatorSms.java b/src/main/java/org/traccar/notificators/NotificatorSms.java
index f4d1de0cb..544b67a5e 100644
--- a/src/main/java/org/traccar/notificators/NotificatorSms.java
+++ b/src/main/java/org/traccar/notificators/NotificatorSms.java
@@ -22,8 +22,6 @@ import org.traccar.model.Position;
import org.traccar.model.User;
import org.traccar.notification.MessageException;
import org.traccar.notification.NotificationFormatter;
-import org.traccar.notification.NotificationMessage;
-import org.traccar.session.cache.CacheManager;
import org.traccar.sms.SmsManager;
import javax.inject.Inject;
@@ -31,21 +29,21 @@ import javax.inject.Inject;
public class NotificatorSms implements Notificator {
private final SmsManager smsManager;
- private final CacheManager cacheManager;
+ private final NotificationFormatter notificationFormatter;
private final StatisticsManager statisticsManager;
@Inject
- public NotificatorSms(SmsManager smsManager, CacheManager cacheManager, StatisticsManager statisticsManager) {
+ public NotificatorSms(
+ SmsManager smsManager, NotificationFormatter notificationFormatter, StatisticsManager statisticsManager) {
this.smsManager = smsManager;
- this.cacheManager = cacheManager;
+ this.notificationFormatter = notificationFormatter;
this.statisticsManager = statisticsManager;
}
@Override
public void send(User user, Event event, Position position) throws MessageException, InterruptedException {
if (user.getPhone() != null) {
- NotificationMessage shortMessage = NotificationFormatter.formatMessage(
- cacheManager, user, event, position, "short");
+ var shortMessage = notificationFormatter.formatMessage(user, event, position, "short");
statisticsManager.registerSms();
smsManager.sendMessage(user.getPhone(), shortMessage.getBody(), false);
}
diff --git a/src/main/java/org/traccar/notificators/NotificatorTelegram.java b/src/main/java/org/traccar/notificators/NotificatorTelegram.java
index 1dccf2c04..a00cd36f1 100644
--- a/src/main/java/org/traccar/notificators/NotificatorTelegram.java
+++ b/src/main/java/org/traccar/notificators/NotificatorTelegram.java
@@ -23,7 +23,6 @@ import org.traccar.model.Event;
import org.traccar.model.Position;
import org.traccar.model.User;
import org.traccar.notification.NotificationFormatter;
-import org.traccar.session.cache.CacheManager;
import javax.inject.Inject;
import javax.ws.rs.client.Client;
@@ -31,7 +30,7 @@ import javax.ws.rs.client.Entity;
public class NotificatorTelegram implements Notificator {
- private final CacheManager cacheManager;
+ private final NotificationFormatter notificationFormatter;
private final Client client;
private final String urlSendText;
@@ -62,8 +61,8 @@ public class NotificatorTelegram implements Notificator {
}
@Inject
- public NotificatorTelegram(Config config, CacheManager cacheManager, Client client) {
- this.cacheManager = cacheManager;
+ public NotificatorTelegram(Config config, NotificationFormatter notificationFormatter, Client client) {
+ this.notificationFormatter = notificationFormatter;
this.client = client;
urlSendText = String.format(
"https://api.telegram.org/bot%s/sendMessage", config.getString(Keys.NOTIFICATOR_TELEGRAM_KEY));
@@ -85,7 +84,7 @@ public class NotificatorTelegram implements Notificator {
@Override
public void send(User user, Event event, Position position) {
- var shortMessage = NotificationFormatter.formatMessage(cacheManager, user, event, position, "short");
+ var shortMessage = notificationFormatter.formatMessage(user, event, position, "short");
TextMessage message = new TextMessage();
message.chatId = user.getString("telegramChatId");
diff --git a/src/main/java/org/traccar/notificators/NotificatorTraccar.java b/src/main/java/org/traccar/notificators/NotificatorTraccar.java
index 0827567ae..8f1260e96 100644
--- a/src/main/java/org/traccar/notificators/NotificatorTraccar.java
+++ b/src/main/java/org/traccar/notificators/NotificatorTraccar.java
@@ -17,7 +17,7 @@ package org.traccar.notificators;
import org.traccar.config.Config;
import org.traccar.config.Keys;
-import org.traccar.session.cache.CacheManager;
+import org.traccar.notification.NotificationFormatter;
import javax.inject.Inject;
import javax.ws.rs.client.Client;
@@ -25,9 +25,9 @@ import javax.ws.rs.client.Client;
public class NotificatorTraccar extends NotificatorFirebase {
@Inject
- public NotificatorTraccar(Config config, CacheManager cacheManager, Client client) {
+ public NotificatorTraccar(Config config, NotificationFormatter notificationFormatter, Client client) {
super(
- cacheManager, client, "https://www.traccar.org/push/",
+ notificationFormatter, client, "https://www.traccar.org/push/",
config.getString(Keys.NOTIFICATOR_TRACCAR_KEY));
}
diff --git a/src/main/java/org/traccar/notificators/NotificatorWeb.java b/src/main/java/org/traccar/notificators/NotificatorWeb.java
index 402f7a9f0..3d899584d 100644
--- a/src/main/java/org/traccar/notificators/NotificatorWeb.java
+++ b/src/main/java/org/traccar/notificators/NotificatorWeb.java
@@ -21,19 +21,18 @@ import org.traccar.model.Position;
import org.traccar.model.User;
import org.traccar.notification.NotificationFormatter;
import org.traccar.session.ConnectionManager;
-import org.traccar.session.cache.CacheManager;
import javax.inject.Inject;
public final class NotificatorWeb implements Notificator {
private final ConnectionManager connectionManager;
- private final CacheManager cacheManager;
+ private final NotificationFormatter notificationFormatter;
@Inject
- public NotificatorWeb(ConnectionManager connectionManager, CacheManager cacheManager) {
+ public NotificatorWeb(ConnectionManager connectionManager, NotificationFormatter notificationFormatter) {
this.connectionManager = connectionManager;
- this.cacheManager = cacheManager;
+ this.notificationFormatter = notificationFormatter;
}
@Override
@@ -49,7 +48,7 @@ public final class NotificatorWeb implements Notificator {
copy.setMaintenanceId(event.getMaintenanceId());
copy.getAttributes().putAll(event.getAttributes());
- var message = NotificationFormatter.formatMessage(cacheManager, user, event, position, "short");
+ var message = notificationFormatter.formatMessage(user, event, position, "short");
copy.set("message", message.getBody());
connectionManager.updateEvent(user.getId(), copy);