aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource/DriverResource.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/api/resource/DriverResource.java')
-rw-r--r--src/org/traccar/api/resource/DriverResource.java29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/org/traccar/api/resource/DriverResource.java b/src/org/traccar/api/resource/DriverResource.java
index 7fe0af473..72eadb711 100644
--- a/src/org/traccar/api/resource/DriverResource.java
+++ b/src/org/traccar/api/resource/DriverResource.java
@@ -37,6 +37,7 @@ import org.traccar.Context;
import org.traccar.api.BaseResource;
import org.traccar.database.DriversManager;
import org.traccar.model.Driver;
+import org.traccar.model.User;
@Path("drivers")
@Produces(MediaType.APPLICATION_JSON)
@@ -50,44 +51,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.getDataManager().linkDriver(getUserId(), entity.getId());
- Context.getDriversManager().refreshUserDrivers();
+ Context.getDriversManager().addItem(entity);
+ Context.getDataManager().linkObject(User.class, getUserId(), entity.getClass(), entity.getId(), true);
+ Context.getDriversManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -95,8 +96,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.class, getUserId(), entity.getId());
+ Context.getDriversManager().updateItem(entity);
return Response.ok(entity).build();
}
@@ -104,8 +105,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.class, getUserId(), id);
+ Context.getDriversManager().removeItem(id);
return Response.noContent().build();
}