diff options
author | Abyss777 <abyss@fox5.ru> | 2016-06-26 00:51:33 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2016-06-26 00:51:33 +0500 |
commit | a25e7bd56c128fb2a1c673abf735b3e64706f9a8 (patch) | |
tree | a99d2cde526f97082d7bc95531772b6835064fcd /src/org/traccar/api/resource | |
parent | 67f46c80d3b5e34440a2644f52b81dddfbaba5fa (diff) | |
download | trackermap-server-a25e7bd56c128fb2a1c673abf735b3e64706f9a8.tar.gz trackermap-server-a25e7bd56c128fb2a1c673abf735b3e64706f9a8.tar.bz2 trackermap-server-a25e7bd56c128fb2a1c673abf735b3e64706f9a8.zip |
Added notifications via email
Added notifications settings
Diffstat (limited to 'src/org/traccar/api/resource')
6 files changed, 92 insertions, 11 deletions
diff --git a/src/org/traccar/api/resource/DevicePermissionResource.java b/src/org/traccar/api/resource/DevicePermissionResource.java index 2ef436f11..7de050074 100644 --- a/src/org/traccar/api/resource/DevicePermissionResource.java +++ b/src/org/traccar/api/resource/DevicePermissionResource.java @@ -38,7 +38,9 @@ public class DevicePermissionResource extends BaseResource { Context.getPermissionsManager().checkAdmin(getUserId()); Context.getDataManager().linkDevice(entity.getUserId(), entity.getDeviceId()); Context.getPermissionsManager().refresh(); - Context.getGeofenceManager().refresh(); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } return Response.ok(entity).build(); } @@ -47,7 +49,9 @@ public class DevicePermissionResource extends BaseResource { Context.getPermissionsManager().checkAdmin(getUserId()); Context.getDataManager().unlinkDevice(entity.getUserId(), entity.getDeviceId()); Context.getPermissionsManager().refresh(); - Context.getGeofenceManager().refresh(); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } return Response.noContent().build(); } diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java index d6032bb1e..d6c53dc04 100644 --- a/src/org/traccar/api/resource/DeviceResource.java +++ b/src/org/traccar/api/resource/DeviceResource.java @@ -60,7 +60,9 @@ public class DeviceResource extends BaseResource { Context.getDataManager().addDevice(entity); Context.getDataManager().linkDevice(getUserId(), entity.getId()); Context.getPermissionsManager().refresh(); - Context.getGeofenceManager().refresh(); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } return Response.ok(entity).build(); } @@ -70,6 +72,9 @@ public class DeviceResource extends BaseResource { Context.getPermissionsManager().checkReadonly(getUserId()); Context.getPermissionsManager().checkDevice(getUserId(), id); Context.getDataManager().updateDevice(entity); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } return Response.ok(entity).build(); } @@ -80,7 +85,9 @@ public class DeviceResource extends BaseResource { Context.getPermissionsManager().checkDevice(getUserId(), id); Context.getDataManager().removeDevice(id); Context.getPermissionsManager().refresh(); - Context.getGeofenceManager().refresh(); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } return Response.noContent().build(); } diff --git a/src/org/traccar/api/resource/GroupPermissionResource.java b/src/org/traccar/api/resource/GroupPermissionResource.java index 564a379d2..1fbf37a2b 100644 --- a/src/org/traccar/api/resource/GroupPermissionResource.java +++ b/src/org/traccar/api/resource/GroupPermissionResource.java @@ -38,7 +38,9 @@ public class GroupPermissionResource extends BaseResource { Context.getPermissionsManager().checkAdmin(getUserId()); Context.getDataManager().linkGroup(entity.getUserId(), entity.getGroupId()); Context.getPermissionsManager().refresh(); - Context.getGeofenceManager().refresh(); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } return Response.ok(entity).build(); } @@ -47,7 +49,9 @@ public class GroupPermissionResource extends BaseResource { Context.getPermissionsManager().checkAdmin(getUserId()); Context.getDataManager().unlinkGroup(entity.getUserId(), entity.getGroupId()); Context.getPermissionsManager().refresh(); - Context.getGeofenceManager().refresh(); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } return Response.noContent().build(); } diff --git a/src/org/traccar/api/resource/GroupResource.java b/src/org/traccar/api/resource/GroupResource.java index dda9ab03b..957f39ebe 100644 --- a/src/org/traccar/api/resource/GroupResource.java +++ b/src/org/traccar/api/resource/GroupResource.java @@ -59,7 +59,9 @@ public class GroupResource extends BaseResource { Context.getDataManager().addGroup(entity); Context.getDataManager().linkGroup(getUserId(), entity.getId()); Context.getPermissionsManager().refresh(); - Context.getGeofenceManager().refresh(); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } return Response.ok(entity).build(); } @@ -69,6 +71,9 @@ public class GroupResource extends BaseResource { Context.getPermissionsManager().checkReadonly(getUserId()); Context.getPermissionsManager().checkGroup(getUserId(), id); Context.getDataManager().updateGroup(entity); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } return Response.ok(entity).build(); } @@ -79,7 +84,9 @@ public class GroupResource extends BaseResource { Context.getPermissionsManager().checkGroup(getUserId(), id); Context.getDataManager().removeGroup(id); Context.getPermissionsManager().refresh(); - Context.getGeofenceManager().refresh(); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } return Response.noContent().build(); } diff --git a/src/org/traccar/api/resource/NotificationResource.java b/src/org/traccar/api/resource/NotificationResource.java new file mode 100644 index 000000000..236e352e1 --- /dev/null +++ b/src/org/traccar/api/resource/NotificationResource.java @@ -0,0 +1,44 @@ +package org.traccar.api.resource;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.traccar.Context;
+import org.traccar.api.BaseResource;
+import org.traccar.model.Notification;
+
+@Path("users/notifications")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class NotificationResource extends BaseResource {
+
+ @GET
+ public Collection<Notification> get(@QueryParam("all") boolean all,
+ @QueryParam("userId") long userId) throws SQLException {
+ if (all) {
+ return Context.getNotificationManager().getAllNotifications();
+ }
+ if (userId == 0) {
+ userId = getUserId();
+ }
+ Context.getPermissionsManager().checkUser(getUserId(), userId);
+ return Context.getNotificationManager().getUserNotifications(userId);
+ }
+
+ @POST
+ public Response update(Notification entity) throws SQLException {
+ Context.getPermissionsManager().checkReadonly(getUserId());
+ Context.getPermissionsManager().checkUser(getUserId(), entity.getUserId());
+ Context.getNotificationManager().updateNotification(entity);
+ return Response.ok(entity).build();
+ }
+}
diff --git a/src/org/traccar/api/resource/UserResource.java b/src/org/traccar/api/resource/UserResource.java index 7cc4ed09a..cfe338b56 100644 --- a/src/org/traccar/api/resource/UserResource.java +++ b/src/org/traccar/api/resource/UserResource.java @@ -52,7 +52,12 @@ public class UserResource extends BaseResource { } Context.getDataManager().addUser(entity); Context.getPermissionsManager().refresh(); - Context.getGeofenceManager().refresh(); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } + if (Context.getNotificationManager() != null) { + Context.getNotificationManager().refresh(); + } return Response.ok(entity).build(); } @@ -66,7 +71,12 @@ public class UserResource extends BaseResource { } Context.getDataManager().updateUser(entity); Context.getPermissionsManager().refresh(); - Context.getGeofenceManager().refresh(); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } + if (Context.getNotificationManager() != null) { + Context.getNotificationManager().refresh(); + } return Response.ok(entity).build(); } @@ -76,7 +86,12 @@ public class UserResource extends BaseResource { Context.getPermissionsManager().checkUser(getUserId(), id); Context.getDataManager().removeUser(id); Context.getPermissionsManager().refresh(); - Context.getGeofenceManager().refresh(); + if (Context.getGeofenceManager() != null) { + Context.getGeofenceManager().refresh(); + } + if (Context.getNotificationManager() != null) { + Context.getNotificationManager().refresh(); + } return Response.noContent().build(); } |