|
46 | 46 | import org.labkey.api.query.QueryService; |
47 | 47 | import org.labkey.api.query.UserSchema; |
48 | 48 | import org.labkey.api.security.RequiresPermission; |
| 49 | +import org.labkey.api.security.User; |
49 | 50 | import org.labkey.api.security.permissions.InsertPermission; |
50 | 51 | import org.labkey.api.security.permissions.ReadPermission; |
51 | 52 | import org.labkey.api.sequenceanalysis.SequenceOutputFile; |
@@ -200,6 +201,7 @@ public Object execute(SimpleApiJsonForm form, BindException errors) throws Excep |
200 | 201 | try (DbScope.Transaction transaction = DbScope.getLabKeyScope().ensureTransaction()) |
201 | 202 | { |
202 | 203 | BatchValidationException bve = new BatchValidationException(); |
| 204 | + validateBarcodes(readsetRows, getContainer(), getUser()); |
203 | 205 |
|
204 | 206 | Map<String, Integer> sampleMap = new HashMap<>(); |
205 | 207 | final List<Map<String, Object>> sampleRowsToInsert = new ArrayList<>(); |
@@ -308,12 +310,36 @@ public Object execute(SimpleApiJsonForm form, BindException errors) throws Excep |
308 | 310 | { |
309 | 311 | _log.error(e); |
310 | 312 |
|
| 313 | + errors.reject(ERROR_MSG, e.getMessage()); |
| 314 | + return null; |
311 | 315 | } |
312 | 316 |
|
313 | 317 | return new ApiSimpleResponse("success", true); |
314 | 318 | } |
315 | 319 | } |
316 | 320 |
|
| 321 | + private static void validateBarcodes(List<Map<String, Object>> readsetRows, Container c, User u) |
| 322 | + { |
| 323 | + Set<String> uniqueBarcodeNames = new HashSet<>(); |
| 324 | + readsetRows.forEach(rs -> { |
| 325 | + if (rs.get("barcode5") != null) { |
| 326 | + uniqueBarcodeNames.add((String.valueOf(rs.get("barcode5")))); |
| 327 | + } |
| 328 | + }); |
| 329 | + |
| 330 | + if (!uniqueBarcodeNames.isEmpty()) |
| 331 | + { |
| 332 | + TableInfo barcodes = QueryService.get().getUserSchema(u, c, SingleCellSchema.SEQUENCE_SCHEMA_NAME).getTable("barcodes"); |
| 333 | + Set<String> foundTags = new HashSet<>(new TableSelector(barcodes, PageFlowUtil.set("tag_name"), new SimpleFilter(FieldKey.fromString("tag_name"), uniqueBarcodeNames, CompareType.IN), null).getArrayList(String.class)); |
| 334 | + if (foundTags.size() != uniqueBarcodeNames.size()) |
| 335 | + { |
| 336 | + uniqueBarcodeNames.removeAll(foundTags); |
| 337 | + |
| 338 | + throw new ApiUsageException("The following barcodes were not found: " + StringUtils.join(uniqueBarcodeNames, ",")); |
| 339 | + } |
| 340 | + } |
| 341 | + } |
| 342 | + |
317 | 343 | private static List<Map<String, Object>> parseRows(SimpleApiJsonForm form, String propName, Container container) throws ApiUsageException |
318 | 344 | { |
319 | 345 | if (!form.getJsonObject().containsKey(propName)) |
|
0 commit comments