Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions api/src/org/labkey/api/assay/AbstractAssayTsvDataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,8 @@ private DataIterator checkData(
DomainProperty wellLocationPropFinder = null;
DomainProperty wellLsidPropFinder = null;

RemapCache cache = new RemapCache();
RemapCache cacheWithoutPkLookup = new RemapCache();
RemapCache cacheWithPkLookup = new RemapCache();
Map<DomainProperty, TableInfo> remappableLookup = new HashMap<>();
Map<Long, ExpMaterial> materialCache = new LongHashMap<>();
Map<Long, Map<String, Long>> plateWellCache = new LongHashMap<>();
Expand Down Expand Up @@ -879,7 +880,12 @@ else if (entry.getKey().equalsIgnoreCase(ProvenanceService.PROVENANCE_INPUT_PROP
{
String s = o instanceof String ? (String) o : o.toString();
TableInfo lookupTable = remappableLookup.get(pd);
Object remapped = cache.remap(lookupTable, s, true);

// GitHub Issue #443: similar to LookupResolutionType.alternateThenPrimaryKey, we want to check if the string value remaps using alternate keys (titleColumn) first
Object remapped = cacheWithoutPkLookup.remap(lookupTable, s, false);
if (remapped == null)
remapped = cacheWithPkLookup.remap(lookupTable, s, true);

if (remapped == null)
{
if (SAMPLE_CONCEPT_URI.equals(pd.getConceptURI()))
Expand Down Expand Up @@ -1026,7 +1032,7 @@ else if (o instanceof MvFieldWrapper mvWrapper)
try
{
if (material == null)
material = exp.findExpMaterial(lookupContainer, user, materialName, byNameSS, cache, materialCache);
material = exp.findExpMaterial(lookupContainer, user, materialName, byNameSS, cacheWithoutPkLookup, materialCache);
}
catch (ValidationException ve)
{
Expand Down
23 changes: 22 additions & 1 deletion study/test/src/org/labkey/test/tests/study/AssayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,10 @@ public void testAssayLookupValidatorConversion()
_listHelper.bulkImportData(TestDataUtils.tsvStringFromRowMaps(List.of(
Map.of(valueField.getName(), "One"),
Map.of(valueField.getName(), "Two"),
Map.of(valueField.getName(), "123")
Map.of(valueField.getName(), "123"),
// GitHub Issue #443: value is the primary key for another row
Map.of(valueField.getName(), "5"), // pk = 4
Map.of(valueField.getName(), "6") // pk = 5
), List.of(valueField.getName()), true));

log("Create an assay with a results lookup field to the list, with lookup validator set");
Expand All @@ -1060,6 +1063,24 @@ public void testAssayLookupValidatorConversion()
.setLookupValidatorEnabled(false);
designerPage.clickFinish();
verifyAssayImportForLookupValidator(ISSUE_53625_ASSAY, lookupField, "RunWithoutLookupValidator", false);

log("GitHub Issue #443: Verify that importing a value that is also a primary key maps to the titleColumn value");
verifyAssayImportForPKValueThatIsTitleColumn(ISSUE_53625_ASSAY, lookupField, "RunWithPKandTitleColumn");
}

private void verifyAssayImportForPKValueThatIsTitleColumn(String assayName, FieldInfo lookupField, String runName)
{
String runDataStr = TestDataUtils.tsvStringFromRowMaps(List.of(
Map.of(lookupField.getName(), "4"), // pk 4, value 5
Map.of(lookupField.getName(), "5"), // pk 4, value 5
Map.of(lookupField.getName(), "6")), // pk 5, value 6
List.of(lookupField.getName()), true
);
importAssayData(assayName, runName, runDataStr);
clickAndWait(Locator.linkWithText(runName));
DataRegionTable dataTable = new DataRegionTable("Data", getDriver());
checker().verifyEquals("Incorrect number of results shown.", 3, dataTable.getDataRowCount());
checker().fatal().verifyEquals("Lookup values not as expected.", List.of("5", "5", "6"), dataTable.getColumnDataAsText(lookupField.getLabel()));
}

private void verifyAssayImportForLookupValidator(String assayName, FieldInfo lookupField, String runName, boolean validatorOn)
Expand Down