From 75374d646e3fe848e00eb7b959b557c0ed0ade68 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 1 Aug 2017 17:23:24 +0500 Subject: Fix retrieving objects by unknown tokens/uniqueId --- src/org/traccar/database/DriversManager.java | 6 +++--- src/org/traccar/database/UsersManager.java | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java index 9defa1931..930951460 100644 --- a/src/org/traccar/database/DriversManager.java +++ b/src/org/traccar/database/DriversManager.java @@ -23,7 +23,7 @@ import org.traccar.model.Driver; public class DriversManager extends ExtendedObjectManager { - private Map driversByUniqueId; + private Map driversByUniqueId; public DriversManager(DataManager dataManager) { super(dataManager, Driver.class); @@ -36,7 +36,7 @@ public class DriversManager extends ExtendedObjectManager { if (driversByUniqueId == null) { driversByUniqueId = new ConcurrentHashMap<>(getAllItems().size()); } - driversByUniqueId.put(driver.getUniqueId(), driver.getId()); + driversByUniqueId.put(driver.getUniqueId(), driver); } @Override @@ -68,6 +68,6 @@ public class DriversManager extends ExtendedObjectManager { } public Driver getDriverByUniqueId(String uniqueId) { - return getById(driversByUniqueId.get(uniqueId)); + return driversByUniqueId.get(uniqueId); } } diff --git a/src/org/traccar/database/UsersManager.java b/src/org/traccar/database/UsersManager.java index ed39f6cfa..576a9e6c7 100644 --- a/src/org/traccar/database/UsersManager.java +++ b/src/org/traccar/database/UsersManager.java @@ -25,7 +25,7 @@ import org.traccar.model.User; public class UsersManager extends SimpleObjectManager { - private Map usersTokens; + private Map usersTokens; public UsersManager(DataManager dataManager) { super(dataManager, User.class); @@ -39,7 +39,7 @@ public class UsersManager extends SimpleObjectManager { usersTokens = new ConcurrentHashMap<>(); } if (user.getToken() != null) { - usersTokens.put(user.getToken(), user.getId()); + usersTokens.put(user.getToken(), user); } } @@ -53,9 +53,7 @@ public class UsersManager extends SimpleObjectManager { protected void updateCachedItem(User user) { User cachedUser = getById(user.getId()); super.updateCachedItem(user); - if (user.getToken() != null) { - usersTokens.put(user.getToken(), user.getId()); - } + putToken(user); if (cachedUser.getToken() != null && !cachedUser.getToken().equals(user.getToken())) { usersTokens.remove(cachedUser.getToken()); } @@ -82,7 +80,7 @@ public class UsersManager extends SimpleObjectManager { } public User getUserByToken(String token) { - return getById(usersTokens.get(token)); + return usersTokens.get(token); } } -- cgit v1.2.3