aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
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
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')
-rw-r--r--src/main/java/org/traccar/Context.java14
-rw-r--r--src/main/java/org/traccar/MainModule.java6
-rw-r--r--src/main/java/org/traccar/api/BaseObjectResource.java36
-rw-r--r--src/main/java/org/traccar/api/ExtendedObjectResource.java2
-rw-r--r--src/main/java/org/traccar/api/SimpleObjectResource.java2
-rw-r--r--src/main/java/org/traccar/api/resource/AttributeResource.java6
-rw-r--r--src/main/java/org/traccar/api/resource/PermissionsResource.java40
-rw-r--r--src/main/java/org/traccar/api/security/PermissionsService.java19
-rw-r--r--src/main/java/org/traccar/database/AttributesManager.java36
-rw-r--r--src/main/java/org/traccar/database/DataManager.java5
-rw-r--r--src/main/java/org/traccar/database/PermissionsManager.java25
-rw-r--r--src/main/java/org/traccar/handler/ComputedAttributesHandler.java11
-rw-r--r--src/main/java/org/traccar/model/Permission.java16
-rw-r--r--src/main/java/org/traccar/storage/DatabaseStorage.java4
-rw-r--r--src/main/java/org/traccar/storage/MemoryStorage.java4
-rw-r--r--src/main/java/org/traccar/storage/Storage.java13
16 files changed, 85 insertions, 154 deletions
diff --git a/src/main/java/org/traccar/Context.java b/src/main/java/org/traccar/Context.java
index 1faa4c9de..4eab36a89 100644
--- a/src/main/java/org/traccar/Context.java
+++ b/src/main/java/org/traccar/Context.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2021 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2022 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ import org.eclipse.jetty.util.URIUtil;
import org.traccar.broadcast.BroadcastService;
import org.traccar.config.Config;
import org.traccar.config.Keys;
-import org.traccar.database.AttributesManager;
import org.traccar.database.BaseObjectManager;
import org.traccar.database.CalendarManager;
import org.traccar.database.CommandsManager;
@@ -44,7 +43,6 @@ import org.traccar.database.UsersManager;
import org.traccar.geocoder.Geocoder;
import org.traccar.helper.Log;
import org.traccar.helper.SanitizerModule;
-import org.traccar.model.Attribute;
import org.traccar.model.BaseModel;
import org.traccar.model.Calendar;
import org.traccar.model.Command;
@@ -213,12 +211,6 @@ public final class Context {
return eventForwarder;
}
- private static AttributesManager attributesManager;
-
- public static AttributesManager getAttributesManager() {
- return attributesManager;
- }
-
private static DriversManager driversManager;
public static DriversManager getDriversManager() {
@@ -343,8 +335,6 @@ public final class Context {
eventForwarder = new EventForwarder();
}
- attributesManager = new AttributesManager(dataManager);
-
driversManager = new DriversManager(dataManager);
commandsManager = new CommandsManager(dataManager, config.getBoolean(Keys.COMMANDS_QUEUEING));
@@ -398,8 +388,6 @@ public final class Context {
return (BaseObjectManager<T>) usersManager;
} else if (clazz.equals(Calendar.class)) {
return (BaseObjectManager<T>) calendarManager;
- } else if (clazz.equals(Attribute.class)) {
- return (BaseObjectManager<T>) attributesManager;
} else if (clazz.equals(Geofence.class)) {
return (BaseObjectManager<T>) geofenceManager;
} else if (clazz.equals(Driver.class)) {
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index 43ca3ba77..f46312221 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -24,7 +24,6 @@ import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import org.traccar.config.Config;
import org.traccar.config.Keys;
-import org.traccar.database.AttributesManager;
import org.traccar.database.CalendarManager;
import org.traccar.session.ConnectionManager;
import org.traccar.database.DataManager;
@@ -131,11 +130,6 @@ public class MainModule extends AbstractModule {
}
@Provides
- public static AttributesManager provideAttributesManager() {
- return Context.getAttributesManager();
- }
-
- @Provides
public static MaintenancesManager provideMaintenancesManager() {
return Context.getMaintenancesManager();
}
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();
diff --git a/src/main/java/org/traccar/api/ExtendedObjectResource.java b/src/main/java/org/traccar/api/ExtendedObjectResource.java
index 41ed3e9d9..8467b46c6 100644
--- a/src/main/java/org/traccar/api/ExtendedObjectResource.java
+++ b/src/main/java/org/traccar/api/ExtendedObjectResource.java
@@ -44,7 +44,7 @@ public class ExtendedObjectResource<T extends BaseModel> extends BaseObjectResou
var conditions = new LinkedList<Condition>();
if (all) {
- if (!permissionsService.isAdmin(getUserId())) {
+ if (permissionsService.notAdmin(getUserId())) {
conditions.add(new Condition.Permission(User.class, getUserId(), baseClass));
}
} else {
diff --git a/src/main/java/org/traccar/api/SimpleObjectResource.java b/src/main/java/org/traccar/api/SimpleObjectResource.java
index 15a496c5f..4a435ca7d 100644
--- a/src/main/java/org/traccar/api/SimpleObjectResource.java
+++ b/src/main/java/org/traccar/api/SimpleObjectResource.java
@@ -41,7 +41,7 @@ public class SimpleObjectResource<T extends BaseModel> extends BaseObjectResourc
var conditions = new LinkedList<Condition>();
if (all) {
- if (!permissionsService.isAdmin(getUserId())) {
+ if (permissionsService.notAdmin(getUserId())) {
conditions.add(new Condition.Permission(User.class, getUserId(), baseClass));
}
} else {
diff --git a/src/main/java/org/traccar/api/resource/AttributeResource.java b/src/main/java/org/traccar/api/resource/AttributeResource.java
index 478b7acfd..fdd0d4f6f 100644
--- a/src/main/java/org/traccar/api/resource/AttributeResource.java
+++ b/src/main/java/org/traccar/api/resource/AttributeResource.java
@@ -67,10 +67,8 @@ public class AttributeResource extends ExtendedObjectResource<Attribute> {
throw new IllegalArgumentException("Device has no last position");
}
- Object result = new ComputedAttributesHandler(
- Context.getConfig(),
- Context.getIdentityManager(),
- Context.getAttributesManager()).computeAttribute(entity, last);
+ Object result = new ComputedAttributesHandler(Context.getConfig(), Context.getIdentityManager(), null)
+ .computeAttribute(entity, last);
if (result != null) {
switch (entity.getType()) {
case "number":
diff --git a/src/main/java/org/traccar/api/resource/PermissionsResource.java b/src/main/java/org/traccar/api/resource/PermissionsResource.java
index 7def38919..484c61e66 100644
--- a/src/main/java/org/traccar/api/resource/PermissionsResource.java
+++ b/src/main/java/org/traccar/api/resource/PermissionsResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,10 +16,11 @@
*/
package org.traccar.api.resource;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Set;
+import org.traccar.Context;
+import org.traccar.api.BaseResource;
+import org.traccar.helper.LogAction;
+import org.traccar.model.Permission;
+import org.traccar.storage.StorageException;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@@ -29,34 +30,21 @@ import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-
-import org.traccar.Context;
-import org.traccar.api.BaseResource;
-import org.traccar.helper.LogAction;
-import org.traccar.model.Device;
-import org.traccar.model.Permission;
-import org.traccar.model.User;
-import org.traccar.storage.StorageException;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Set;
@Path("permissions")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class PermissionsResource extends BaseResource {
- private void checkPermission(Permission permission, boolean link) {
- if (!link && permission.getOwnerClass().equals(User.class)
- && permission.getPropertyClass().equals(Device.class)) {
- if (getUserId() != permission.getOwnerId()) {
- Context.getPermissionsManager().checkUser(getUserId(), permission.getOwnerId());
- } else {
- Context.getPermissionsManager().checkAdmin(getUserId());
- }
- } else {
- Context.getPermissionsManager().checkPermission(
- permission.getOwnerClass(), getUserId(), permission.getOwnerId());
+ private void checkPermission(Permission permission, boolean link) throws StorageException {
+ if (permissionsService.notAdmin(getUserId())) {
+ permissionsService.checkPermission(permission.getOwnerClass(), getUserId(), permission.getOwnerId());
+ permissionsService.checkPermission(permission.getOwnerClass(), getUserId(), permission.getOwnerId());
}
- Context.getPermissionsManager().checkPermission(
- permission.getPropertyClass(), getUserId(), permission.getPropertyId());
}
private void checkPermissionTypes(List<LinkedHashMap<String, Long>> entities) {
diff --git a/src/main/java/org/traccar/api/security/PermissionsService.java b/src/main/java/org/traccar/api/security/PermissionsService.java
index ac687fc1c..9daef355e 100644
--- a/src/main/java/org/traccar/api/security/PermissionsService.java
+++ b/src/main/java/org/traccar/api/security/PermissionsService.java
@@ -61,8 +61,8 @@ public class PermissionsService {
return user;
}
- public boolean isAdmin(long userId) throws StorageException {
- return getUser(userId).getAdministrator();
+ public boolean notAdmin(long userId) throws StorageException {
+ return !getUser(userId).getAdministrator();
}
public void checkAdmin(long userId) throws StorageException, SecurityException {
@@ -134,16 +134,11 @@ public class PermissionsService {
if (!getUser(userId).getAdministrator() && !(clazz.equals(User.class) && userId == objectId)) {
var objects = storage.getObjects(clazz, new Request(
new Columns.Include("id"),
- new Condition.Permission(
- User.class, userId, clazz.equals(User.class) ? ManagedUser.class : clazz)));
- boolean found = false;
- for (var object : objects) {
- if (object.getId() == objectId) {
- found = true;
- break;
- }
- }
- if (!found) {
+ new Condition.And(
+ new Condition.Equals("id", "id", objectId),
+ new Condition.Permission(
+ User.class, userId, clazz.equals(User.class) ? ManagedUser.class : clazz))));
+ if (!objects.isEmpty()) {
throw new SecurityException(clazz.getSimpleName() + " access denied");
}
}
diff --git a/src/main/java/org/traccar/database/AttributesManager.java b/src/main/java/org/traccar/database/AttributesManager.java
deleted file mode 100644
index 28816645a..000000000
--- a/src/main/java/org/traccar/database/AttributesManager.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.traccar.database;
-
-import org.traccar.model.Attribute;
-
-public class AttributesManager extends ExtendedObjectManager<Attribute> {
-
- public AttributesManager(DataManager dataManager) {
- super(dataManager, Attribute.class);
- }
-
- @Override
- public void updateCachedItem(Attribute attribute) {
- Attribute cachedAttribute = getById(attribute.getId());
- cachedAttribute.setDescription(attribute.getDescription());
- cachedAttribute.setAttribute(attribute.getAttribute());
- cachedAttribute.setExpression(attribute.getExpression());
- cachedAttribute.setType(attribute.getType());
- }
-
-}
diff --git a/src/main/java/org/traccar/database/DataManager.java b/src/main/java/org/traccar/database/DataManager.java
index 9ac808a69..b5966ca9e 100644
--- a/src/main/java/org/traccar/database/DataManager.java
+++ b/src/main/java/org/traccar/database/DataManager.java
@@ -240,8 +240,9 @@ public class DataManager {
return storage.getPermissions(owner, property);
}
- public void linkObject(Class<?> owner, long ownerId, Class<?> property, long propertyId, boolean link)
- throws StorageException {
+ 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 {
diff --git a/src/main/java/org/traccar/database/PermissionsManager.java b/src/main/java/org/traccar/database/PermissionsManager.java
index 9a673c784..29bb8a27b 100644
--- a/src/main/java/org/traccar/database/PermissionsManager.java
+++ b/src/main/java/org/traccar/database/PermissionsManager.java
@@ -18,7 +18,6 @@ package org.traccar.database;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.Context;
-import org.traccar.model.Attribute;
import org.traccar.model.BaseModel;
import org.traccar.model.Calendar;
import org.traccar.model.Command;
@@ -368,26 +367,8 @@ public class PermissionsManager {
if (object.equals(Device.class)) {
checkDevice(userId, objectId);
- } else if (object.equals(Group.class)) {
- checkGroup(userId, objectId);
- } else if (object.equals(User.class) || object.equals(ManagedUser.class)) {
- checkUser(userId, objectId);
- } else if (object.equals(Geofence.class)) {
- manager = Context.getGeofenceManager();
- } else if (object.equals(Attribute.class)) {
- manager = Context.getAttributesManager();
- } else if (object.equals(Driver.class)) {
- manager = Context.getDriversManager();
- } else if (object.equals(Calendar.class)) {
- manager = Context.getCalendarManager();
} else if (object.equals(Command.class)) {
manager = Context.getCommandsManager();
- } else if (object.equals(Maintenance.class)) {
- manager = Context.getMaintenancesManager();
- } else if (object.equals(Notification.class)) {
- manager = Context.getNotificationManager();
- } else if (object.equals(Order.class)) {
- manager = Context.getOrderManager();
} else {
throw new IllegalArgumentException("Unknown object type");
}
@@ -409,7 +390,6 @@ public class PermissionsManager {
}
Context.getCalendarManager().refreshUserItems();
Context.getDriversManager().refreshUserItems();
- Context.getAttributesManager().refreshUserItems();
Context.getCommandsManager().refreshUserItems();
Context.getMaintenancesManager().refreshUserItems();
if (Context.getNotificationManager() != null) {
@@ -422,7 +402,6 @@ public class PermissionsManager {
Context.getGeofenceManager().refreshExtendedPermissions();
}
Context.getDriversManager().refreshExtendedPermissions();
- Context.getAttributesManager().refreshExtendedPermissions();
Context.getCommandsManager().refreshExtendedPermissions();
Context.getMaintenancesManager().refreshExtendedPermissions();
}
@@ -439,8 +418,6 @@ public class PermissionsManager {
Context.getGeofenceManager().refreshUserItems();
} else if (permission.getPropertyClass().equals(Driver.class)) {
Context.getDriversManager().refreshUserItems();
- } else if (permission.getPropertyClass().equals(Attribute.class)) {
- Context.getAttributesManager().refreshUserItems();
} else if (permission.getPropertyClass().equals(Calendar.class)) {
Context.getCalendarManager().refreshUserItems();
} else if (permission.getPropertyClass().equals(Command.class)) {
@@ -458,8 +435,6 @@ public class PermissionsManager {
Context.getGeofenceManager().refreshExtendedPermissions();
} else if (permission.getPropertyClass().equals(Driver.class)) {
Context.getDriversManager().refreshExtendedPermissions();
- } else if (permission.getPropertyClass().equals(Attribute.class)) {
- Context.getAttributesManager().refreshExtendedPermissions();
} else if (permission.getPropertyClass().equals(Command.class)) {
Context.getCommandsManager().refreshExtendedPermissions();
} else if (permission.getPropertyClass().equals(Maintenance.class)) {
diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
index 9dc170909..bec3d38e0 100644
--- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
+++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
@@ -34,11 +34,11 @@ import org.slf4j.LoggerFactory;
import org.traccar.BaseDataHandler;
import org.traccar.config.Config;
import org.traccar.config.Keys;
-import org.traccar.database.AttributesManager;
import org.traccar.database.IdentityManager;
import org.traccar.model.Attribute;
import org.traccar.model.Device;
import org.traccar.model.Position;
+import org.traccar.session.cache.CacheManager;
import javax.inject.Inject;
@@ -48,7 +48,7 @@ public class ComputedAttributesHandler extends BaseDataHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ComputedAttributesHandler.class);
private final IdentityManager identityManager;
- private final AttributesManager attributesManager;
+ private final CacheManager cacheManager;
private final JexlEngine engine;
@@ -56,9 +56,9 @@ public class ComputedAttributesHandler extends BaseDataHandler {
@Inject
public ComputedAttributesHandler(
- Config config, IdentityManager identityManager, AttributesManager attributesManager) {
+ Config config, IdentityManager identityManager, CacheManager cacheManager) {
this.identityManager = identityManager;
- this.attributesManager = attributesManager;
+ this.cacheManager = cacheManager;
engine = new JexlEngine();
engine.setStrict(true);
engine.setFunctions(Collections.singletonMap("math", Math.class));
@@ -107,8 +107,7 @@ public class ComputedAttributesHandler extends BaseDataHandler {
@Override
protected Position handlePosition(Position position) {
- Collection<Attribute> attributes = attributesManager.getItems(
- attributesManager.getAllDeviceItems(position.getDeviceId()));
+ Collection<Attribute> attributes = cacheManager.getDeviceObjects(position.getDeviceId(), Attribute.class);
for (Attribute attribute : attributes) {
if (attribute.getAttribute() != null) {
Object result = null;
diff --git a/src/main/java/org/traccar/model/Permission.java b/src/main/java/org/traccar/model/Permission.java
index bace6b7d4..41dfa43e4 100644
--- a/src/main/java/org/traccar/model/Permission.java
+++ b/src/main/java/org/traccar/model/Permission.java
@@ -31,12 +31,12 @@ import org.traccar.storage.QueryIgnore;
public class Permission {
- private static final Map<String, Class<?>> CLASSES = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ private static final Map<String, Class<? extends BaseModel>> CLASSES = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
static {
try {
for (Class<?> clazz : ClassScanner.findSubclasses(BaseModel.class)) {
- CLASSES.put(clazz.getSimpleName(), clazz);
+ CLASSES.put(clazz.getSimpleName(), (Class<? extends BaseModel>) clazz);
}
} catch (IOException | ReflectiveOperationException | URISyntaxException e) {
throw new RuntimeException(e);
@@ -45,9 +45,9 @@ public class Permission {
private final LinkedHashMap<String, Long> data;
- private final Class<?> ownerClass;
+ private final Class<? extends BaseModel> ownerClass;
private final long ownerId;
- private final Class<?> propertyClass;
+ private final Class<? extends BaseModel> propertyClass;
private final long propertyId;
public Permission(LinkedHashMap<String, Long> data) {
@@ -61,7 +61,9 @@ public class Permission {
propertyId = property.getValue();
}
- public Permission(Class<?> ownerClass, long ownerId, Class<?> propertyClass, long propertyId) {
+ public Permission(
+ Class<? extends BaseModel> ownerClass, long ownerId,
+ Class<? extends BaseModel> propertyClass, long propertyId) {
this.ownerClass = ownerClass;
this.ownerId = ownerId;
this.propertyClass = propertyClass;
@@ -105,7 +107,7 @@ public class Permission {
@QueryIgnore
@JsonIgnore
- public Class<?> getOwnerClass() {
+ public Class<? extends BaseModel> getOwnerClass() {
return ownerClass;
}
@@ -117,7 +119,7 @@ public class Permission {
@QueryIgnore
@JsonIgnore
- public Class<?> getPropertyClass() {
+ public Class<? extends BaseModel> getPropertyClass() {
return propertyClass;
}
diff --git a/src/main/java/org/traccar/storage/DatabaseStorage.java b/src/main/java/org/traccar/storage/DatabaseStorage.java
index e4e4f3294..91dd6b077 100644
--- a/src/main/java/org/traccar/storage/DatabaseStorage.java
+++ b/src/main/java/org/traccar/storage/DatabaseStorage.java
@@ -15,6 +15,7 @@
*/
package org.traccar.storage;
+import org.traccar.model.BaseModel;
import org.traccar.model.Device;
import org.traccar.model.Group;
import org.traccar.model.GroupedModel;
@@ -116,7 +117,8 @@ public class DatabaseStorage extends Storage {
@Override
public List<Permission> getPermissions(
- Class<?> ownerClass, long ownerId, Class<?> propertyClass, long propertyId) throws StorageException {
+ Class<? extends BaseModel> ownerClass, long ownerId,
+ Class<? extends BaseModel> propertyClass, long propertyId) throws StorageException {
StringBuilder query = new StringBuilder("SELECT * FROM ");
query.append(Permission.getStorageName(ownerClass, propertyClass));
var conditions = new LinkedList<Condition>();
diff --git a/src/main/java/org/traccar/storage/MemoryStorage.java b/src/main/java/org/traccar/storage/MemoryStorage.java
index 71e895428..f19897ff8 100644
--- a/src/main/java/org/traccar/storage/MemoryStorage.java
+++ b/src/main/java/org/traccar/storage/MemoryStorage.java
@@ -15,6 +15,7 @@
*/
package org.traccar.storage;
+import org.traccar.model.BaseModel;
import org.traccar.model.Pair;
import org.traccar.model.Permission;
import org.traccar.storage.query.Request;
@@ -54,7 +55,8 @@ public class MemoryStorage extends Storage {
@Override
public List<Permission> getPermissions(
- Class<?> ownerClass, long ownerId, Class<?> propertyClass, long propertyId) {
+ Class<? extends BaseModel> ownerClass, long ownerId,
+ Class<? extends BaseModel> propertyClass, long propertyId) {
return getPermissionsSet(ownerClass, propertyClass).stream()
.filter(pair -> ownerId == 0 || pair.getFirst().equals(ownerId))
.filter(pair -> propertyId == 0 || pair.getSecond().equals(propertyId))
diff --git a/src/main/java/org/traccar/storage/Storage.java b/src/main/java/org/traccar/storage/Storage.java
index 22b5aaedc..62dba0165 100644
--- a/src/main/java/org/traccar/storage/Storage.java
+++ b/src/main/java/org/traccar/storage/Storage.java
@@ -15,6 +15,7 @@
*/
package org.traccar.storage;
+import org.traccar.model.BaseModel;
import org.traccar.model.Permission;
import org.traccar.storage.query.Request;
@@ -31,24 +32,28 @@ public abstract class Storage {
public abstract void removeObject(Class<?> clazz, Request request) throws StorageException;
public abstract List<Permission> getPermissions(
- Class<?> ownerClass, long ownerId, Class<?> propertyClass, long propertyId) throws StorageException;
+ Class<? extends BaseModel> ownerClass, long ownerId,
+ Class<? extends BaseModel> propertyClass, long propertyId) throws StorageException;
public abstract void addPermission(Permission permission) throws StorageException;
public abstract void removePermission(Permission permission) throws StorageException;
public List<Permission> getPermissions(
- Class<?> ownerClass, Class<?> propertyClass) throws StorageException {
+ Class<? extends BaseModel> ownerClass,
+ Class<? extends BaseModel> propertyClass) throws StorageException {
return getPermissions(ownerClass, 0, propertyClass, 0);
}
public List<Permission> getPermissions(
- Class<?> ownerClass, long ownerId, Class<?> propertyClass) throws StorageException {
+ Class<? extends BaseModel> ownerClass, long ownerId,
+ Class<? extends BaseModel> propertyClass) throws StorageException {
return getPermissions(ownerClass, ownerId, propertyClass, 0);
}
public List<Permission> getPermissions(
- Class<?> ownerClass, Class<?> propertyClass, long propertyId) throws StorageException {
+ Class<? extends BaseModel> ownerClass,
+ Class<? extends BaseModel> propertyClass, long propertyId) throws StorageException {
return getPermissions(ownerClass, 0, propertyClass, propertyId);
}