|
296 | 296 | import static java.util.Collections.singleton; |
297 | 297 | import static java.util.stream.Collectors.toList; |
298 | 298 | import static java.util.stream.Collectors.toSet; |
| 299 | +import static org.labkey.api.assay.AbstractTsvAssayProvider.GPAT_PROTOCOL_LSID_PREFIX; |
299 | 300 | import static org.labkey.api.data.CompareType.IN; |
300 | 301 | import static org.labkey.api.data.DbScope.CommitTaskOption.POSTCOMMIT; |
301 | 302 | import static org.labkey.api.data.DbScope.CommitTaskOption.POSTROLLBACK; |
@@ -4229,6 +4230,7 @@ public void deleteExperimentRuns(Container container, final User user, @Nullable |
4229 | 4230 |
|
4230 | 4231 | try (DbScope.Transaction transaction = ensureTransaction()) |
4231 | 4232 | { |
| 4233 | + AssayService assayService = AssayService.get(); |
4232 | 4234 | // This can be slightly expensive to fetch, so don't do it multiple times if runs share protocols |
4233 | 4235 | Map<ExpProtocol, ProtocolImplementation> protocolImpls = new HashMap<>(); |
4234 | 4236 |
|
@@ -4264,18 +4266,21 @@ public void deleteExperimentRuns(Container container, final User user, @Nullable |
4264 | 4266 | throw new UnauthorizedException("Cannot delete rows from dataset " + dataset); |
4265 | 4267 | } |
4266 | 4268 |
|
4267 | | - AssayProvider provider = AssayService.get().getProvider(protocol); |
4268 | | - if (provider != null) |
| 4269 | + if (assayService != null) |
4269 | 4270 | { |
4270 | | - AssayTableMetadata tableMetadata = provider.getTableMetadata(protocol); |
4271 | | - SimpleFilter filter = new SimpleFilter(tableMetadata.getRunRowIdFieldKeyFromResults(), run.getRowId()); |
4272 | | - Collection<String> lsids = new TableSelector(tableInfo, singleton("LSID"), filter, null).getCollection(String.class); |
| 4271 | + AssayProvider provider = assayService.getProvider(protocol); |
| 4272 | + if (provider != null) |
| 4273 | + { |
| 4274 | + AssayTableMetadata tableMetadata = provider.getTableMetadata(protocol); |
| 4275 | + SimpleFilter filter = new SimpleFilter(tableMetadata.getRunRowIdFieldKeyFromResults(), run.getRowId()); |
| 4276 | + Collection<String> lsids = new TableSelector(tableInfo, singleton("LSID"), filter, null).getCollection(String.class); |
4273 | 4277 |
|
4274 | | - // Add an audit event to the link to study history |
4275 | | - publishService.addRecallAuditEvent(run.getContainer(), user, dataset, lsids.size(), null); |
| 4278 | + // Add an audit event to the link to study history |
| 4279 | + publishService.addRecallAuditEvent(run.getContainer(), user, dataset, lsids.size(), null); |
4276 | 4280 |
|
4277 | | - // Do the actual delete on the dataset for the rows in question |
4278 | | - dataset.deleteDatasetRows(user, lsids); |
| 4281 | + // Do the actual delete on the dataset for the rows in question |
| 4282 | + dataset.deleteDatasetRows(user, lsids); |
| 4283 | + } |
4279 | 4284 | } |
4280 | 4285 | } |
4281 | 4286 | } |
@@ -4339,12 +4344,12 @@ public void deleteExperimentRuns(Container container, final User user, @Nullable |
4339 | 4344 | // ideally this would be transacted as a commit task but we decided against it due to complications |
4340 | 4345 | run.archiveDataFiles(user); |
4341 | 4346 | // Re-index replaced run if replacing run is deleted |
4342 | | - if (run.getReplacesRuns() != null) |
| 4347 | + if (assayService != null && run.getReplacesRuns() != null) |
4343 | 4348 | { |
4344 | 4349 | List<ExpRunImpl> replacedRuns = run.getReplacesRuns(); |
4345 | 4350 | transaction.addCommitTask(() -> |
4346 | 4351 | replacedRuns.forEach(replacedRun -> |
4347 | | - AssayService.get().indexAssayRun(SearchService.get().defaultTask().getQueue(container, SearchService.PRIORITY.modified), replacedRun.getRowId()) |
| 4352 | + assayService.indexAssayRun(SearchService.get().defaultTask().getQueue(container, SearchService.PRIORITY.modified), replacedRun.getRowId()) |
4348 | 4353 | ), |
4349 | 4354 | DbScope.CommitTaskOption.POSTCOMMIT |
4350 | 4355 | ); |
@@ -6469,8 +6474,12 @@ public Protocol saveProtocol( |
6469 | 6474 | if (newProtocol) |
6470 | 6475 | { |
6471 | 6476 | // if protocol exists, throw error |
6472 | | - if (AssayService.get().getAssayProtocolByName(protocol.getContainer(), protocol.getName()) != null) |
6473 | | - throw new RuntimeSQLException(new SQLException("Assay design with name '" + protocol.getName() + "' already exists.")); |
| 6477 | + if (GPAT_PROTOCOL_LSID_PREFIX.equals(protocol.getLSIDNamespacePrefix()) && AssayService.get() != null) |
| 6478 | + { |
| 6479 | + ExpProtocol existingProtocol = AssayService.get().getAssayProtocolByName(protocol.getContainer(), protocol.getName()); |
| 6480 | + if (existingProtocol != null && GPAT_PROTOCOL_LSID_PREFIX.equals(existingProtocol.getLSIDNamespacePrefix())) |
| 6481 | + throw new RuntimeSQLException(new SQLException("Assay design with name '" + protocol.getName() + "' already exists.")); |
| 6482 | + } |
6474 | 6483 |
|
6475 | 6484 | result = Table.insert(user, getTinfoProtocol(), protocol); |
6476 | 6485 | } |
@@ -9793,26 +9802,30 @@ public Map<String, Integer> moveAssayRuns(@NotNull List<? extends ExpRun> assayR |
9793 | 9802 | AbstractQueryUpdateService.addTransactionAuditEvent(transaction, user, auditEvent); |
9794 | 9803 | } |
9795 | 9804 |
|
9796 | | - for (Map.Entry<ExpProtocol, List<ExpRun>> entry: protocolMap.entrySet()) |
| 9805 | + AssayService assayService = AssayService.get(); |
| 9806 | + if (assayService != null) |
9797 | 9807 | { |
9798 | | - ExpProtocol protocol = entry.getKey(); |
9799 | | - AssayProvider provider = AssayService.get().getProvider(protocol); |
9800 | | - List<ExpRun> runs = entry.getValue(); |
9801 | | - if (provider != null) |
| 9808 | + for (Map.Entry<ExpProtocol, List<ExpRun>> entry: protocolMap.entrySet()) |
9802 | 9809 | { |
9803 | | - provider.moveRuns(runs, targetContainer, user, assayMoveData); |
9804 | | - Map<String, Integer> counts = assayMoveData.counts(); |
9805 | | - int auditEventCount = expService.moveAuditEvents(targetContainer, runLsids); |
9806 | | - counts.put("auditEvents", counts.getOrDefault("auditEvents", 0) + auditEventCount); |
9807 | | - if (auditBehavior != null && AuditBehaviorType.NONE != auditBehavior) |
| 9810 | + ExpProtocol protocol = entry.getKey(); |
| 9811 | + AssayProvider provider = assayService.getProvider(protocol); |
| 9812 | + List<ExpRun> runs = entry.getValue(); |
| 9813 | + if (provider != null) |
9808 | 9814 | { |
9809 | | - for (ExpRun run : runs) |
| 9815 | + provider.moveRuns(runs, targetContainer, user, assayMoveData); |
| 9816 | + Map<String, Integer> counts = assayMoveData.counts(); |
| 9817 | + int auditEventCount = expService.moveAuditEvents(targetContainer, runLsids); |
| 9818 | + counts.put("auditEvents", counts.getOrDefault("auditEvents", 0) + auditEventCount); |
| 9819 | + if (auditBehavior != null && AuditBehaviorType.NONE != auditBehavior) |
9810 | 9820 | { |
9811 | | - run.setContainer(targetContainer); |
| 9821 | + for (ExpRun run : runs) |
| 9822 | + { |
| 9823 | + run.setContainer(targetContainer); |
9812 | 9824 |
|
9813 | | - // Issue 52570: include source and target containers in the audit event message |
9814 | | - String message = String.format("Moved from %s to %s", container.getPath(), targetContainer.getPath()); |
9815 | | - auditRunEvent(user, protocol, run, null, "Assay run was moved.", userComment, message); |
| 9825 | + // Issue 52570: include source and target containers in the audit event message |
| 9826 | + String message = String.format("Moved from %s to %s", container.getPath(), targetContainer.getPath()); |
| 9827 | + auditRunEvent(user, protocol, run, null, "Assay run was moved.", userComment, message); |
| 9828 | + } |
9816 | 9829 | } |
9817 | 9830 | } |
9818 | 9831 | } |
|
0 commit comments