From 1fb66b16c309de4ffee5334b7d868e8b9050a102 Mon Sep 17 00:00:00 2001 From: labkey-nicka Date: Wed, 29 Jul 2026 09:36:10 -0700 Subject: [PATCH 1/2] Use details view when looking up samples --- .../test/util/exp/SampleTypeAPIHelper.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/org/labkey/test/util/exp/SampleTypeAPIHelper.java b/src/org/labkey/test/util/exp/SampleTypeAPIHelper.java index a631cf83cf..f81b168bba 100644 --- a/src/org/labkey/test/util/exp/SampleTypeAPIHelper.java +++ b/src/org/labkey/test/util/exp/SampleTypeAPIHelper.java @@ -149,26 +149,28 @@ public static Map getSortedRowIdToSamplesMap(String containerPa */ public static Map getRowIdsForSamples(String containerPath, String sampleTypeName, List sampleNames) throws IOException, CommandException { - // Use json for the value parameter of the filter. This allows for tricky characters like ";" to be passed to the API. StringBuilder json = new StringBuilder("{json:["); Iterator iterator = sampleNames.iterator(); - while (iterator.hasNext()) { + while (iterator.hasNext()) + { String sampleName = iterator.next(); json.append(EscapeUtil.toJSONStr(sampleName)); - if (iterator.hasNext()) { + if (iterator.hasNext()) json.append(", "); - } else { + else json.append("]}"); - } } + // Use the details view to avoid column and filter settings on the default view + String detailsView = "~~DETAILS~~"; Connection connection = WebTestHelper.getRemoteApiConnection(); SelectRowsCommand cmd = new SelectRowsCommand("samples", sampleTypeName); - cmd.setColumns(Arrays.asList("RowId", "Name")); + cmd.setColumns(List.of("RowId", "Name")); cmd.addFilter("Name", json, Filter.Operator.IN); + cmd.setViewName(detailsView); SelectRowsResponse response = cmd.execute(connection, containerPath); @@ -176,10 +178,11 @@ public static Map getRowIdsForSamples(String containerPath, Str // There have been some TC failures where selectRows is not returning anything when it should. Adding this // logging to help get more logging when/if it happens again. - if(response.getRowCount().intValue() == 0) + if (response.getRowCount().intValue() == 0) { cmd = new SelectRowsCommand("samples", sampleTypeName); - cmd.setColumns(Arrays.asList("Name")); + cmd.setColumns(List.of("Name")); + cmd.setViewName(detailsView); SelectRowsResponse responseCount = cmd.execute(connection, containerPath); @@ -187,7 +190,7 @@ public static Map getRowIdsForSamples(String containerPath, Str sampleTypeName, responseCount.getRowCount().intValue()); List names = new ArrayList<>(); - for(Map row : responseCount.getRows()) + for (Map row : responseCount.getRows()) { Object tempName = row.get("Name"); names.add(tempName.toString()); @@ -198,7 +201,7 @@ public static Map getRowIdsForSamples(String containerPath, Str Map rowIds = new TreeMap<>(); - for(Map row : response.getRows()) + for (Map row : response.getRows()) { Object name = row.get("Name"); Object value = row.get("RowId"); @@ -206,8 +209,7 @@ public static Map getRowIdsForSamples(String containerPath, Str } // Check that the names returned from the query match the names sent in. - Assert.assertEquals(errorMsg, - new HashSet<>(sampleNames), rowIds.keySet()); + Assert.assertEquals(errorMsg, new HashSet<>(sampleNames), rowIds.keySet()); return rowIds; } From 72582a9177390b2fcbf205350c92fb72492fb6e9 Mon Sep 17 00:00:00 2001 From: labkey-nicka Date: Wed, 29 Jul 2026 10:13:04 -0700 Subject: [PATCH 2/2] Use JSONArray --- .../test/util/exp/SampleTypeAPIHelper.java | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/org/labkey/test/util/exp/SampleTypeAPIHelper.java b/src/org/labkey/test/util/exp/SampleTypeAPIHelper.java index f81b168bba..45c1d4d649 100644 --- a/src/org/labkey/test/util/exp/SampleTypeAPIHelper.java +++ b/src/org/labkey/test/util/exp/SampleTypeAPIHelper.java @@ -15,6 +15,7 @@ */ package org.labkey.test.util.exp; +import org.json.JSONArray; import org.junit.Assert; import org.labkey.remoteapi.CommandException; import org.labkey.remoteapi.Connection; @@ -28,14 +29,12 @@ import org.labkey.test.params.experiment.SampleTypeDefinition; import org.labkey.test.util.DomainUtils; import org.labkey.test.util.DomainUtils.DomainKind; -import org.labkey.test.util.EscapeUtil; import org.labkey.test.util.TestDataGenerator; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; @@ -150,19 +149,7 @@ public static Map getSortedRowIdToSamplesMap(String containerPa public static Map getRowIdsForSamples(String containerPath, String sampleTypeName, List sampleNames) throws IOException, CommandException { // Use json for the value parameter of the filter. This allows for tricky characters like ";" to be passed to the API. - StringBuilder json = new StringBuilder("{json:["); - - Iterator iterator = sampleNames.iterator(); - - while (iterator.hasNext()) - { - String sampleName = iterator.next(); - json.append(EscapeUtil.toJSONStr(sampleName)); - if (iterator.hasNext()) - json.append(", "); - else - json.append("]}"); - } + StringBuilder json = new StringBuilder("{json:").append(new JSONArray(sampleNames)).append("}"); // Use the details view to avoid column and filter settings on the default view String detailsView = "~~DETAILS~~";