From 25fba4d04a8c5778f324e961c4a9ac0e0f9c733b Mon Sep 17 00:00:00 2001 From: Alice Lambois Date: Tue, 14 May 2024 14:59:41 +0200 Subject: [PATCH] Merge 2 set date services --- .../controller/rest/ScheduleController.java | 24 ++++--------------- .../rest/ScheduleControllerTest.java | 4 ++-- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/main/java/fr/insee/genesis/controller/rest/ScheduleController.java b/src/main/java/fr/insee/genesis/controller/rest/ScheduleController.java index 1618873f..2dc19a8e 100644 --- a/src/main/java/fr/insee/genesis/controller/rest/ScheduleController.java +++ b/src/main/java/fr/insee/genesis/controller/rest/ScheduleController.java @@ -41,7 +41,7 @@ public ResponseEntity getAllSchedules() { List storedSurveySchedules = scheduleApiPort.getAllSchedules(); - log.info("Returning " + storedSurveySchedules.size() + " schedule documents..."); + log.info("Returning {} schedule documents...", storedSurveySchedules.size()); return ResponseEntity.ok(storedSurveySchedules); } @@ -55,29 +55,13 @@ public ResponseEntity addSchedule( @Parameter(description = "Schedule end date and time", example = "2024-01-01T12:00:00") @RequestParam("scheduleEndDate") LocalDateTime scheduleEndDate ){ try { - log.info("New schedule request for survey " + surveyName); + log.info("New schedule request for survey {}", surveyName); scheduleApiPort.addSchedule(surveyName, serviceToCall, frequency, scheduleBeginDate, scheduleEndDate); }catch (InvalidCronExpressionException e){ - log.warn("Returned error for wrong frequency : " + frequency); + log.warn("Returned error for wrong frequency : {}", frequency); return ResponseEntity.badRequest().body("Wrong frequency syntax"); } - log.info("New schedule created for survey " + surveyName); - return ResponseEntity.ok().build(); - } - - @Operation(summary = "Update last execution date with now") - @PostMapping(path = "/updateLastExecutionDate") - public ResponseEntity updateSurveyLastExecution( - @Parameter(description = "Survey name to call Kraftwerk on") @RequestBody String surveyName - ) { - try { - log.debug("Got update last execution on {}", surveyName); - scheduleApiPort.updateLastExecutionName(surveyName, LocalDateTime.now()); - log.info("{} last execution updated !", surveyName); - }catch (NotFoundException e){ - log.warn("Survey {} not found !", surveyName); - return ResponseEntity.notFound().build(); - } + log.info("New schedule created for survey {}", surveyName); return ResponseEntity.ok().build(); } diff --git a/src/test/java/fr/insee/genesis/controller/rest/ScheduleControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/ScheduleControllerTest.java index d94b2f7f..096066ef 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/ScheduleControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/ScheduleControllerTest.java @@ -140,7 +140,7 @@ void addScheduleDedupTest() throws InvalidCronExpressionException { @Test void updateLastExecutionTest(){ //When - scheduleController.updateSurveyLastExecution("TESTSURVEY"); + scheduleController.setSurveyLastExecution("TESTSURVEY", LocalDateTime.now()); //Then List mongoStubFiltered = scheduleApiPortStub.mongoStub.stream().filter(scheduleDocument -> @@ -187,7 +187,7 @@ void wrongFrequencyTest(){ @Test void notFoundTest(){ //When+Then - ResponseEntity response = scheduleController.updateSurveyLastExecution("ERROR"); + ResponseEntity response = scheduleController.setSurveyLastExecution("ERROR", LocalDateTime.now()); Assertions.assertThat(response.getStatusCode().is4xxClientError()).isTrue(); } }