aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource/DeviceResource.java
diff options
context:
space:
mode:
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();
+ }
+
}