aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-07-19 15:24:55 +0500
committerAbyss777 <abyss@fox5.ru>2017-07-19 15:24:55 +0500
commita9478ded48de140d47d17def1ee5329267fe6088 (patch)
treeadc5a9177fd5adcf10a8b56ee4620780dfc13cd9 /src/org/traccar/api/resource
parentcb0d7cccaecfe049e04defd90884976ac1e982f9 (diff)
downloadtraccar-server-a9478ded48de140d47d17def1ee5329267fe6088.tar.gz
traccar-server-a9478ded48de140d47d17def1ee5329267fe6088.tar.bz2
traccar-server-a9478ded48de140d47d17def1ee5329267fe6088.zip
Refactored four managers
Diffstat (limited to 'src/org/traccar/api/resource')
-rw-r--r--src/org/traccar/api/resource/AttributePermissionResource.java8
-rw-r--r--src/org/traccar/api/resource/AttributeResource.java26
-rw-r--r--src/org/traccar/api/resource/CalendarPermissionResource.java8
-rw-r--r--src/org/traccar/api/resource/CalendarResource.java20
-rw-r--r--src/org/traccar/api/resource/DeviceAttributeResource.java4
-rw-r--r--src/org/traccar/api/resource/DeviceDriverResource.java4
-rw-r--r--src/org/traccar/api/resource/DeviceGeofenceResource.java4
-rw-r--r--src/org/traccar/api/resource/DriverPermissionResource.java8
-rw-r--r--src/org/traccar/api/resource/DriverResource.java26
-rw-r--r--src/org/traccar/api/resource/EventResource.java2
-rw-r--r--src/org/traccar/api/resource/GeofencePermissionResource.java8
-rw-r--r--src/org/traccar/api/resource/GeofenceResource.java27
-rw-r--r--src/org/traccar/api/resource/GroupAttributeResource.java4
-rw-r--r--src/org/traccar/api/resource/GroupDriverResource.java4
-rw-r--r--src/org/traccar/api/resource/GroupGeofenceResource.java4
-rw-r--r--src/org/traccar/api/resource/UserResource.java2
16 files changed, 80 insertions, 79 deletions
diff --git a/src/org/traccar/api/resource/AttributePermissionResource.java b/src/org/traccar/api/resource/AttributePermissionResource.java
index 1924bcdf1..37e50e371 100644
--- a/src/org/traccar/api/resource/AttributePermissionResource.java
+++ b/src/org/traccar/api/resource/AttributePermissionResource.java
@@ -39,9 +39,9 @@ public class AttributePermissionResource extends BaseResource {
public Response add(AttributePermission entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkUser(getUserId(), entity.getUserId());
- Context.getPermissionsManager().checkAttribute(getUserId(), entity.getAttributeId());
+ Context.getPermissionsManager().checkPermission("attribute", getUserId(), entity.getAttributeId());
Context.getDataManager().linkAttribute(entity.getUserId(), entity.getAttributeId());
- Context.getAttributesManager().refreshUserAttributes();
+ Context.getAttributesManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -49,9 +49,9 @@ public class AttributePermissionResource extends BaseResource {
public Response remove(AttributePermission entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkUser(getUserId(), entity.getUserId());
- Context.getPermissionsManager().checkAttribute(getUserId(), entity.getAttributeId());
+ Context.getPermissionsManager().checkPermission("attribute", getUserId(), entity.getAttributeId());
Context.getDataManager().unlinkAttribute(entity.getUserId(), entity.getAttributeId());
- Context.getAttributesManager().refreshUserAttributes();
+ Context.getAttributesManager().refreshUserItems();
return Response.noContent().build();
}
diff --git a/src/org/traccar/api/resource/AttributeResource.java b/src/org/traccar/api/resource/AttributeResource.java
index 4d326779b..c67d9cafe 100644
--- a/src/org/traccar/api/resource/AttributeResource.java
+++ b/src/org/traccar/api/resource/AttributeResource.java
@@ -52,42 +52,42 @@ public class AttributeResource extends BaseResource {
AttributesManager attributesManager = Context.getAttributesManager();
if (refresh) {
- attributesManager.refreshAttributes();
+ attributesManager.refreshItems();
}
Set<Long> result = new HashSet<>();
if (all) {
if (Context.getPermissionsManager().isAdmin(getUserId())) {
- result.addAll(attributesManager.getAllAttributes());
+ result.addAll(attributesManager.getAllItems());
} else {
Context.getPermissionsManager().checkManager(getUserId());
- result.addAll(attributesManager.getManagedAttributes(getUserId()));
+ result.addAll(attributesManager.getManagedItems(getUserId()));
}
} else {
if (userId == 0) {
userId = getUserId();
}
Context.getPermissionsManager().checkUser(getUserId(), userId);
- result.addAll(attributesManager.getUserAttributes(userId));
+ result.addAll(attributesManager.getUserItems(userId));
}
if (groupId != 0) {
Context.getPermissionsManager().checkGroup(getUserId(), groupId);
- result.retainAll(attributesManager.getGroupAttributes(groupId));
+ result.retainAll(attributesManager.getGroupItems(groupId));
}
if (deviceId != 0) {
Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- result.retainAll(attributesManager.getDeviceAttributes(deviceId));
+ result.retainAll(attributesManager.getDeviceItems(deviceId));
}
- return attributesManager.getAttributes(result);
+ return attributesManager.getItems(Attribute.class, result);
}
private Response add(Attribute entity) throws SQLException {
- Context.getAttributesManager().addAttribute(entity);
+ Context.getAttributesManager().addItem(entity);
Context.getDataManager().linkAttribute(getUserId(), entity.getId());
- Context.getAttributesManager().refreshUserAttributes();
+ Context.getAttributesManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -127,8 +127,8 @@ public class AttributeResource extends BaseResource {
@PUT
public Response update(Attribute entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkAttribute(getUserId(), entity.getId());
- Context.getAttributesManager().updateAttribute(entity);
+ Context.getPermissionsManager().checkPermission("attribute", getUserId(), entity.getId());
+ Context.getAttributesManager().updateItem(entity);
return Response.ok(entity).build();
}
@@ -136,8 +136,8 @@ public class AttributeResource extends BaseResource {
@DELETE
public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkAttribute(getUserId(), id);
- Context.getAttributesManager().removeAttribute(id);
+ Context.getPermissionsManager().checkPermission("attribute", getUserId(), id);
+ Context.getAttributesManager().removeItem(id);
return Response.noContent().build();
}
diff --git a/src/org/traccar/api/resource/CalendarPermissionResource.java b/src/org/traccar/api/resource/CalendarPermissionResource.java
index a49254b6b..3936bcaf3 100644
--- a/src/org/traccar/api/resource/CalendarPermissionResource.java
+++ b/src/org/traccar/api/resource/CalendarPermissionResource.java
@@ -39,9 +39,9 @@ public class CalendarPermissionResource extends BaseResource {
public Response add(CalendarPermission entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkUser(getUserId(), entity.getUserId());
- Context.getPermissionsManager().checkCalendar(getUserId(), entity.getCalendarId());
+ Context.getPermissionsManager().checkPermission("calendar", getUserId(), entity.getCalendarId());
Context.getDataManager().linkCalendar(entity.getUserId(), entity.getCalendarId());
- Context.getCalendarManager().refreshUserCalendars();
+ Context.getCalendarManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -49,9 +49,9 @@ public class CalendarPermissionResource extends BaseResource {
public Response remove(CalendarPermission entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkUser(getUserId(), entity.getUserId());
- Context.getPermissionsManager().checkCalendar(getUserId(), entity.getCalendarId());
+ Context.getPermissionsManager().checkPermission("calendar", getUserId(), entity.getCalendarId());
Context.getDataManager().unlinkCalendar(entity.getUserId(), entity.getCalendarId());
- Context.getCalendarManager().refreshUserCalendars();
+ Context.getCalendarManager().refreshUserItems();
return Response.noContent().build();
}
}
diff --git a/src/org/traccar/api/resource/CalendarResource.java b/src/org/traccar/api/resource/CalendarResource.java
index 641d3b4b5..be675fc79 100644
--- a/src/org/traccar/api/resource/CalendarResource.java
+++ b/src/org/traccar/api/resource/CalendarResource.java
@@ -33,6 +33,7 @@ import javax.ws.rs.core.Response;
import org.traccar.Context;
import org.traccar.api.BaseResource;
+import org.traccar.database.CalendarManager;
import org.traccar.model.Calendar;
@Path("calendars")
@@ -44,28 +45,29 @@ public class CalendarResource extends BaseResource {
public Collection<Calendar> get(
@QueryParam("all") boolean all, @QueryParam("userId") long userId) throws SQLException {
+ CalendarManager calendarManager = Context.getCalendarManager();
if (all) {
if (Context.getPermissionsManager().isAdmin(getUserId())) {
- return Context.getCalendarManager().getAllCalendars();
+ return calendarManager.getItems(Calendar.class, calendarManager.getAllItems());
} else {
Context.getPermissionsManager().checkManager(getUserId());
- return Context.getCalendarManager().getManagedCalendars(getUserId());
+ return calendarManager.getItems(Calendar.class, calendarManager.getManagedItems(getUserId()));
}
} else {
if (userId == 0) {
userId = getUserId();
}
Context.getPermissionsManager().checkUser(getUserId(), userId);
- return Context.getCalendarManager().getUserCalendars(userId);
+ return calendarManager.getItems(Calendar.class, calendarManager.getUserItems(userId));
}
}
@POST
public Response add(Calendar entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getCalendarManager().addCalendar(entity);
+ Context.getCalendarManager().addItem(entity);
Context.getDataManager().linkCalendar(getUserId(), entity.getId());
- Context.getCalendarManager().refreshUserCalendars();
+ Context.getCalendarManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -73,8 +75,8 @@ public class CalendarResource extends BaseResource {
@PUT
public Response update(Calendar entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkCalendar(getUserId(), entity.getId());
- Context.getCalendarManager().updateCalendar(entity);
+ Context.getPermissionsManager().checkPermission("calendar", getUserId(), entity.getId());
+ Context.getCalendarManager().updateItem(entity);
return Response.ok(entity).build();
}
@@ -82,8 +84,8 @@ public class CalendarResource extends BaseResource {
@DELETE
public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkCalendar(getUserId(), id);
- Context.getCalendarManager().removeCalendar(id);
+ Context.getPermissionsManager().checkPermission("calendar", getUserId(), id);
+ Context.getCalendarManager().removeItem(id);
return Response.noContent().build();
}
}
diff --git a/src/org/traccar/api/resource/DeviceAttributeResource.java b/src/org/traccar/api/resource/DeviceAttributeResource.java
index 82d17bcc6..bb833d4db 100644
--- a/src/org/traccar/api/resource/DeviceAttributeResource.java
+++ b/src/org/traccar/api/resource/DeviceAttributeResource.java
@@ -39,7 +39,7 @@ public class DeviceAttributeResource extends BaseResource {
public Response add(DeviceAttribute entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkDevice(getUserId(), entity.getDeviceId());
- Context.getPermissionsManager().checkAttribute(getUserId(), entity.getAttributeId());
+ Context.getPermissionsManager().checkPermission("attribute", getUserId(), entity.getAttributeId());
Context.getDataManager().linkDeviceAttribute(entity.getDeviceId(), entity.getAttributeId());
Context.getAttributesManager().refresh();
return Response.ok(entity).build();
@@ -49,7 +49,7 @@ public class DeviceAttributeResource extends BaseResource {
public Response remove(DeviceAttribute entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkDevice(getUserId(), entity.getDeviceId());
- Context.getPermissionsManager().checkAttribute(getUserId(), entity.getAttributeId());
+ Context.getPermissionsManager().checkPermission("attribute", getUserId(), entity.getAttributeId());
Context.getDataManager().unlinkDeviceAttribute(entity.getDeviceId(), entity.getAttributeId());
Context.getAttributesManager().refresh();
return Response.noContent().build();
diff --git a/src/org/traccar/api/resource/DeviceDriverResource.java b/src/org/traccar/api/resource/DeviceDriverResource.java
index 341c50909..286f2223f 100644
--- a/src/org/traccar/api/resource/DeviceDriverResource.java
+++ b/src/org/traccar/api/resource/DeviceDriverResource.java
@@ -39,7 +39,7 @@ public class DeviceDriverResource extends BaseResource {
public Response add(DeviceDriver entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkDevice(getUserId(), entity.getDeviceId());
- Context.getPermissionsManager().checkDriver(getUserId(), entity.getDriverId());
+ Context.getPermissionsManager().checkPermission("driver", getUserId(), entity.getDriverId());
Context.getDataManager().linkDeviceDriver(entity.getDeviceId(), entity.getDriverId());
Context.getDriversManager().refresh();
return Response.ok(entity).build();
@@ -49,7 +49,7 @@ public class DeviceDriverResource extends BaseResource {
public Response remove(DeviceDriver entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkDevice(getUserId(), entity.getDeviceId());
- Context.getPermissionsManager().checkDriver(getUserId(), entity.getDriverId());
+ Context.getPermissionsManager().checkPermission("driver", getUserId(), entity.getDriverId());
Context.getDataManager().unlinkDeviceDriver(entity.getDeviceId(), entity.getDriverId());
Context.getDriversManager().refresh();
return Response.noContent().build();
diff --git a/src/org/traccar/api/resource/DeviceGeofenceResource.java b/src/org/traccar/api/resource/DeviceGeofenceResource.java
index 6254fe3cf..8034e2168 100644
--- a/src/org/traccar/api/resource/DeviceGeofenceResource.java
+++ b/src/org/traccar/api/resource/DeviceGeofenceResource.java
@@ -38,7 +38,7 @@ public class DeviceGeofenceResource extends BaseResource {
public Response add(DeviceGeofence entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkDevice(getUserId(), entity.getDeviceId());
- Context.getPermissionsManager().checkGeofence(getUserId(), entity.getGeofenceId());
+ Context.getPermissionsManager().checkPermission("geofence", getUserId(), entity.getGeofenceId());
Context.getDataManager().linkDeviceGeofence(entity.getDeviceId(), entity.getGeofenceId());
Context.getGeofenceManager().refresh();
return Response.ok(entity).build();
@@ -48,7 +48,7 @@ public class DeviceGeofenceResource extends BaseResource {
public Response remove(DeviceGeofence entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkDevice(getUserId(), entity.getDeviceId());
- Context.getPermissionsManager().checkGeofence(getUserId(), entity.getGeofenceId());
+ Context.getPermissionsManager().checkPermission("geofence", getUserId(), entity.getGeofenceId());
Context.getDataManager().unlinkDeviceGeofence(entity.getDeviceId(), entity.getGeofenceId());
Context.getGeofenceManager().refresh();
return Response.noContent().build();
diff --git a/src/org/traccar/api/resource/DriverPermissionResource.java b/src/org/traccar/api/resource/DriverPermissionResource.java
index fd1ca7c6d..4d890cae9 100644
--- a/src/org/traccar/api/resource/DriverPermissionResource.java
+++ b/src/org/traccar/api/resource/DriverPermissionResource.java
@@ -40,9 +40,9 @@ public class DriverPermissionResource extends BaseResource {
public Response add(DriverPermission entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkUser(getUserId(), entity.getUserId());
- Context.getPermissionsManager().checkDriver(getUserId(), entity.getDriverId());
+ Context.getPermissionsManager().checkPermission("driver", getUserId(), entity.getDriverId());
Context.getDataManager().linkDriver(entity.getUserId(), entity.getDriverId());
- Context.getDriversManager().refreshUserDrivers();
+ Context.getDriversManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -50,9 +50,9 @@ public class DriverPermissionResource extends BaseResource {
public Response remove(DriverPermission entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkUser(getUserId(), entity.getUserId());
- Context.getPermissionsManager().checkDriver(getUserId(), entity.getDriverId());
+ Context.getPermissionsManager().checkPermission("driver", getUserId(), entity.getDriverId());
Context.getDataManager().unlinkDriver(entity.getUserId(), entity.getDriverId());
- Context.getDriversManager().refreshUserDrivers();
+ Context.getDriversManager().refreshUserItems();
return Response.noContent().build();
}
diff --git a/src/org/traccar/api/resource/DriverResource.java b/src/org/traccar/api/resource/DriverResource.java
index 7fe0af473..3d6a12795 100644
--- a/src/org/traccar/api/resource/DriverResource.java
+++ b/src/org/traccar/api/resource/DriverResource.java
@@ -50,44 +50,44 @@ public class DriverResource extends BaseResource {
DriversManager driversManager = Context.getDriversManager();
if (refresh) {
- driversManager.refreshDrivers();
+ driversManager.refreshItems();
}
Set<Long> result = new HashSet<>();
if (all) {
if (Context.getPermissionsManager().isAdmin(getUserId())) {
- result.addAll(driversManager.getAllDrivers());
+ result.addAll(driversManager.getAllItems());
} else {
Context.getPermissionsManager().checkManager(getUserId());
- result.addAll(driversManager.getManagedDrivers(getUserId()));
+ result.addAll(driversManager.getManagedItems(getUserId()));
}
} else {
if (userId == 0) {
userId = getUserId();
}
Context.getPermissionsManager().checkUser(getUserId(), userId);
- result.addAll(driversManager.getUserDrivers(userId));
+ result.addAll(driversManager.getUserItems(userId));
}
if (groupId != 0) {
Context.getPermissionsManager().checkGroup(getUserId(), groupId);
- result.retainAll(driversManager.getGroupDrivers(groupId));
+ result.retainAll(driversManager.getGroupItems(groupId));
}
if (deviceId != 0) {
Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- result.retainAll(driversManager.getDeviceDrivers(deviceId));
+ result.retainAll(driversManager.getDeviceItems(deviceId));
}
- return driversManager.getDrivers(result);
+ return driversManager.getItems(Driver.class, result);
}
@POST
public Response add(Driver entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getDriversManager().addDriver(entity);
+ Context.getDriversManager().addItem(entity);
Context.getDataManager().linkDriver(getUserId(), entity.getId());
- Context.getDriversManager().refreshUserDrivers();
+ Context.getDriversManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -95,8 +95,8 @@ public class DriverResource extends BaseResource {
@PUT
public Response update(Driver entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkDriver(getUserId(), entity.getId());
- Context.getDriversManager().updateDriver(entity);
+ Context.getPermissionsManager().checkPermission("driver", getUserId(), entity.getId());
+ Context.getDriversManager().updateItem(entity);
return Response.ok(entity).build();
}
@@ -104,8 +104,8 @@ public class DriverResource extends BaseResource {
@DELETE
public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkDriver(getUserId(), id);
- Context.getDriversManager().removeDriver(id);
+ Context.getPermissionsManager().checkPermission("driver", 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 0ef5456af..9b43bf4b0 100644
--- a/src/org/traccar/api/resource/EventResource.java
+++ b/src/org/traccar/api/resource/EventResource.java
@@ -25,7 +25,7 @@ public class EventResource extends BaseResource {
Event event = Context.getDataManager().getEvent(id);
Context.getPermissionsManager().checkDevice(getUserId(), event.getDeviceId());
if (event.getGeofenceId() != 0) {
- Context.getPermissionsManager().checkGeofence(getUserId(), event.getGeofenceId());
+ Context.getPermissionsManager().checkPermission("geofence", getUserId(), event.getGeofenceId());
}
return event;
}
diff --git a/src/org/traccar/api/resource/GeofencePermissionResource.java b/src/org/traccar/api/resource/GeofencePermissionResource.java
index 8faa63d85..a569e56fd 100644
--- a/src/org/traccar/api/resource/GeofencePermissionResource.java
+++ b/src/org/traccar/api/resource/GeofencePermissionResource.java
@@ -37,9 +37,9 @@ public class GeofencePermissionResource extends BaseResource {
public Response add(GeofencePermission entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkUser(getUserId(), entity.getUserId());
- Context.getPermissionsManager().checkGeofence(getUserId(), entity.getGeofenceId());
+ Context.getPermissionsManager().checkPermission("geofence", getUserId(), entity.getGeofenceId());
Context.getDataManager().linkGeofence(entity.getUserId(), entity.getGeofenceId());
- Context.getGeofenceManager().refreshUserGeofences();
+ Context.getGeofenceManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -47,9 +47,9 @@ public class GeofencePermissionResource extends BaseResource {
public Response remove(GeofencePermission entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkUser(getUserId(), entity.getUserId());
- Context.getPermissionsManager().checkGeofence(getUserId(), entity.getGeofenceId());
+ Context.getPermissionsManager().checkPermission("geofence", getUserId(), entity.getGeofenceId());
Context.getDataManager().unlinkGeofence(entity.getUserId(), entity.getGeofenceId());
- Context.getGeofenceManager().refreshUserGeofences();
+ Context.getGeofenceManager().refreshUserItems();
return Response.noContent().build();
}
diff --git a/src/org/traccar/api/resource/GeofenceResource.java b/src/org/traccar/api/resource/GeofenceResource.java
index d5acf106a..4a52822cc 100644
--- a/src/org/traccar/api/resource/GeofenceResource.java
+++ b/src/org/traccar/api/resource/GeofenceResource.java
@@ -49,44 +49,44 @@ public class GeofenceResource extends BaseResource {
GeofenceManager geofenceManager = Context.getGeofenceManager();
if (refresh) {
- geofenceManager.refreshGeofences();
+ geofenceManager.refreshItems();
}
Set<Long> result = new HashSet<>();
if (all) {
if (Context.getPermissionsManager().isAdmin(getUserId())) {
- result.addAll(geofenceManager.getAllGeofencesIds());
+ result.addAll(geofenceManager.getAllItems());
} else {
Context.getPermissionsManager().checkManager(getUserId());
- result.addAll(geofenceManager.getManagedGeofencesIds(getUserId()));
+ result.addAll(geofenceManager.getManagedItems(getUserId()));
}
} else {
if (userId == 0) {
userId = getUserId();
}
Context.getPermissionsManager().checkUser(getUserId(), userId);
- result.addAll(geofenceManager.getUserGeofencesIds(userId));
+ result.addAll(geofenceManager.getUserItems(userId));
}
if (groupId != 0) {
Context.getPermissionsManager().checkGroup(getUserId(), groupId);
- result.retainAll(geofenceManager.getGroupGeofencesIds(groupId));
+ result.retainAll(geofenceManager.getGroupItems(groupId));
}
if (deviceId != 0) {
Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- result.retainAll(geofenceManager.getDeviceGeofencesIds(deviceId));
+ result.retainAll(geofenceManager.getDeviceItems(deviceId));
}
- return geofenceManager.getGeofences(result);
+ return geofenceManager.getItems(Geofence.class, result);
}
@POST
public Response add(Geofence entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getDataManager().addGeofence(entity);
+ Context.getGeofenceManager().addItem(entity);
Context.getDataManager().linkGeofence(getUserId(), entity.getId());
- Context.getGeofenceManager().refreshGeofences();
+ Context.getGeofenceManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -94,8 +94,8 @@ public class GeofenceResource extends BaseResource {
@PUT
public Response update(Geofence entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkGeofence(getUserId(), entity.getId());
- Context.getGeofenceManager().updateGeofence(entity);
+ Context.getPermissionsManager().checkPermission("geofence", getUserId(), entity.getId());
+ Context.getGeofenceManager().updateItem(entity);
return Response.ok(entity).build();
}
@@ -103,9 +103,8 @@ public class GeofenceResource extends BaseResource {
@DELETE
public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkGeofence(getUserId(), id);
- Context.getDataManager().removeGeofence(id);
- Context.getGeofenceManager().refreshGeofences();
+ Context.getPermissionsManager().checkPermission("geofence", getUserId(), id);
+ Context.getGeofenceManager().removeItem(id);
return Response.noContent().build();
}
diff --git a/src/org/traccar/api/resource/GroupAttributeResource.java b/src/org/traccar/api/resource/GroupAttributeResource.java
index d8b8b58c9..5df63194e 100644
--- a/src/org/traccar/api/resource/GroupAttributeResource.java
+++ b/src/org/traccar/api/resource/GroupAttributeResource.java
@@ -39,7 +39,7 @@ public class GroupAttributeResource extends BaseResource {
public Response add(GroupAttribute entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkGroup(getUserId(), entity.getGroupId());
- Context.getPermissionsManager().checkAttribute(getUserId(), entity.getAttributeId());
+ Context.getPermissionsManager().checkPermission("attribute", getUserId(), entity.getAttributeId());
Context.getDataManager().linkGroupAttribute(entity.getGroupId(), entity.getAttributeId());
Context.getAttributesManager().refresh();
return Response.ok(entity).build();
@@ -49,7 +49,7 @@ public class GroupAttributeResource extends BaseResource {
public Response remove(GroupAttribute entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkGroup(getUserId(), entity.getGroupId());
- Context.getPermissionsManager().checkAttribute(getUserId(), entity.getAttributeId());
+ Context.getPermissionsManager().checkPermission("attribute", getUserId(), entity.getAttributeId());
Context.getDataManager().unlinkGroupAttribute(entity.getGroupId(), entity.getAttributeId());
Context.getAttributesManager().refresh();
return Response.noContent().build();
diff --git a/src/org/traccar/api/resource/GroupDriverResource.java b/src/org/traccar/api/resource/GroupDriverResource.java
index 76fc2892c..71c1aca29 100644
--- a/src/org/traccar/api/resource/GroupDriverResource.java
+++ b/src/org/traccar/api/resource/GroupDriverResource.java
@@ -39,7 +39,7 @@ public class GroupDriverResource extends BaseResource {
public Response add(GroupDriver entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkGroup(getUserId(), entity.getGroupId());
- Context.getPermissionsManager().checkDriver(getUserId(), entity.getDriverId());
+ Context.getPermissionsManager().checkPermission("driver", getUserId(), entity.getDriverId());
Context.getDataManager().linkGroupDriver(entity.getGroupId(), entity.getDriverId());
Context.getDriversManager().refresh();
return Response.ok(entity).build();
@@ -49,7 +49,7 @@ public class GroupDriverResource extends BaseResource {
public Response remove(GroupDriver entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkGroup(getUserId(), entity.getGroupId());
- Context.getPermissionsManager().checkDriver(getUserId(), entity.getDriverId());
+ Context.getPermissionsManager().checkPermission("driver", getUserId(), entity.getDriverId());
Context.getDataManager().unlinkGroupDriver(entity.getGroupId(), entity.getDriverId());
Context.getDriversManager().refresh();
return Response.noContent().build();
diff --git a/src/org/traccar/api/resource/GroupGeofenceResource.java b/src/org/traccar/api/resource/GroupGeofenceResource.java
index 81fd4e45f..14000c4b5 100644
--- a/src/org/traccar/api/resource/GroupGeofenceResource.java
+++ b/src/org/traccar/api/resource/GroupGeofenceResource.java
@@ -37,7 +37,7 @@ public class GroupGeofenceResource extends BaseResource {
public Response add(GroupGeofence entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkGroup(getUserId(), entity.getGroupId());
- Context.getPermissionsManager().checkGeofence(getUserId(), entity.getGeofenceId());
+ Context.getPermissionsManager().checkPermission("geofence", getUserId(), entity.getGeofenceId());
Context.getDataManager().linkGroupGeofence(entity.getGroupId(), entity.getGeofenceId());
Context.getGeofenceManager().refresh();
return Response.ok(entity).build();
@@ -47,7 +47,7 @@ public class GroupGeofenceResource extends BaseResource {
public Response remove(GroupGeofence entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkGroup(getUserId(), entity.getGroupId());
- Context.getPermissionsManager().checkGeofence(getUserId(), entity.getGeofenceId());
+ Context.getPermissionsManager().checkPermission("geofence", getUserId(), entity.getGeofenceId());
Context.getDataManager().unlinkGroupGeofence(entity.getGroupId(), entity.getGeofenceId());
Context.getGeofenceManager().refresh();
return Response.noContent().build();
diff --git a/src/org/traccar/api/resource/UserResource.java b/src/org/traccar/api/resource/UserResource.java
index 4d8a8b3a4..b9187fdbb 100644
--- a/src/org/traccar/api/resource/UserResource.java
+++ b/src/org/traccar/api/resource/UserResource.java
@@ -104,7 +104,7 @@ public class UserResource extends BaseResource {
Context.getPermissionsManager().checkUser(getUserId(), id);
Context.getPermissionsManager().removeUser(id);
if (Context.getGeofenceManager() != null) {
- Context.getGeofenceManager().refreshUserGeofences();
+ Context.getGeofenceManager().refreshUserItems();
}
if (Context.getNotificationManager() != null) {
Context.getNotificationManager().refresh();