|
20 | 20 | import java.util.HashSet; |
21 | 21 | import java.util.List; |
22 | 22 | import java.util.Map; |
| 23 | +import java.util.NoSuchElementException; |
23 | 24 | import java.util.TreeMap; |
| 25 | +import java.util.stream.Collectors; |
24 | 26 |
|
25 | 27 | public class SampleTypeAPIHelper |
26 | 28 | { |
@@ -177,4 +179,30 @@ public static Map<String, Integer> getRowIdsForSamples(String containerPath, Str |
177 | 179 | return rowIds; |
178 | 180 | } |
179 | 181 |
|
| 182 | + /** |
| 183 | + * Get sample state IDs defined in the specified folder. Useful for updating sample status via API |
| 184 | + * @param containerPath Path to the folder where the sample statuses are defined |
| 185 | + */ |
| 186 | + public static Map<String, Integer> getSampleStateIds(String containerPath) throws IOException, CommandException |
| 187 | + { |
| 188 | + Connection cn = WebTestHelper.getRemoteApiConnection(); |
| 189 | + SelectRowsCommand insertCmd = new SelectRowsCommand("core", "DataStates"); |
| 190 | + return insertCmd.execute(cn, containerPath).getRows().stream().collect(Collectors.toMap(row -> |
| 191 | + (String) row.get("label"), row -> (Integer) row.get("rowId"))); |
| 192 | + } |
| 193 | + |
| 194 | + /** |
| 195 | + * Get sample state ID defined in the specified folder. Useful for updating sample status via API |
| 196 | + * @param name Label of the sample state |
| 197 | + * @param containerPath Path to the folder where the sample statuses are defined |
| 198 | + */ |
| 199 | + public static Integer getSampleStateId(String name, String containerPath) throws IOException, CommandException |
| 200 | + { |
| 201 | + Map<String, Integer> sampleStateIds = getSampleStateIds(containerPath); |
| 202 | + if(sampleStateIds.containsKey(name)) |
| 203 | + return sampleStateIds.get(name); |
| 204 | + else |
| 205 | + throw new NoSuchElementException("Sample state '%s' not defined in '%s': %s".formatted(name, containerPath, sampleStateIds.keySet())); |
| 206 | + } |
| 207 | + |
180 | 208 | } |
0 commit comments