diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-03-14 22:24:17 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-14 22:24:17 +1300 |
commit | e85f2a54420aa1299ea70b0bcf4a0c870620a31a (patch) | |
tree | 6a0ce5ded2fd24e5cf98f5e5f04095a03593105d /src/org/traccar/database/PermissionsManager.java | |
parent | b3e2f211c3a3c64c8fa704ba1942970bb97f8eae (diff) | |
parent | 1b499620810fe6d376a4a72c5ab66b6be2f4af5c (diff) | |
download | trackermap-server-e85f2a54420aa1299ea70b0bcf4a0c870620a31a.tar.gz trackermap-server-e85f2a54420aa1299ea70b0bcf4a0c870620a31a.tar.bz2 trackermap-server-e85f2a54420aa1299ea70b0bcf4a0c870620a31a.zip |
Merge pull request #3001 from Abyss777/timezone
Timezone field to User and Server model
Diffstat (limited to 'src/org/traccar/database/PermissionsManager.java')
-rw-r--r-- | src/org/traccar/database/PermissionsManager.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java index 5313859df..e4bd6f5db 100644 --- a/src/org/traccar/database/PermissionsManager.java +++ b/src/org/traccar/database/PermissionsManager.java @@ -25,6 +25,7 @@ import org.traccar.model.Server; import org.traccar.model.User; import org.traccar.model.UserPermission; +import java.lang.reflect.Method; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; @@ -395,4 +396,31 @@ 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 (ReflectiveOperationException | SecurityException | IllegalArgumentException exception) { + return defaultValue; + } + if (server.getForceSettings()) { + preference = serverPreference != null ? serverPreference : userPreference; + } else { + preference = userPreference != null ? userPreference : serverPreference; + } + return preference != null ? preference : defaultValue; + } + } |