aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/PermissionsManager.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-03-14 12:05:25 +0500
committerAbyss777 <abyss@fox5.ru>2017-03-14 12:05:25 +0500
commite1deb7ae138a8821fd91cf85321b68c5a73675c7 (patch)
treeb313448ef355af5e9d70d717b503e31920f2bca2 /src/org/traccar/database/PermissionsManager.java
parent31ab23aeacce2ed9777ea38cdaf4cda199fc3a86 (diff)
downloadtrackermap-server-e1deb7ae138a8821fd91cf85321b68c5a73675c7.tar.gz
trackermap-server-e1deb7ae138a8821fd91cf85321b68c5a73675c7.tar.bz2
trackermap-server-e1deb7ae138a8821fd91cf85321b68c5a73675c7.zip
Implemented helper lookupPreference
Diffstat (limited to 'src/org/traccar/database/PermissionsManager.java')
-rw-r--r--src/org/traccar/database/PermissionsManager.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index 5313859df..0607a2141 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -25,6 +25,8 @@ import org.traccar.model.Server;
import org.traccar.model.User;
import org.traccar.model.UserPermission;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
@@ -395,4 +397,32 @@ public class PermissionsManager {
return users.get(usersTokens.get(token));
}
+ public Object lookupPreference(long userId, String key, Object defaultValue) {
+ String methodName = "get" + key.substring(0, 1).toUpperCase() + key.substring(1);
+ Object preference;
+ Object serverPreference = null;
+ Object userPreference = null;
+ try {
+ Method method = null;
+ method = User.class.getMethod(methodName, (Class<?>[]) null);
+ if (method != null) {
+ userPreference = method.invoke(users.get(userId), (Object[]) null);
+ }
+ method = null;
+ method = Server.class.getMethod(methodName, (Class<?>[]) null);
+ if (method != null) {
+ serverPreference = method.invoke(server, (Object[]) null);
+ }
+ } catch (NoSuchMethodException | SecurityException | IllegalAccessException
+ | IllegalArgumentException | InvocationTargetException exception) {
+ return defaultValue;
+ }
+ if (server.getForceSettings()) {
+ preference = serverPreference != null ? serverPreference : userPreference;
+ } else {
+ preference = userPreference != null ? userPreference : serverPreference;
+ }
+ return preference != null ? preference : defaultValue;
+ }
+
}