Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Commit f251236

Browse files
committed
delete batch entity when deleting batch contents
1 parent 8f33016 commit f251236

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

src/main/java/org/brapi/test/BrAPITestServer/controller/core/BatchesApiController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,11 @@ public ResponseEntity<BatchesSingleResponse> batchesBatchDbIdDelete(
179179
BrAPIComponent component = componentFactory.getComponent(batchType);
180180
if (hardDelete) {
181181
component.deleteBatchData(batch.getData());
182-
return responseOK(new BatchesSingleResponse(), null);
182+
batchService.deleteBatch(batchDbId);
183+
return responseNoContent();
183184
}
184185
component.softDeleteBatchData(batch.getData());
185-
return responseOK(new BatchesSingleResponse(), null);
186+
batchService.deleteBatch(batchDbId);
187+
return responseNoContent();
186188
}
187189
}

src/main/java/org/brapi/test/BrAPITestServer/exceptions/BatchDeleteWrongTypeException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public class BatchDeleteWrongTypeException extends BrAPIServerException {
99
public BatchDeleteWrongTypeException(BatchTypes requiredType, BatchTypes suppliedType, String batchDeleteDbId, HttpStatus status) {
1010
super(status, "");
1111
String msg = "The " + suppliedType.toString() + " batch delete " + batchDeleteDbId + " must be of type " + requiredType.toString();
12+
this.setResponseMessage(msg);
1213
}
1314
}

src/main/java/org/brapi/test/BrAPITestServer/service/core/BatchService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ public List<BatchSummary> saveNewBatch(@Valid List<BatchNewRequest> requests) th
103103
}
104104

105105
public void deleteBatch(String batchDbId) throws BrAPIServerException {
106-
BatchDetails batch = getBatch(batchDbId);
107-
batchRepository.deleteAllByIdInBatch(batch.getData());
106+
batchRepository.deleteAllByIdInBatch(Arrays.asList(batchDbId));
108107
}
109108

110109
private BatchDetails convertToDetails(BatchEntity entity) {

src/main/java/org/brapi/test/BrAPITestServer/service/core/ListService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public List<ListSummary> findBatchDeleteLists(String batchDeleteDbId, Metadata m
4545
throw new BatchDeleteWrongTypeException(BatchTypes.LISTS, details.getBatchType(), batchDeleteDbId, HttpStatus.BAD_REQUEST);
4646
}
4747

48+
// Check if the batch is empty
49+
if (details.getData().isEmpty()) {
50+
return new ArrayList<>();
51+
}
52+
4853
// Get the list summaries referenced in the batch delete
4954
ListSearchRequest request = new ListSearchRequest();
5055
details.getData().forEach(request::addListDbIdsItem);

src/main/java/org/brapi/test/BrAPITestServer/service/core/TrialService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public List<Trial> findBatchDeleteTrials(String batchDeleteDbId, Metadata metada
5656
throw new BatchDeleteWrongTypeException(BatchTypes.TRIALS, details.getBatchType(), batchDeleteDbId, HttpStatus.BAD_REQUEST);
5757
}
5858

59+
// Check if the batch is empty
60+
if (details.getData().isEmpty()) {
61+
return new ArrayList<>();
62+
}
63+
5964
// Get the trials referenced in the batch delete
6065
TrialSearchRequest request = new TrialSearchRequest();
6166
details.getData().forEach(request::addTrialDbIdsItem);

src/main/java/org/brapi/test/BrAPITestServer/service/geno/SampleService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public List<Sample> findBatchDeleteSamples(String batchDeleteDbId, Metadata meta
7373
throw new BatchDeleteWrongTypeException(BatchTypes.SAMPLES, details.getBatchType(), batchDeleteDbId, HttpStatus.BAD_REQUEST);
7474
}
7575

76+
// Check if the batch is empty
77+
if (details.getData().isEmpty()) {
78+
return new ArrayList<>();
79+
}
80+
7681
// Get the list summaries referenced in the batch delete
7782
SampleSearchRequest request = new SampleSearchRequest();
7883
details.getData().forEach(request::addSampleDbIdsItem);

0 commit comments

Comments
 (0)