diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-13 19:03:37 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-13 19:03:37 -0700 |
commit | dd2594ddce22e105a6d9cb356c3c22c3227e58f9 (patch) | |
tree | 367e75f8fd5a29ffb0dc7c11d0204ed4c82760f5 /src | |
parent | 6433ec663ec79196714dcd99939cdddf81f77a7a (diff) | |
download | trackermap-server-dd2594ddce22e105a6d9cb356c3c22c3227e58f9.tar.gz trackermap-server-dd2594ddce22e105a6d9cb356c3c22c3227e58f9.tar.bz2 trackermap-server-dd2594ddce22e105a6d9cb356c3c22c3227e58f9.zip |
Remove data manager methods
Diffstat (limited to 'src')
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())); } |