aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-07-21 18:41:49 +0500
committerAbyss777 <abyss@fox5.ru>2017-07-21 18:41:49 +0500
commit69c46399ee0f6b3dd2b0589cb412e9e17f040369 (patch)
tree4d838e7c52df78acaae804eaa08911825edc0acd /src/org/traccar/api/resource
parent55d91ec7a86777bb0427422c15c2b8a60aa00071 (diff)
downloadtraccar-server-69c46399ee0f6b3dd2b0589cb412e9e17f040369.tar.gz
traccar-server-69c46399ee0f6b3dd2b0589cb412e9e17f040369.tar.bz2
traccar-server-69c46399ee0f6b3dd2b0589cb412e9e17f040369.zip
Use classes instead of constants everywhere
Diffstat (limited to 'src/org/traccar/api/resource')
-rw-r--r--src/org/traccar/api/resource/AttributeResource.java6
-rw-r--r--src/org/traccar/api/resource/CalendarResource.java6
-rw-r--r--src/org/traccar/api/resource/DeviceResource.java2
-rw-r--r--src/org/traccar/api/resource/DriverResource.java6
-rw-r--r--src/org/traccar/api/resource/EventResource.java3
-rw-r--r--src/org/traccar/api/resource/GeofenceResource.java6
-rw-r--r--src/org/traccar/api/resource/GroupResource.java2
-rw-r--r--src/org/traccar/api/resource/PermissionsResource.java10
-rw-r--r--src/org/traccar/api/resource/UserResource.java3
9 files changed, 23 insertions, 21 deletions
diff --git a/src/org/traccar/api/resource/AttributeResource.java b/src/org/traccar/api/resource/AttributeResource.java
index 63cdfb2a7..7e6947d26 100644
--- a/src/org/traccar/api/resource/AttributeResource.java
+++ b/src/org/traccar/api/resource/AttributeResource.java
@@ -87,7 +87,7 @@ public class AttributeResource extends BaseResource {
private Response add(Attribute entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getAttributesManager().addItem(entity);
- linkNew(entity);
+ linkNewEntity(entity);
Context.getAttributesManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -128,7 +128,7 @@ public class AttributeResource extends BaseResource {
@PUT
public Response update(Attribute entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkPermission(Context.TYPE_ATTRIBUTE, getUserId(), entity.getId());
+ Context.getPermissionsManager().checkPermission(Attribute.class, getUserId(), entity.getId());
Context.getAttributesManager().updateItem(entity);
return Response.ok(entity).build();
}
@@ -137,7 +137,7 @@ public class AttributeResource extends BaseResource {
@DELETE
public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkPermission(Context.TYPE_ATTRIBUTE, getUserId(), id);
+ Context.getPermissionsManager().checkPermission(Attribute.class, getUserId(), id);
Context.getAttributesManager().removeItem(id);
return Response.noContent().build();
}
diff --git a/src/org/traccar/api/resource/CalendarResource.java b/src/org/traccar/api/resource/CalendarResource.java
index d29080ee2..30f5df6b8 100644
--- a/src/org/traccar/api/resource/CalendarResource.java
+++ b/src/org/traccar/api/resource/CalendarResource.java
@@ -66,7 +66,7 @@ public class CalendarResource extends BaseResource {
public Response add(Calendar entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getCalendarManager().addItem(entity);
- linkNew(entity);
+ linkNewEntity(entity);
Context.getCalendarManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -75,7 +75,7 @@ public class CalendarResource extends BaseResource {
@PUT
public Response update(Calendar entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkPermission(Context.TYPE_CALENDAR, getUserId(), entity.getId());
+ Context.getPermissionsManager().checkPermission(Calendar.class, getUserId(), entity.getId());
Context.getCalendarManager().updateItem(entity);
return Response.ok(entity).build();
}
@@ -84,7 +84,7 @@ public class CalendarResource extends BaseResource {
@DELETE
public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkPermission(Context.TYPE_CALENDAR, getUserId(), id);
+ Context.getPermissionsManager().checkPermission(Calendar.class, getUserId(), id);
Context.getCalendarManager().removeItem(id);
return Response.noContent().build();
}
diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java
index 285ed6a31..e1c0fc96d 100644
--- a/src/org/traccar/api/resource/DeviceResource.java
+++ b/src/org/traccar/api/resource/DeviceResource.java
@@ -77,7 +77,7 @@ public class DeviceResource extends BaseResource {
Context.getPermissionsManager().checkDeviceReadonly(getUserId());
Context.getPermissionsManager().checkDeviceLimit(getUserId());
Context.getDeviceManager().addDevice(entity);
- linkNew(entity);
+ linkNewEntity(entity);
Context.getPermissionsManager().refreshPermissions();
Context.getPermissionsManager().refreshAllExtendedPermissions();
return Response.ok(entity).build();
diff --git a/src/org/traccar/api/resource/DriverResource.java b/src/org/traccar/api/resource/DriverResource.java
index b528a197a..cf80bf7df 100644
--- a/src/org/traccar/api/resource/DriverResource.java
+++ b/src/org/traccar/api/resource/DriverResource.java
@@ -86,7 +86,7 @@ public class DriverResource extends BaseResource {
public Response add(Driver entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getDriversManager().addItem(entity);
- linkNew(entity);
+ linkNewEntity(entity);
Context.getDriversManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -95,7 +95,7 @@ public class DriverResource extends BaseResource {
@PUT
public Response update(Driver entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkPermission(Context.TYPE_DRIVER, getUserId(), entity.getId());
+ Context.getPermissionsManager().checkPermission(Driver.class, getUserId(), entity.getId());
Context.getDriversManager().updateItem(entity);
return Response.ok(entity).build();
}
@@ -104,7 +104,7 @@ public class DriverResource extends BaseResource {
@DELETE
public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkPermission(Context.TYPE_DRIVER, getUserId(), id);
+ Context.getPermissionsManager().checkPermission(Driver.class, getUserId(), id);
Context.getDriversManager().removeItem(id);
return Response.noContent().build();
}
diff --git a/src/org/traccar/api/resource/EventResource.java b/src/org/traccar/api/resource/EventResource.java
index 85f981514..b7fda6f73 100644
--- a/src/org/traccar/api/resource/EventResource.java
+++ b/src/org/traccar/api/resource/EventResource.java
@@ -12,6 +12,7 @@ import javax.ws.rs.core.MediaType;
import org.traccar.Context;
import org.traccar.api.BaseResource;
import org.traccar.model.Event;
+import org.traccar.model.Geofence;
@Path("events")
@Produces(MediaType.APPLICATION_JSON)
@@ -25,7 +26,7 @@ public class EventResource extends BaseResource {
Event event = Context.getDataManager().getEvent(id);
Context.getPermissionsManager().checkDevice(getUserId(), event.getDeviceId());
if (event.getGeofenceId() != 0) {
- Context.getPermissionsManager().checkPermission(Context.TYPE_GEOFENCE, getUserId(), event.getGeofenceId());
+ Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), event.getGeofenceId());
}
return event;
}
diff --git a/src/org/traccar/api/resource/GeofenceResource.java b/src/org/traccar/api/resource/GeofenceResource.java
index c9cc72bd7..341180cf8 100644
--- a/src/org/traccar/api/resource/GeofenceResource.java
+++ b/src/org/traccar/api/resource/GeofenceResource.java
@@ -85,7 +85,7 @@ public class GeofenceResource extends BaseResource {
public Response add(Geofence entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getGeofenceManager().addItem(entity);
- linkNew(entity);
+ linkNewEntity(entity);
Context.getGeofenceManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -94,7 +94,7 @@ public class GeofenceResource extends BaseResource {
@PUT
public Response update(Geofence entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkPermission(Context.TYPE_GEOFENCE, getUserId(), entity.getId());
+ Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), entity.getId());
Context.getGeofenceManager().updateItem(entity);
return Response.ok(entity).build();
}
@@ -103,7 +103,7 @@ public class GeofenceResource extends BaseResource {
@DELETE
public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkPermission(Context.TYPE_GEOFENCE, getUserId(), id);
+ Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), id);
Context.getGeofenceManager().removeItem(id);
return Response.noContent().build();
}
diff --git a/src/org/traccar/api/resource/GroupResource.java b/src/org/traccar/api/resource/GroupResource.java
index 5d575ebfe..2ecd11fe5 100644
--- a/src/org/traccar/api/resource/GroupResource.java
+++ b/src/org/traccar/api/resource/GroupResource.java
@@ -61,7 +61,7 @@ public class GroupResource extends BaseResource {
public Response add(Group entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getDeviceManager().addGroup(entity);
- linkNew(entity);
+ linkNewEntity(entity);
Context.getPermissionsManager().refreshPermissions();
Context.getPermissionsManager().refreshAllExtendedPermissions();
return Response.ok(entity).build();
diff --git a/src/org/traccar/api/resource/PermissionsResource.java b/src/org/traccar/api/resource/PermissionsResource.java
index 707242cf1..515efbe41 100644
--- a/src/org/traccar/api/resource/PermissionsResource.java
+++ b/src/org/traccar/api/resource/PermissionsResource.java
@@ -17,7 +17,7 @@
package org.traccar.api.resource;
import java.sql.SQLException;
-import java.util.Map;
+import java.util.LinkedHashMap;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@@ -36,17 +36,17 @@ import org.traccar.api.BaseResource;
public class PermissionsResource extends BaseResource {
@POST
- public Response add(Map<String, Long> entity) throws SQLException {
+ public Response add(LinkedHashMap<String, Long> entity) throws SQLException, ClassNotFoundException {
Context.getPermissionsManager().checkReadonly(getUserId());
- handlePermission(entity, true);
+ checkAndLinkPermission(entity, true);
Context.getPermissionsManager().refreshPermissions(entity);
return Response.noContent().build();
}
@DELETE
- public Response remove(Map<String, Long> entity) throws SQLException {
+ public Response remove(LinkedHashMap<String, Long> entity) throws SQLException, ClassNotFoundException {
Context.getPermissionsManager().checkReadonly(getUserId());
- handlePermission(entity, false);
+ checkAndLinkPermission(entity, false);
Context.getPermissionsManager().refreshPermissions(entity);
return Response.noContent().build();
}
diff --git a/src/org/traccar/api/resource/UserResource.java b/src/org/traccar/api/resource/UserResource.java
index e710c940d..98395e3cc 100644
--- a/src/org/traccar/api/resource/UserResource.java
+++ b/src/org/traccar/api/resource/UserResource.java
@@ -17,6 +17,7 @@ package org.traccar.api.resource;
import org.traccar.Context;
import org.traccar.api.BaseResource;
+import org.traccar.model.ManagedUser;
import org.traccar.model.User;
import javax.annotation.security.PermitAll;
@@ -74,7 +75,7 @@ public class UserResource extends BaseResource {
}
Context.getPermissionsManager().addUser(entity);
if (Context.getPermissionsManager().isManager(getUserId())) {
- Context.getDataManager().linkObject("userId", getUserId(), "managedUserId", entity.getId(), true);
+ Context.getDataManager().linkObject(User.class, getUserId(), ManagedUser.class, entity.getId(), true);
}
Context.getPermissionsManager().refreshUserPermissions();
if (Context.getNotificationManager() != null) {