aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/api/resource')
-rw-r--r--src/org/traccar/api/resource/DevicePermissionResource.java8
-rw-r--r--src/org/traccar/api/resource/DeviceResource.java11
-rw-r--r--src/org/traccar/api/resource/GroupPermissionResource.java8
-rw-r--r--src/org/traccar/api/resource/GroupResource.java11
-rw-r--r--src/org/traccar/api/resource/NotificationResource.java59
-rw-r--r--src/org/traccar/api/resource/UserResource.java21
6 files changed, 107 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..5bec7fd85
--- /dev/null
+++ b/src/org/traccar/api/resource/NotificationResource.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * 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.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();
}