55import org .apache .logging .log4j .Logger ;
66import org .jetbrains .annotations .Nullable ;
77import org .labkey .api .collections .CaseInsensitiveHashMap ;
8- import org .labkey .api .collections .CaseInsensitiveHashSet ;
98import org .labkey .api .data .CompareType ;
109import org .labkey .api .data .Container ;
1110import org .labkey .api .data .ContainerManager ;
@@ -261,15 +260,17 @@ public void possiblySendRabNotification(int reviewerId)
261260 }
262261 }
263262
264- public int ensureMccAliasExists (Collection <String > ids , Map <Object , Object > existingAliases )
263+ public int ensureMccAliasExists (Collection <String > rawIds , Map <Object , Object > existingAliases )
265264 {
266265 // NOTE: The incoming object can convert numeric IDs from strings to int, so manually convert:
267- ids = new CaseInsensitiveHashSet (ids .stream ().map (String ::valueOf ).collect (Collectors .toSet ()));
266+ // Also, CaseInsensitiveSet will convert the keys to lowercase, which is problematic for case-sensitive databases
267+ final CaseInsensitiveHashMap <String > idMap = new CaseInsensitiveHashMap <>();
268+ rawIds .stream ().map (String ::valueOf ).forEach (x -> idMap .put (x , x ));
268269
269270 CaseInsensitiveHashMap <String > ciExistingAliases = new CaseInsensitiveHashMap <>();
270271 existingAliases .forEach ((key , val ) -> ciExistingAliases .put (String .valueOf (key ), String .valueOf (val )));
271272
272- SimpleFilter filter = new SimpleFilter (FieldKey .fromString ("subjectname" ), ids , CompareType .IN );
273+ SimpleFilter filter = new SimpleFilter (FieldKey .fromString ("subjectname" ), idMap . values () , CompareType .IN );
273274
274275 final Set <String > aliasesFound = new HashSet <>();
275276 TableInfo ti = QueryService .get ().getUserSchema (_user , _container , MccSchema .NAME ).getTable (MccSchema .TABLE_ANIMAL_MAPPING );
@@ -283,8 +284,8 @@ public int ensureMccAliasExists(Collection<String> ids, Map<Object, Object> exis
283284 }
284285 });
285286
286- ids . removeAll ( aliasesFound );
287- if (ids .isEmpty ())
287+ aliasesFound . forEach ( idMap :: remove );
288+ if (idMap .isEmpty ())
288289 {
289290 return 0 ;
290291 }
@@ -293,7 +294,7 @@ public int ensureMccAliasExists(Collection<String> ids, Map<Object, Object> exis
293294 try
294295 {
295296 AtomicInteger aliasesReused = new AtomicInteger (0 );
296- ids .forEach (id -> {
297+ idMap .forEach (( key , id ) -> {
297298 CaseInsensitiveHashMap <Object > row = new CaseInsensitiveHashMap <>();
298299 row .put ("subjectname" , id );
299300 if (ciExistingAliases .containsKey (id ))
0 commit comments