aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/notification
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-09 17:56:37 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-09 17:56:37 -0700
commitadafc5f6130854dd88c191dd04489073419ee41d (patch)
treee101d03069894f9a2fbfd388d9b3f93424cbe4d0 /src/main/java/org/traccar/notification
parent29b5d05cfd66a9f51b7ce272c1fb07077bc715b2 (diff)
downloadtrackermap-server-adafc5f6130854dd88c191dd04489073419ee41d.tar.gz
trackermap-server-adafc5f6130854dd88c191dd04489073419ee41d.tar.bz2
trackermap-server-adafc5f6130854dd88c191dd04489073419ee41d.zip
Remove SMS from context
Diffstat (limited to 'src/main/java/org/traccar/notification')
-rw-r--r--src/main/java/org/traccar/notification/NotificatorManager.java56
1 files changed, 19 insertions, 37 deletions
diff --git a/src/main/java/org/traccar/notification/NotificatorManager.java b/src/main/java/org/traccar/notification/NotificatorManager.java
index dfd8cd3d6..9705377b4 100644
--- a/src/main/java/org/traccar/notification/NotificatorManager.java
+++ b/src/main/java/org/traccar/notification/NotificatorManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +24,8 @@ import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.Context;
+import org.traccar.Main;
+import org.traccar.config.Keys;
import org.traccar.model.Typed;
import org.traccar.notificators.NotificatorFirebase;
import org.traccar.notificators.NotificatorMail;
@@ -39,45 +41,25 @@ public final class NotificatorManager {
private static final Logger LOGGER = LoggerFactory.getLogger(NotificatorManager.class);
- private static final Notificator NULL_NOTIFICATOR = new NotificatorNull();
+ private static final Map<String, Class<? extends Notificator>> NOTIFICATORS_ALL = Map.of(
+ "web", NotificatorWeb.class,
+ "mail", NotificatorMail.class,
+ "sms", NotificatorSms.class,
+ "firebase", NotificatorFirebase.class,
+ "traccar", NotificatorTraccar.class,
+ "telegram", NotificatorTelegram.class,
+ "pushover", NotificatorPushover.class);
private final Map<String, Notificator> notificators = new HashMap<>();
public NotificatorManager() {
- final String[] types = Context.getConfig().getString("notificator.types", "").split(",");
- for (String type : types) {
- String defaultNotificator = "";
- switch (type) {
- case "web":
- defaultNotificator = NotificatorWeb.class.getCanonicalName();
- break;
- case "mail":
- defaultNotificator = NotificatorMail.class.getCanonicalName();
- break;
- case "sms":
- defaultNotificator = NotificatorSms.class.getCanonicalName();
- break;
- case "firebase":
- defaultNotificator = NotificatorFirebase.class.getCanonicalName();
- break;
- case "traccar":
- defaultNotificator = NotificatorTraccar.class.getCanonicalName();
- break;
- case "telegram":
- defaultNotificator = NotificatorTelegram.class.getCanonicalName();
- break;
- case "pushover":
- defaultNotificator = NotificatorPushover.class.getCanonicalName();
- break;
- default:
- break;
- }
- final String className = Context.getConfig()
- .getString("notificator." + type + ".class", defaultNotificator);
- try {
- notificators.put(type, (Notificator) Class.forName(className).newInstance());
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
- LOGGER.warn("Unable to load notificator class for " + type + " " + className + " " + e.getMessage());
+ String types = Context.getConfig().getString(Keys.NOTIFICATOR_TYPES);
+ if (types != null) {
+ for (String type : types.split(",")) {
+ var notificatorClass = NOTIFICATORS_ALL.get(type);
+ if (notificatorClass != null) {
+ notificators.put(type, Main.getInjector().getInstance(notificatorClass));
+ }
}
}
}
@@ -86,7 +68,7 @@ public final class NotificatorManager {
final Notificator notificator = notificators.get(type);
if (notificator == null) {
LOGGER.warn("No notificator configured for type : " + type);
- return NULL_NOTIFICATOR;
+ return new NotificatorNull();
}
return notificator;
}