aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/api/resource/EventResource.java6
-rw-r--r--src/main/java/org/traccar/api/resource/PermissionsResource.java6
-rw-r--r--src/main/java/org/traccar/api/resource/PositionResource.java3
-rw-r--r--src/main/java/org/traccar/api/resource/UserResource.java3
-rw-r--r--src/main/java/org/traccar/database/DataManager.java16
5 files changed, 11 insertions, 23 deletions
diff --git a/src/main/java/org/traccar/api/resource/EventResource.java b/src/main/java/org/traccar/api/resource/EventResource.java
index 38b101b25..eb373946a 100644
--- a/src/main/java/org/traccar/api/resource/EventResource.java
+++ b/src/main/java/org/traccar/api/resource/EventResource.java
@@ -19,6 +19,9 @@ import org.traccar.Context;
import org.traccar.api.BaseResource;
import org.traccar.model.Event;
import org.traccar.storage.StorageException;
+import org.traccar.storage.query.Columns;
+import org.traccar.storage.query.Condition;
+import org.traccar.storage.query.Request;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@@ -37,7 +40,8 @@ public class EventResource extends BaseResource {
@Path("{id}")
@GET
public Event get(@PathParam("id") long id) throws StorageException {
- Event event = Context.getDataManager().getObject(Event.class, id);
+ Event event = storage.getObject(Event.class, new Request(
+ new Columns.All(), new Condition.Equals("id", "id", id)));
if (event == null) {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
}
diff --git a/src/main/java/org/traccar/api/resource/PermissionsResource.java b/src/main/java/org/traccar/api/resource/PermissionsResource.java
index a4db6754c..36ee0c213 100644
--- a/src/main/java/org/traccar/api/resource/PermissionsResource.java
+++ b/src/main/java/org/traccar/api/resource/PermissionsResource.java
@@ -70,8 +70,7 @@ public class PermissionsResource extends BaseResource {
for (LinkedHashMap<String, Long> entity: entities) {
Permission permission = new Permission(entity);
checkPermission(permission, true);
- Context.getDataManager().linkObject(permission.getOwnerClass(), permission.getOwnerId(),
- permission.getPropertyClass(), permission.getPropertyId(), true);
+ storage.addPermission(permission);
cacheManager.invalidate(permission.getOwnerClass(), permission.getOwnerId(),
permission.getPropertyClass(), permission.getPropertyId());
LogAction.link(getUserId(), permission.getOwnerClass(), permission.getOwnerId(),
@@ -96,8 +95,7 @@ public class PermissionsResource extends BaseResource {
for (LinkedHashMap<String, Long> entity: entities) {
Permission permission = new Permission(entity);
checkPermission(permission, false);
- Context.getDataManager().linkObject(permission.getOwnerClass(), permission.getOwnerId(),
- permission.getPropertyClass(), permission.getPropertyId(), false);
+ storage.removePermission(permission);
cacheManager.invalidate(permission.getOwnerClass(), permission.getOwnerId(),
permission.getPropertyClass(), permission.getPropertyId());
LogAction.unlink(getUserId(), permission.getOwnerClass(), permission.getOwnerId(),
diff --git a/src/main/java/org/traccar/api/resource/PositionResource.java b/src/main/java/org/traccar/api/resource/PositionResource.java
index ae948ee14..2c0724df8 100644
--- a/src/main/java/org/traccar/api/resource/PositionResource.java
+++ b/src/main/java/org/traccar/api/resource/PositionResource.java
@@ -49,7 +49,8 @@ public class PositionResource extends BaseResource {
if (!positionIds.isEmpty()) {
ArrayList<Position> positions = new ArrayList<>();
for (Long positionId : positionIds) {
- Position position = Context.getDataManager().getObject(Position.class, positionId);
+ Position position = storage.getObject(Position.class, new Request(
+ new Columns.All(), new Condition.Equals("id", "id", positionId)));
Context.getPermissionsManager().checkDevice(getUserId(), position.getDeviceId());
positions.add(position);
}
diff --git a/src/main/java/org/traccar/api/resource/UserResource.java b/src/main/java/org/traccar/api/resource/UserResource.java
index 83bb8fd0b..84f41ca1a 100644
--- a/src/main/java/org/traccar/api/resource/UserResource.java
+++ b/src/main/java/org/traccar/api/resource/UserResource.java
@@ -21,6 +21,7 @@ import org.traccar.config.Keys;
import org.traccar.database.UsersManager;
import org.traccar.helper.LogAction;
import org.traccar.model.ManagedUser;
+import org.traccar.model.Permission;
import org.traccar.model.User;
import org.traccar.storage.StorageException;
@@ -86,7 +87,7 @@ public class UserResource extends BaseObjectResource<User> {
Context.getUsersManager().addItem(entity);
LogAction.create(getUserId(), entity);
if (Context.getPermissionsManager().getUserManager(getUserId())) {
- Context.getDataManager().linkObject(User.class, getUserId(), ManagedUser.class, entity.getId(), true);
+ storage.addPermission(new Permission(User.class, getUserId(), ManagedUser.class, entity.getId()));
LogAction.link(getUserId(), User.class, getUserId(), ManagedUser.class, entity.getId());
}
Context.getUsersManager().refreshUserItems();
diff --git a/src/main/java/org/traccar/database/DataManager.java b/src/main/java/org/traccar/database/DataManager.java
index 8ed907fdd..fd45a0321 100644
--- a/src/main/java/org/traccar/database/DataManager.java
+++ b/src/main/java/org/traccar/database/DataManager.java
@@ -208,22 +208,6 @@ public class DataManager {
return storage.getPermissions(owner, property);
}
- public void linkObject(
- Class<? extends BaseModel> owner, long ownerId,
- Class<? extends BaseModel> property, long propertyId, boolean link) throws StorageException {
- if (link) {
- storage.addPermission(new Permission(owner, ownerId, property, propertyId));
- } else {
- storage.removePermission(new Permission(owner, ownerId, property, propertyId));
- }
- }
-
- public <T extends BaseModel> T getObject(Class<T> clazz, long entityId) throws StorageException {
- return storage.getObject(clazz, new Request(
- new Columns.All(),
- new Condition.Equals("id", "id", entityId)));
- }
-
public <T extends BaseModel> Collection<T> getObjects(Class<T> clazz) throws StorageException {
return storage.getObjects(clazz, new Request(new Columns.All()));
}