aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-14 18:50:48 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-14 18:50:48 -0700
commit0d5c7606c73d84aab44f69936ab62afa0b68939b (patch)
tree4e9cbebe1ddcd3e3b75a15bee8e23d05374ca434 /src/main/java/org/traccar/api
parent415ba3ddb0f770b829c997beb3e575ffb6e195ec (diff)
downloadtrackermap-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')
-rw-r--r--src/main/java/org/traccar/api/BaseObjectResource.java10
-rw-r--r--src/main/java/org/traccar/api/resource/NotificationResource.java22
2 files changed, 20 insertions, 12 deletions
diff --git a/src/main/java/org/traccar/api/BaseObjectResource.java b/src/main/java/org/traccar/api/BaseObjectResource.java
index cc930c591..aa777f3f6 100644
--- a/src/main/java/org/traccar/api/BaseObjectResource.java
+++ b/src/main/java/org/traccar/api/BaseObjectResource.java
@@ -22,7 +22,6 @@ import org.traccar.database.ExtendedObjectManager;
import org.traccar.database.SimpleObjectManager;
import org.traccar.helper.LogAction;
import org.traccar.model.BaseModel;
-import org.traccar.model.Calendar;
import org.traccar.model.Device;
import org.traccar.model.Group;
import org.traccar.model.Permission;
@@ -87,7 +86,6 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
((SimpleObjectManager<T>) manager).refreshUserItems();
} else if (baseClass.equals(Group.class) || baseClass.equals(Device.class)) {
Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
- Context.getPermissionsManager().refreshAllExtendedPermissions();
}
return Response.ok(entity).build();
}
@@ -112,7 +110,6 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
if (baseClass.equals(Group.class) || baseClass.equals(Device.class)) {
Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
- Context.getPermissionsManager().refreshAllExtendedPermissions();
}
return Response.ok(entity).build();
}
@@ -145,13 +142,6 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
Context.getDeviceManager().updateDeviceCache(true);
}
Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
- if (baseClass.equals(User.class)) {
- Context.getPermissionsManager().refreshAllUsersPermissions();
- } else {
- Context.getPermissionsManager().refreshAllExtendedPermissions();
- }
- } else if (baseClass.equals(Calendar.class)) {
- Context.getNotificationManager().refreshItems();
}
return Response.noContent().build();
}
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