File tree Expand file tree Collapse file tree
src/main/java/gov/cabinetoffice/gap/adminbackend/services Expand file tree Collapse file tree Original file line number Diff line number Diff 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 );
You can’t perform that action at this time.
0 commit comments