Skip to content
Open
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
22 changes: 22 additions & 0 deletions src/org/labkey/test/util/exp/SampleTypeAPIHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.Assert;
import org.labkey.remoteapi.CommandException;
import org.labkey.remoteapi.Connection;
import org.labkey.remoteapi.query.ContainerFilter;
import org.labkey.remoteapi.query.Filter;
import org.labkey.remoteapi.query.SelectRowsCommand;
import org.labkey.remoteapi.query.SelectRowsResponse;
Expand Down Expand Up @@ -201,6 +202,27 @@ public static Map<String, Integer> getRowIdsForSamples(String containerPath, Str
return rowIds;
}

/**
* Row ids of every sample type named {@code sampleTypeName} that is visible from {@code containerPath}, in the
* CurrentPlusProjectAndShared scope a sample type lookup resolves against.
*
* <p>Manufacturing a rowId/name collision needs the id the server actually assigned, because
* {@code exp.MaterialSource.RowId} is a database-wide sequence: a hardcoded numeric sample type name collides
* only when the sequence happens to cooperate. Require exactly one match as well, since a resolver reports an
* ambiguity rather than picking, and that error is swallowed by the import code.
*/
public static List<Integer> getSampleTypeRowIds(String containerPath, String sampleTypeName) throws IOException, CommandException
{
SelectRowsCommand cmd = new SelectRowsCommand("exp", "SampleSets");
cmd.setColumns(List.of("RowId"));
cmd.addFilter("Name", sampleTypeName, Filter.Operator.EQUAL);
cmd.setContainerFilter(ContainerFilter.CurrentPlusProjectAndShared);

return cmd.execute(WebTestHelper.getRemoteApiConnection(), containerPath).getRows().stream()
.map(row -> Integer.parseInt(row.get("RowId").toString()))
.toList();
}

/**
* Get sample state IDs defined in the specified project/folder. Useful for updating sample status via API
* @param containerPath Path to the project/folder where the sample statuses are defined (typically project)
Expand Down