Skip to content

Commit 116cf62

Browse files
committed
Wire async executor for record updates
1 parent 6347c31 commit 116cf62

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/main/java/gov/nist/oar/distrib/web/RPAAsyncExecutor.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import gov.nist.oar.distrib.service.rpa.RPARequestHandler;
88
import gov.nist.oar.distrib.service.rpa.exceptions.RequestProcessingException;
9+
import gov.nist.oar.distrib.service.rpa.model.Record;
910
import gov.nist.oar.distrib.service.rpa.model.RecordWrapper;
1011
import gov.nist.oar.distrib.service.rpa.model.UserInfoWrapper;
1112

@@ -40,4 +41,22 @@ public void handleAfterRecordCreationAsync(RecordWrapper wrapper, UserInfoWrappe
4041
e.getMessage(), e);
4142
}
4243
}
44+
45+
/**
46+
* Handle the post-processing of a record update (approval/decline) asynchronously.
47+
* This method does not throw any exceptions; rather, it logs any errors and continues.
48+
*
49+
* @param record The record that was updated.
50+
* @param status The approval status ("approved" or "declined").
51+
* @param datasetId The ID of the dataset associated with the record.
52+
*/
53+
@Async
54+
public void handleAfterRecordUpdateAsync(Record record, String status, String datasetId) {
55+
try {
56+
handler.handleAfterRecordUpdate(record, status, datasetId);
57+
} catch (RequestProcessingException e) {
58+
LOGGER.error("Async post-processing failed for record update (record ID {}): {}",
59+
record.getId(), e.getMessage(), e);
60+
}
61+
}
4362
}

src/main/java/gov/nist/oar/distrib/web/RPARequestHandlerController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import gov.nist.oar.distrib.service.RPACachingService;
44
import gov.nist.oar.distrib.service.rpa.RPARequestHandler;
55
import gov.nist.oar.distrib.service.rpa.RecordCreationResult;
6+
import gov.nist.oar.distrib.service.rpa.RecordUpdateResult;
67
import gov.nist.oar.distrib.service.rpa.exceptions.InvalidRequestException;
78
import gov.nist.oar.distrib.service.rpa.exceptions.RecaptchaClientException;
89
import gov.nist.oar.distrib.service.rpa.exceptions.RecaptchaServerException;
@@ -398,12 +399,18 @@ public ResponseEntity<RecordStatus> updateRecord(@PathVariable String id, @Reque
398399
if (tokenDetails != null) {
399400
LOGGER.debug("Updating record with ID: {}", id);
400401
String smeId = tokenDetails.get("userEmail");
401-
RecordStatus recordStatus = service.updateRecord(id, patch.getApprovalStatus(), smeId);
402+
RecordUpdateResult result = service.updateRecord(id, patch.getApprovalStatus(), smeId);
403+
404+
// Trigger async post-processing (caching, email notifications)
405+
asyncExecutor.handleAfterRecordUpdateAsync(
406+
result.getRecord(),
407+
patch.getApprovalStatus(),
408+
result.getDatasetId());
402409

403410
logUpdateAction(tokenDetails, id);
404411

405412
LOGGER.debug("Record successfully updated");
406-
return new ResponseEntity<RecordStatus>(recordStatus, HttpStatus.OK);
413+
return new ResponseEntity<RecordStatus>(result.getRecordStatus(), HttpStatus.OK);
407414
} else {
408415
LOGGER.error("Token is invalid");
409416
throw new UnauthorizedException("invalid token");

0 commit comments

Comments
 (0)