aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource/DeviceResource.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-07-20 08:56:29 +0500
committerAbyss777 <abyss@fox5.ru>2017-07-20 09:52:27 +0500
commitafb9a199f57824ec06c993b6028c35b616f64885 (patch)
tree1ab2531846dc1ff4c9b5e0d6d71ebcec231aff89 /src/org/traccar/api/resource/DeviceResource.java
parenta9478ded48de140d47d17def1ee5329267fe6088 (diff)
downloadtrackermap-server-afb9a199f57824ec06c993b6028c35b616f64885.tar.gz
trackermap-server-afb9a199f57824ec06c993b6028c35b616f64885.tar.bz2
trackermap-server-afb9a199f57824ec06c993b6028c35b616f64885.zip
Combine permission resources and reuse common database functions
Diffstat (limited to 'src/org/traccar/api/resource/DeviceResource.java')
-rw-r--r--src/org/traccar/api/resource/DeviceResource.java45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java
index ce46b4e29..41a8970e2 100644
--- a/src/org/traccar/api/resource/DeviceResource.java
+++ b/src/org/traccar/api/resource/DeviceResource.java
@@ -35,7 +35,9 @@ import javax.ws.rs.core.Response;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
@Path("devices")
@Produces(MediaType.APPLICATION_JSON)
@@ -77,11 +79,12 @@ public class DeviceResource extends BaseResource {
Context.getPermissionsManager().checkDeviceReadonly(getUserId());
Context.getPermissionsManager().checkDeviceLimit(getUserId());
Context.getDeviceManager().addDevice(entity);
- Context.getDataManager().linkDevice(getUserId(), entity.getId());
+ LinkedHashMap<String, Long> link = new LinkedHashMap<>();
+ link.put("userId", getUserId());
+ link.put("deviceId", entity.getId());
+ Context.getDataManager().linkObject(link, true);
Context.getPermissionsManager().refreshPermissions();
- if (Context.getGeofenceManager() != null) {
- Context.getGeofenceManager().refresh();
- }
+ Context.getPermissionsManager().refreshAllExtendedPermissions();
return Response.ok(entity).build();
}
@@ -93,13 +96,11 @@ public class DeviceResource extends BaseResource {
Context.getPermissionsManager().checkDevice(getUserId(), entity.getId());
Context.getDeviceManager().updateDevice(entity);
Context.getPermissionsManager().refreshPermissions();
- if (Context.getGeofenceManager() != null) {
- Context.getGeofenceManager().refresh();
- }
+ Context.getPermissionsManager().refreshAllExtendedPermissions();
return Response.ok(entity).build();
}
- @Path("{id}")
+ @Path("{id : \\d+}")
@DELETE
public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
@@ -107,9 +108,7 @@ public class DeviceResource extends BaseResource {
Context.getPermissionsManager().checkDevice(getUserId(), id);
Context.getDeviceManager().removeDevice(id);
Context.getPermissionsManager().refreshPermissions();
- if (Context.getGeofenceManager() != null) {
- Context.getGeofenceManager().refresh();
- }
+ Context.getPermissionsManager().refreshAllExtendedPermissions();
Context.getAliasesManager().removeDevice(id);
return Response.noContent().build();
}
@@ -122,4 +121,28 @@ public class DeviceResource extends BaseResource {
return Response.noContent().build();
}
+ @Path("/{slave : (geofences|drivers|attributes)}")
+ @POST
+ public Response add(Map<String, Long> entity) throws SQLException {
+ Context.getPermissionsManager().checkReadonly(getUserId());
+ for (String key : entity.keySet()) {
+ Context.getPermissionsManager().checkPermission(key.replace("Id", ""), getUserId(), entity.get(key));
+ }
+ Context.getDataManager().linkObject(entity, true);
+ Context.getPermissionsManager().refreshPermissions(entity);
+ return Response.noContent().build();
+ }
+
+ @Path("/{slave : (geofences|drivers|attributes)}")
+ @DELETE
+ public Response remove(Map<String, Long> entity) throws SQLException {
+ Context.getPermissionsManager().checkReadonly(getUserId());
+ for (String key : entity.keySet()) {
+ Context.getPermissionsManager().checkPermission(key.replace("Id", ""), getUserId(), entity.get(key));
+ }
+ Context.getDataManager().linkObject(entity, false);
+ Context.getPermissionsManager().refreshPermissions(entity);
+ return Response.noContent().build();
+ }
+
}