From 986b034e3077e93707d350267dd879ff20c4457e Mon Sep 17 00:00:00 2001 From: Edwin Tan Date: Thu, 5 Dec 2024 10:55:47 -0800 Subject: [PATCH] add logging when starting task and when task executes successfully --- .../cms/gov/madie/measure/resources/MeasureController.java | 5 ++++- .../cms/gov/madie/measure/services/MeasureSetService.java | 4 ++++ .../gov/madie/measure/resources/MeasureControllerTest.java | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/cms/gov/madie/measure/resources/MeasureController.java b/src/main/java/cms/gov/madie/measure/resources/MeasureController.java index 84d92370..949a4669 100644 --- a/src/main/java/cms/gov/madie/measure/resources/MeasureController.java +++ b/src/main/java/cms/gov/madie/measure/resources/MeasureController.java @@ -332,7 +332,10 @@ public ResponseEntity deleteCmsId( HttpServletRequest request, @PathVariable String measureId, @RequestParam(name = "cmsId") Integer cmsId, - @Value("${admin-api-key}") String apiKey) { + @Value("${admin-api-key}") String apiKey, + Principal principal) { + log.info("User [{}] - Started admin task [deleteCmsId] and is attempting to delete " + + "CMS id [{}] from measure with measure id [{}]", principal.getName(), cmsId, measureId); return ResponseEntity.status(HttpStatus.OK) .body(measureSetService.deleteCmsId(measureId, cmsId)); } diff --git a/src/main/java/cms/gov/madie/measure/services/MeasureSetService.java b/src/main/java/cms/gov/madie/measure/services/MeasureSetService.java index 41b2d225..dbf6c008 100644 --- a/src/main/java/cms/gov/madie/measure/services/MeasureSetService.java +++ b/src/main/java/cms/gov/madie/measure/services/MeasureSetService.java @@ -185,6 +185,10 @@ public String deleteCmsId(String measureId, Integer cmsId) { measureSet.setCmsId(null); measureSetRepository.save(measureSet); + log.info("With the measure id of [{}], successfully queried " + + "for its measure set with measure set id of [{}] and deleted CMS id " + + "of [{}] from the measure set", measureId, measureSetId, cmsId); + return String.format("CMS id of %s was deleted successfully from " + "measure set with measure set id of %s", cmsId, measureSetId); } else { diff --git a/src/test/java/cms/gov/madie/measure/resources/MeasureControllerTest.java b/src/test/java/cms/gov/madie/measure/resources/MeasureControllerTest.java index 03d300fb..6b11835d 100644 --- a/src/test/java/cms/gov/madie/measure/resources/MeasureControllerTest.java +++ b/src/test/java/cms/gov/madie/measure/resources/MeasureControllerTest.java @@ -27,6 +27,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.mock.web.MockHttpServletRequest; import java.io.UnsupportedEncodingException; import java.security.Principal; @@ -264,6 +265,9 @@ void createCmsId() { @Test void deleteCmsId() { + Principal principal = mock(Principal.class); + MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); + String measureId = "measureId"; final MeasureSet measureSet = @@ -279,7 +283,7 @@ void deleteCmsId() { when(measureSetService.deleteCmsId(anyString(), anyInt())).thenReturn(expectedBody); - ResponseEntity response = controller.deleteCmsId(null, measureId, measureSet.getCmsId(), "apiKey"); + ResponseEntity response = controller.deleteCmsId(mockHttpServletRequest, measureId, measureSet.getCmsId(), "apiKey", principal); assertThat(response.getBody(), is(notNullValue())); assertEquals(expectedBody, response.getBody());