diff options
Diffstat (limited to 'src/main/java/org/traccar/model/Permission.java')
-rw-r--r-- | src/main/java/org/traccar/model/Permission.java | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/main/java/org/traccar/model/Permission.java b/src/main/java/org/traccar/model/Permission.java index ad0176b39..0b2f0584f 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,23 +45,25 @@ 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) { this.data = data; var iterator = data.entrySet().iterator(); var owner = iterator.next(); - ownerClass = CLASSES.get(owner.getKey().substring(0, owner.getKey().length() - 2)); + ownerClass = getKeyClass(owner.getKey()); ownerId = owner.getValue(); var property = iterator.next(); - propertyClass = CLASSES.get(property.getKey().substring(0, property.getKey().length() - 2)); + propertyClass = getKeyClass(property.getKey()); 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; @@ -71,7 +73,11 @@ public class Permission { data.put(getKey(propertyClass), propertyId); } - private static String getKey(Class<?> clazz) { + public static Class<? extends BaseModel> getKeyClass(String key) { + return CLASSES.get(key.substring(0, key.length() - 2)); + } + + public static String getKey(Class<?> clazz) { return Introspector.decapitalize(clazz.getSimpleName()) + "Id"; } @@ -105,7 +111,7 @@ public class Permission { @QueryIgnore @JsonIgnore - public Class<?> getOwnerClass() { + public Class<? extends BaseModel> getOwnerClass() { return ownerClass; } @@ -117,7 +123,7 @@ public class Permission { @QueryIgnore @JsonIgnore - public Class<?> getPropertyClass() { + public Class<? extends BaseModel> getPropertyClass() { return propertyClass; } |