diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-07-25 15:31:03 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-25 15:31:03 +1200 |
commit | 6253fa291c3a2962fef2076c0cbb0f4e1ca8a3b4 (patch) | |
tree | 8cba8784f507140e871e290229ab9841034a0c07 /src/org/traccar/database/PermissionsManager.java | |
parent | c8e5c5e3da63646fd7c84d4f522bc8d7e5109982 (diff) | |
parent | f35961c2f4a3104a009d6e3cd6bc862e6810b998 (diff) | |
download | trackermap-server-6253fa291c3a2962fef2076c0cbb0f4e1ca8a3b4.tar.gz trackermap-server-6253fa291c3a2962fef2076c0cbb0f4e1ca8a3b4.tar.bz2 trackermap-server-6253fa291c3a2962fef2076c0cbb0f4e1ca8a3b4.zip |
Merge pull request #3385 from Abyss777/optimize_managers
Few managers optimizations
Diffstat (limited to 'src/org/traccar/database/PermissionsManager.java')
-rw-r--r-- | src/org/traccar/database/PermissionsManager.java | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java index b9cdfc36b..70969d749 100644 --- a/src/org/traccar/database/PermissionsManager.java +++ b/src/org/traccar/database/PermissionsManager.java @@ -115,11 +115,10 @@ public class PermissionsManager { public final void refreshUserPermissions() { userPermissions.clear(); try { - for (Map<String, Long> permission : dataManager.getPermissions(User.class, User.class)) { - getUserPermissions(permission.get(DataManager.makeNameId(User.class))) - .add(permission.get(DataManager.makeNameId(ManagedUser.class))); + for (Permission permission : dataManager.getPermissions(User.class, User.class)) { + getUserPermissions(permission.getOwnerId()).add(permission.getPropertyId()); } - } catch (SQLException error) { + } catch (SQLException | ClassNotFoundException error) { Log.warning(error); } } @@ -130,23 +129,20 @@ public class PermissionsManager { try { GroupTree groupTree = new GroupTree(Context.getDeviceManager().getAllGroups(), Context.getDeviceManager().getAllDevices()); - for (Map<String, Long> groupPermission : dataManager.getPermissions(User.class, Group.class)) { - Set<Long> userGroupPermissions = getGroupPermissions(groupPermission - .get(DataManager.makeNameId(User.class))); - Set<Long> userDevicePermissions = getDevicePermissions(groupPermission - .get(DataManager.makeNameId(User.class))); - userGroupPermissions.add(groupPermission.get(DataManager.makeNameId(Group.class))); - for (Group group : groupTree.getGroups(groupPermission.get(DataManager.makeNameId(Group.class)))) { + for (Permission groupPermission : dataManager.getPermissions(User.class, Group.class)) { + Set<Long> userGroupPermissions = getGroupPermissions(groupPermission.getOwnerId()); + Set<Long> userDevicePermissions = getDevicePermissions(groupPermission.getOwnerId()); + userGroupPermissions.add(groupPermission.getPropertyId()); + for (Group group : groupTree.getGroups(groupPermission.getPropertyId())) { userGroupPermissions.add(group.getId()); } - for (Device device : groupTree.getDevices(groupPermission.get(DataManager.makeNameId(Group.class)))) { + for (Device device : groupTree.getDevices(groupPermission.getPropertyId())) { userDevicePermissions.add(device.getId()); } } - for (Map<String, Long> devicePermission : dataManager.getPermissions(User.class, Device.class)) { - getDevicePermissions(devicePermission.get(DataManager.makeNameId(User.class))) - .add(devicePermission.get(DataManager.makeNameId(Device.class))); + for (Permission devicePermission : dataManager.getPermissions(User.class, Device.class)) { + getDevicePermissions(devicePermission.getOwnerId()).add(devicePermission.getPropertyId()); } groupDevices.clear(); @@ -156,7 +152,7 @@ public class PermissionsManager { } } - } catch (SQLException error) { + } catch (SQLException | ClassNotFoundException error) { Log.warning(error); } |