aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api/BaseObjectResource.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-03 17:06:30 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-03 17:06:30 -0700
commit4030d3207c157a3fcee2653c18440898b6b2a2e6 (patch)
treeb7e04a72bd369f75871edf832f7ff58198001a85 /src/main/java/org/traccar/api/BaseObjectResource.java
parent65b0f9c5398ddcb28018cb1963108534c638b1f4 (diff)
downloadtrackermap-server-4030d3207c157a3fcee2653c18440898b6b2a2e6.tar.gz
trackermap-server-4030d3207c157a3fcee2653c18440898b6b2a2e6.tar.bz2
trackermap-server-4030d3207c157a3fcee2653c18440898b6b2a2e6.zip
Remove attributes manager
Diffstat (limited to 'src/main/java/org/traccar/api/BaseObjectResource.java')
-rw-r--r--src/main/java/org/traccar/api/BaseObjectResource.java36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/api/BaseObjectResource.java b/src/main/java/org/traccar/api/BaseObjectResource.java
index 07c74449c..d6401dc42 100644
--- a/src/main/java/org/traccar/api/BaseObjectResource.java
+++ b/src/main/java/org/traccar/api/BaseObjectResource.java
@@ -66,7 +66,12 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
permissionsService.checkEdit(getUserId(), entity, true);
BaseObjectManager<T> manager = Context.getManager(baseClass);
- manager.addItem(entity);
+ if (manager != null) {
+ manager.addItem(entity);
+ } else {
+ entity.setId(storage.addObject(entity, new Request(new Columns.Exclude("id"))));
+ }
+
LogAction.create(getUserId(), entity);
storage.addPermission(new Permission(User.class, getUserId(), baseClass, entity.getId()));
@@ -87,7 +92,15 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
permissionsService.checkEdit(getUserId(), entity, false);
permissionsService.checkPermission(baseClass, getUserId(), entity.getId());
- Context.getManager(baseClass).updateItem(entity);
+ BaseObjectManager<T> manager = Context.getManager(baseClass);
+ if (manager != null) {
+ manager.updateItem(entity);
+ } else {
+ storage.updateObject(entity, new Request(
+ new Columns.Exclude("id"),
+ new Condition.Equals("id", "id")));
+ }
+
LogAction.edit(getUserId(), entity);
if (baseClass.equals(Group.class) || baseClass.equals(Device.class)) {
@@ -104,15 +117,20 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
permissionsService.checkPermission(baseClass, getUserId(), id);
BaseObjectManager<T> manager = Context.getManager(baseClass);
- manager.removeItem(id);
- LogAction.remove(getUserId(), baseClass, id);
-
- if (manager instanceof SimpleObjectManager) {
- ((SimpleObjectManager<T>) manager).refreshUserItems();
- if (manager instanceof ExtendedObjectManager) {
- ((ExtendedObjectManager<T>) manager).refreshExtendedPermissions();
+ if (manager != null) {
+ manager.removeItem(id);
+ if (manager instanceof SimpleObjectManager) {
+ ((SimpleObjectManager<T>) manager).refreshUserItems();
+ if (manager instanceof ExtendedObjectManager) {
+ ((ExtendedObjectManager<T>) manager).refreshExtendedPermissions();
+ }
}
+ } else {
+ storage.removeObject(baseClass, new Request(new Condition.Equals("id", "id", id)));
}
+
+ LogAction.remove(getUserId(), baseClass, id);
+
if (baseClass.equals(Group.class) || baseClass.equals(Device.class) || baseClass.equals(User.class)) {
if (baseClass.equals(Group.class)) {
Context.getGroupsManager().refreshItems();