aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2018-06-26 12:05:16 +0500
committerAbyss777 <abyss@fox5.ru>2018-06-26 12:05:16 +0500
commit825ee0d178a24620f075cb4ffb8d49c75b046484 (patch)
tree2bc60aaea8d4c1eff707ae6e0b8ff558d45d15dc /src
parentaba402226403f8b3eb58cc01e8f536eb4104d35a (diff)
downloadtrackermap-server-825ee0d178a24620f075cb4ffb8d49c75b046484.tar.gz
trackermap-server-825ee0d178a24620f075cb4ffb8d49c75b046484.tar.bz2
trackermap-server-825ee0d178a24620f075cb4ffb8d49c75b046484.zip
Cleanup and some adjustments
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/api/resource/NotificationResource.java9
-rw-r--r--src/org/traccar/database/NotificationManager.java5
-rw-r--r--src/org/traccar/model/Notification.java18
-rw-r--r--src/org/traccar/notification/NotificationException.java4
-rw-r--r--src/org/traccar/notification/NotificationMail.java4
-rw-r--r--src/org/traccar/notification/NotificationNull.java4
-rw-r--r--src/org/traccar/notification/NotificationSms.java4
-rw-r--r--src/org/traccar/notification/NotificationWeb.java4
-rw-r--r--src/org/traccar/notification/Notificator.java4
-rw-r--r--src/org/traccar/notification/NotificatorManager.java26
-rw-r--r--src/org/traccar/sms/SMSException.java4
-rw-r--r--src/org/traccar/sms/SMSManager.java16
12 files changed, 67 insertions, 35 deletions
diff --git a/src/org/traccar/api/resource/NotificationResource.java b/src/org/traccar/api/resource/NotificationResource.java
index 2347b43fa..9046569a0 100644
--- a/src/org/traccar/api/resource/NotificationResource.java
+++ b/src/org/traccar/api/resource/NotificationResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 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.
@@ -52,8 +52,9 @@ public class NotificationResource extends ExtendedObjectResource<Notification> {
@POST
@Path("test")
public Response testMessage() throws NotificationException, InterruptedException {
- for (String method : Context.getNotificatorManager().getNotificatorTypes()) {
- Context.getNotificatorManager().getNotificator(method).sendSync(getUserId(), new Event("test", 0), null);
+ for (Typed method : Context.getNotificatorManager().getNotificatorTypes()) {
+ Context.getNotificatorManager()
+ .getNotificator(method.getType()).sendSync(getUserId(), new Event("test", 0), null);
}
return Response.noContent().build();
}
@@ -68,7 +69,7 @@ public class NotificationResource extends ExtendedObjectResource<Notification> {
@GET
@Path("notificators")
- public Collection<String> getNotificators() {
+ public Collection<Typed> getNotificators() {
return Context.getNotificatorManager().getNotificatorTypes();
}
diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java
index 2c1ffc09c..b2a30e4f1 100644
--- a/src/org/traccar/database/NotificationManager.java
+++ b/src/org/traccar/database/NotificationManager.java
@@ -90,8 +90,9 @@ public class NotificationManager extends ExtendedObjectManager<Notification> {
notificationMethods.addAll(notification.getTransportMethods());
}
}
- for (String nm : notificationMethods) {
- Context.getNotificatorManager().getNotificator(nm).sendAsync(userId, event, position);
+ for (String notificationMethod : notificationMethods) {
+ Context.getNotificatorManager()
+ .getNotificator(notificationMethod).sendAsync(userId, event, position);
}
}
}
diff --git a/src/org/traccar/model/Notification.java b/src/org/traccar/model/Notification.java
index 0b632c861..4923798c2 100644
--- a/src/org/traccar/model/Notification.java
+++ b/src/org/traccar/model/Notification.java
@@ -18,6 +18,10 @@ package org.traccar.model;
import java.util.HashSet;
import java.util.Set;
+import org.traccar.database.QueryIgnore;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
public class Notification extends ScheduledModel {
private boolean always;
@@ -52,13 +56,17 @@ public class Notification extends ScheduledModel {
}
+ @JsonIgnore
+ @QueryIgnore
public Set<String> getTransportMethods() {
- final Set<String> set = new HashSet<>();
- final String[] tmp = transports.split(",");
- for (String t : tmp) {
- set.add(t.trim());
+ final Set<String> result = new HashSet<>();
+ if (transports != null) {
+ final String[] transportsList = transports.split(",");
+ for (String transport : transportsList) {
+ result.add(transport.trim());
+ }
}
- return set;
+ return result;
}
}
diff --git a/src/org/traccar/notification/NotificationException.java b/src/org/traccar/notification/NotificationException.java
index 34d5a80f7..525e5ee37 100644
--- a/src/org/traccar/notification/NotificationException.java
+++ b/src/org/traccar/notification/NotificationException.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/org/traccar/notification/NotificationMail.java b/src/org/traccar/notification/NotificationMail.java
index fb89bf5bd..76387c73b 100644
--- a/src/org/traccar/notification/NotificationMail.java
+++ b/src/org/traccar/notification/NotificationMail.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/org/traccar/notification/NotificationNull.java b/src/org/traccar/notification/NotificationNull.java
index fd7950a80..3ee954c24 100644
--- a/src/org/traccar/notification/NotificationNull.java
+++ b/src/org/traccar/notification/NotificationNull.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/org/traccar/notification/NotificationSms.java b/src/org/traccar/notification/NotificationSms.java
index 63fd57895..dd3304d85 100644
--- a/src/org/traccar/notification/NotificationSms.java
+++ b/src/org/traccar/notification/NotificationSms.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/org/traccar/notification/NotificationWeb.java b/src/org/traccar/notification/NotificationWeb.java
index c6a1ae281..8e04fc2c4 100644
--- a/src/org/traccar/notification/NotificationWeb.java
+++ b/src/org/traccar/notification/NotificationWeb.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/org/traccar/notification/Notificator.java b/src/org/traccar/notification/Notificator.java
index 7192d25c0..09f98d3ad 100644
--- a/src/org/traccar/notification/Notificator.java
+++ b/src/org/traccar/notification/Notificator.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/org/traccar/notification/NotificatorManager.java b/src/org/traccar/notification/NotificatorManager.java
index 20c7749d2..87a294345 100644
--- a/src/org/traccar/notification/NotificatorManager.java
+++ b/src/org/traccar/notification/NotificatorManager.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,11 +19,13 @@ package org.traccar.notification;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.traccar.Context;
import org.traccar.helper.Log;
+import org.traccar.model.Typed;
public final class NotificatorManager {
@@ -33,13 +35,13 @@ public final class NotificatorManager {
final String className = Context.getConfig().getString("notificator." + type + ".class", "");
if (className.length() > 0) {
try {
- final Class<Notificator> c = (Class<Notificator>) Class.forName(className);
+ final Class<Notificator> clazz = (Class<Notificator>) Class.forName(className);
try {
- final Constructor<Notificator> constructor = c.getConstructor(new Class[]{String.class});
+ final Constructor<Notificator> constructor = clazz.getConstructor(new Class[]{String.class});
notificators.put(type, constructor.newInstance(type));
} catch (NoSuchMethodException e) {
// No constructor with String argument
- notificators.put(type, c.newInstance());
+ notificators.put(type, clazz.newInstance());
}
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException | InvocationTargetException e) {
@@ -53,17 +55,21 @@ public final class NotificatorManager {
private static final Notificator NULL_NOTIFICATOR = new NotificationNull();
public Notificator getNotificator(String type) {
- final Notificator n = notificators.get(type);
- if (n == null) {
+ final Notificator notificator = notificators.get(type);
+ if (notificator == null) {
Log.error("No notificator configured for type : " + type);
return NULL_NOTIFICATOR;
}
- return n;
+ return notificator;
}
- public Set<String> getNotificatorTypes() {
- return notificators.keySet();
+ public Set<Typed> getNotificatorTypes() {
+ Set<Typed> result = new HashSet<>();
+ for (String notificator : notificators.keySet()) {
+ result.add(new Typed(notificator));
+ }
+ return result;
}
diff --git a/src/org/traccar/sms/SMSException.java b/src/org/traccar/sms/SMSException.java
index c9c0b3128..22ca95296 100644
--- a/src/org/traccar/sms/SMSException.java
+++ b/src/org/traccar/sms/SMSException.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/org/traccar/sms/SMSManager.java b/src/org/traccar/sms/SMSManager.java
index b40dae867..c4cb68fb7 100644
--- a/src/org/traccar/sms/SMSManager.java
+++ b/src/org/traccar/sms/SMSManager.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.traccar.sms;
public interface SMSManager {