Skip to content
13 changes: 8 additions & 5 deletions api/src/org/labkey/api/exp/query/SamplesSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,17 @@ public ForeignKey materialIdForeignKey(@Nullable final ExpSampleType st, @Nullab

private TableInfo createLookupTableInfo()
{
// Hack to support lookup via RowId or Name
if (domainProperty != null && domainProperty.getPropertyType().getJdbcType().isText())
_columnName = "Name";

// GitHub Issue #688
if (st != null)
return getTable(tableName, getLookupContainerFilter());

ExpMaterialTable ret = ExperimentService.get().createMaterialTable(SamplesSchema.this, getLookupContainerFilter(), st);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't explore why the lookups were set up correctly for the all samples case, but I assume with your edits that this still works?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. with my edit, the All Samples lookup still works as expected. I believe it is because in ExpSchema.getMaterialIdForeignKey() the all samples case uses getTable() for the ExpSchema instead of calling the code here in SamplesSchema.materialIdForeignKey

ret.populate();
ret.overlayMetadata(ret.getPublicName(), SamplesSchema.this, new ArrayList<>());
if (domainProperty != null && domainProperty.getPropertyType().getJdbcType().isText())
{
// Hack to support lookup via RowId or Name
_columnName = "Name";
}
ret.setLocked(true);
return ret;
}
Expand Down
20 changes: 17 additions & 3 deletions study/test/src/org/labkey/test/tests/study/AssayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ public void testSampleFieldUpdate()
clickAndWait(Locator.linkWithText("view results"));
assertElementPresent("Sample lookup failed for: OS_1", new Locator.LinkLocator("OS_1"), 1);


log("Edit assay design and change Sample field to point to created Sample Type");
goToManageAssays();
clickAndWait(Locator.LinkLocator.linkWithText(SAMPLE_FIELD_TEST_ASSAY));
Expand All @@ -294,10 +293,21 @@ public void testSampleFieldUpdate()
importAssayData(SAMPLE_FIELD_TEST_ASSAY, TEST_RUN2, "SampleField\nS_1");
goToManageAssays().clickAndWait(Locator.linkWithText(SAMPLE_FIELD_TEST_ASSAY));
clickAndWait(Locator.linkWithText("view results"));
// assertElementPresent("Sample lookup failed for: OS_1", new Locator.LinkLocator("OS_1"), 1); //TODO this becomes the RowId "<123>" after change. Issue #40047

DataRegionTable table = new DataRegionTable("Data", getDriver());
List<String> sampleFieldValues = table.getColumnDataAsText("SampleField");
assertTrue("First sample should not resolve to sample type", sampleFieldValues.get(0).startsWith("<"));
assertEquals("Second sample should resolve to sample type", "S_1", sampleFieldValues.get(1));
assertElementPresent("Sample lookup failed for: S_1", new Locator.LinkLocator("S_1"), 1);

log("GitHub Issue #688: verify sample lookup to createdBy");
_customizeViewsHelper.openCustomizeViewPanel();
_customizeViewsHelper.addColumn("SampleField/CreatedBy");
_customizeViewsHelper.applyCustomView();
table = new DataRegionTable("Data", getDriver());
List<String> createdByValues = table.getColumnDataAsText("SampleField/CreatedBy");
assertEquals("First sample should not have a createdBy since it doesn't resolve", " ", createdByValues.get(0));
assertEquals("Second sample should have a createdBy since it resolves to a sample type", getCurrentUserName(), createdByValues.get(1));

log("Edit assay design and change Sample field to point back to 'All Samples'");
goToManageAssays();
clickAndWait(Locator.LinkLocator.linkWithText(SAMPLE_FIELD_TEST_ASSAY));
Expand All @@ -319,6 +329,10 @@ public void testSampleFieldUpdate()
assertElementPresent("Sample lookup failed for: S_2", new Locator.LinkLocator("S_2"), 1);
assertElementPresent("Sample lookup failed for: OS_2", new Locator.LinkLocator("OS_2"), 1);

log("GitHub Issue #688: verify sample lookup to createdBy");
table = new DataRegionTable("Data", getDriver());
for (int i = 0; i < table.getDataRowCount(); i++)
assertEquals("Row " + i + " should have current user as createdBy since they all resolve to samples", getCurrentUserName(), table.getDataAsText(i, "SampleField/CreatedBy"));
}

private void importAssayData(String assayName, String runName, String runDataStr)
Expand Down
Loading