Skip to content

Commit 4c6c4a7

Browse files
Implement idempotency check for spotlight submissions in SpotlightBatchService
1 parent e8ec48f commit 4c6c4a7

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/main/java/gov/cabinetoffice/gap/adminbackend/services/SpotlightBatchService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ public SpotlightBatch addSpotlightSubmissionToSpotlightBatch(SpotlightSubmission
107107
UUID spotlightBatchId) {
108108
final SpotlightBatch spotlightBatch = getSpotlightBatch(spotlightBatchId);
109109
final List<SpotlightSubmission> existingSpotlightSubmissions = spotlightBatch.getSpotlightSubmissions();
110+
111+
// Check if submission is already in the batch (idempotent operation)
112+
boolean alreadyExists = existingSpotlightSubmissions != null
113+
&& existingSpotlightSubmissions.stream()
114+
.anyMatch(s -> s.getId().equals(spotlightSubmission.getId()));
115+
116+
if (alreadyExists) {
117+
log.info("Submission {} is already in batch {}. Returning existing batch (idempotent).",
118+
spotlightSubmission.getId(), spotlightBatchId);
119+
return spotlightBatch;
120+
}
121+
110122
final List<SpotlightBatch> existingSpotlightBatches = spotlightSubmission.getBatches();
111123

112124
existingSpotlightSubmissions.add(spotlightSubmission);

0 commit comments

Comments
 (0)