diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-14 18:50:48 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-14 18:50:48 -0700 |
commit | 0d5c7606c73d84aab44f69936ab62afa0b68939b (patch) | |
tree | 4e9cbebe1ddcd3e3b75a15bee8e23d05374ca434 /src/main/java/org/traccar/api/resource | |
parent | 415ba3ddb0f770b829c997beb3e575ffb6e195ec (diff) | |
download | trackermap-server-0d5c7606c73d84aab44f69936ab62afa0b68939b.tar.gz trackermap-server-0d5c7606c73d84aab44f69936ab62afa0b68939b.tar.bz2 trackermap-server-0d5c7606c73d84aab44f69936ab62afa0b68939b.zip |
Refactor notification manager
Diffstat (limited to 'src/main/java/org/traccar/api/resource')
-rw-r--r-- | src/main/java/org/traccar/api/resource/NotificationResource.java | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/api/resource/NotificationResource.java b/src/main/java/org/traccar/api/resource/NotificationResource.java index 0a95b257a..a42de687d 100644 --- a/src/main/java/org/traccar/api/resource/NotificationResource.java +++ b/src/main/java/org/traccar/api/resource/NotificationResource.java @@ -15,7 +15,11 @@ */ package org.traccar.api.resource; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.Collection; +import java.util.HashSet; +import java.util.Set; import javax.inject.Inject; import javax.ws.rs.Consumes; @@ -27,7 +31,8 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.traccar.Context; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.api.ExtendedObjectResource; import org.traccar.model.Event; import org.traccar.model.Notification; @@ -42,6 +47,8 @@ import org.traccar.storage.StorageException; @Consumes(MediaType.APPLICATION_JSON) public class NotificationResource extends ExtendedObjectResource<Notification> { + private static final Logger LOGGER = LoggerFactory.getLogger(NotificationResource.class); + @Inject private NotificatorManager notificatorManager; @@ -52,7 +59,18 @@ public class NotificationResource extends ExtendedObjectResource<Notification> { @GET @Path("types") public Collection<Typed> get() { - return Context.getNotificationManager().getAllNotificationTypes(); + Set<Typed> types = new HashSet<>(); + Field[] fields = Event.class.getDeclaredFields(); + for (Field field : fields) { + if (Modifier.isStatic(field.getModifiers()) && field.getName().startsWith("TYPE_")) { + try { + types.add(new Typed(field.get(null).toString())); + } catch (IllegalArgumentException | IllegalAccessException error) { + LOGGER.warn("Get event types error", error); + } + } + } + return types; } @GET |