Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MccTest on case-sensitive DBs #141

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions mcc/src/org/labkey/mcc/query/TriggerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.collections.CaseInsensitiveHashMap;
import org.labkey.api.collections.CaseInsensitiveHashSet;
import org.labkey.api.data.CompareType;
import org.labkey.api.data.Container;
import org.labkey.api.data.ContainerManager;
Expand Down Expand Up @@ -261,15 +260,17 @@ public void possiblySendRabNotification(int reviewerId)
}
}

public int ensureMccAliasExists(Collection<String> ids, Map<Object, Object> existingAliases)
public int ensureMccAliasExists(Collection<String> rawIds, Map<Object, Object> existingAliases)
{
// NOTE: The incoming object can convert numeric IDs from strings to int, so manually convert:
ids = new CaseInsensitiveHashSet(ids.stream().map(String::valueOf).collect(Collectors.toSet()));
// Also, CaseInsensitiveSet will convert the keys to lowercase, which is problematic for case-sensitive databases
final CaseInsensitiveHashMap<String> idMap = new CaseInsensitiveHashMap<>();
rawIds.stream().map(String::valueOf).forEach(x -> idMap.put(x, x));

CaseInsensitiveHashMap<String> ciExistingAliases = new CaseInsensitiveHashMap<>();
existingAliases.forEach((key, val) -> ciExistingAliases.put(String.valueOf(key), String.valueOf(val)));

SimpleFilter filter = new SimpleFilter(FieldKey.fromString("subjectname"), ids, CompareType.IN);
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("subjectname"), idMap.values(), CompareType.IN);

final Set<String> aliasesFound = new HashSet<>();
TableInfo ti = QueryService.get().getUserSchema(_user, _container, MccSchema.NAME).getTable(MccSchema.TABLE_ANIMAL_MAPPING);
Expand All @@ -283,8 +284,8 @@ public int ensureMccAliasExists(Collection<String> ids, Map<Object, Object> exis
}
});

ids.removeAll(aliasesFound);
if (ids.isEmpty())
aliasesFound.forEach(idMap::remove);
if (idMap.isEmpty())
{
return 0;
}
Expand All @@ -293,7 +294,7 @@ public int ensureMccAliasExists(Collection<String> ids, Map<Object, Object> exis
try
{
AtomicInteger aliasesReused = new AtomicInteger(0);
ids.forEach(id -> {
idMap.forEach((key, id) -> {
CaseInsensitiveHashMap<Object> row = new CaseInsensitiveHashMap<>();
row.put("subjectname", id);
if (ciExistingAliases.containsKey(id))
Expand Down