diff --git a/Model/src/main/java/org/gusdb/wdk/model/user/UserCache.java b/Model/src/main/java/org/gusdb/wdk/model/user/UserCache.java index 19aaca2ea..2d7239e5f 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/user/UserCache.java +++ b/Model/src/main/java/org/gusdb/wdk/model/user/UserCache.java @@ -23,7 +23,7 @@ public UserCache(UserFactory userFactory) { */ public UserCache(User user) { put(user.getUserId(), user); - _userFactory = null; + _userFactory = user.getWdkModel().getUserFactory(); } public void loadUsersByIds(List userIds) { @@ -41,13 +41,10 @@ public User get(Object id) { } Long userId = (Long)id; if (!containsKey(userId)) { - if (_userFactory != null) { + synchronized(this) { put(userId, _userFactory.getUserById(userId) .orElseThrow(() -> new WdkRuntimeException("User with ID " + userId + " does not exist."))); } - else { - throw new WdkRuntimeException("No-lookup cache does not contain the requested user (" + userId + ")."); - } } return super.get(userId); } diff --git a/Model/src/main/java/org/gusdb/wdk/model/user/UserFactory.java b/Model/src/main/java/org/gusdb/wdk/model/user/UserFactory.java index fcd98ac64..5be064650 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/user/UserFactory.java +++ b/Model/src/main/java/org/gusdb/wdk/model/user/UserFactory.java @@ -180,7 +180,18 @@ public void resetPassword(String loginName) throws InvalidUsernameOrEmailExcepti public Map getUsersById(List userIds) { // ensure a unique list userIds = new ArrayList<>(new HashSet<>(userIds)); - return OAuthQuerier.getUsersById(_client, _config, userIds, json -> new BasicUser(_wdkModel, json)); + Map userMap = OAuthQuerier.getUsersById(_client, _config, userIds, json -> new BasicUser(_wdkModel, json)); + // FIXME: This is a temporary hack to account for guests created before the + // implementation of bearer tokens who still have WDK steps/strats. Eventually + // these guests should be removed during regular maintenance cleanup; once all + // guests created before spring 2024 are removed, this code can also be removed. + for (Long userId : userIds) { + if (userMap.get(userId) == null) { + // OAuth does not know about this user; trust that it is a guest + userMap.put(userId, new BasicUser(_wdkModel, userId, true, userId.toString(), userId.toString())); + } + } + return userMap; } public Map getUsersByEmail(List emails) { diff --git a/Model/src/main/java/org/gusdb/wdk/model/user/UserPasswordEmailer.java b/Model/src/main/java/org/gusdb/wdk/model/user/UserPasswordEmailer.java index 8806d2d42..8db094bfc 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/user/UserPasswordEmailer.java +++ b/Model/src/main/java/org/gusdb/wdk/model/user/UserPasswordEmailer.java @@ -1,6 +1,5 @@ package org.gusdb.wdk.model.user; -import java.util.Optional; import java.util.regex.Matcher; import org.gusdb.wdk.model.Attachment; diff --git a/Model/src/main/java/org/gusdb/wdk/model/user/UserReferenceFactory.java b/Model/src/main/java/org/gusdb/wdk/model/user/UserReferenceFactory.java index 4b81ec6fe..d7f72f05c 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/user/UserReferenceFactory.java +++ b/Model/src/main/java/org/gusdb/wdk/model/user/UserReferenceFactory.java @@ -1,6 +1,5 @@ package org.gusdb.wdk.model.user; -import java.sql.Timestamp; import java.sql.Types; import java.util.Date; import java.util.Optional; diff --git a/Model/src/test/java/org/gusdb/wdk/model/fix/table/edaanalysis/plugins/VDIMigrationPluginTest.java b/Model/src/test/java/org/gusdb/wdk/model/fix/table/edaanalysis/plugins/VDIMigrationPluginTest.java index b94a1f653..b68661501 100644 --- a/Model/src/test/java/org/gusdb/wdk/model/fix/table/edaanalysis/plugins/VDIMigrationPluginTest.java +++ b/Model/src/test/java/org/gusdb/wdk/model/fix/table/edaanalysis/plugins/VDIMigrationPluginTest.java @@ -1,6 +1,11 @@ package org.gusdb.wdk.model.fix.table.edaanalysis.plugins; -import org.gusdb.wdk.model.WdkModel; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Objects; +import java.util.Optional; + import org.gusdb.wdk.model.fix.table.TableRowInterfaces; import org.gusdb.wdk.model.fix.table.edaanalysis.AnalysisRow; import org.json.JSONObject; @@ -9,21 +14,14 @@ import org.junit.Test; import org.mockito.Mockito; -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Objects; -import java.util.Optional; - public class VDIMigrationPluginTest { - private WdkModel mockedModel; + private ClassLoader classLoader; private VDIEntityIdRetriever retriever; @Before public void setup() { classLoader = getClass().getClassLoader(); - mockedModel = Mockito.mock(WdkModel.class); retriever = Mockito.mock(VDIEntityIdRetriever.class); }