From 495904fd27c11f567daeedd58b8d235a334e47ba Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 19 Sep 2023 09:04:47 -0600 Subject: [PATCH] GRAD2-2312 HD-21648-GRAD - P3 - Regeneration of the Graduated Student SCHOOL Report --- .../controller/JobLauncherController.java | 8 ++++---- .../BaseRunCompletionNotificationListener.java | 6 +++--- .../gov/educ/api/batchgraduation/rest/RestUtils.java | 10 +++++++--- .../educ/api/batchgraduation/util/RestUtilsTest.java | 12 +++++++++--- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/controller/JobLauncherController.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/controller/JobLauncherController.java index 8bd33c82..dd0ee3b5 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/controller/JobLauncherController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/controller/JobLauncherController.java @@ -415,14 +415,14 @@ public ResponseEntity launchRerunFailed(@PathVariable Long bat @PreAuthorize(PermissionsConstants.RUN_GRAD_ALGORITHM) @Operation(summary = "Re-Generate School Reports for the given batchJobId", description = "RRe-Generate School Reports for the given batchJobId", tags = { "RE-RUN" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),@ApiResponse(responseCode = "500", description = "Internal Server Error")}) - public ResponseEntity launchRegenerateSchoolReports(@PathVariable Long batchId, @RequestHeader(name="Authorization") String accessToken) { + public ResponseEntity launchRegenerateSchoolReports(@PathVariable Long batchId) { BatchGradAlgorithmJobHistoryEntity entity = gradBatchHistoryService.getGradAlgorithmJobHistory(batchId); if (entity != null) { try { logger.info(" Re-Generating School Reports for {} --------------------------------------------------------", entity.getJobType()); List uniqueSchoolList = gradBatchHistoryService.getSchoolListForReport(batchId); logger.info(" Number of Schools [{}] ---------------------------------------------------------", uniqueSchoolList.size()); - restUtils.createAndStoreSchoolReports(accessToken.replace(BEARER, ""), uniqueSchoolList, entity.getJobType()); + restUtils.createAndStoreSchoolReports(uniqueSchoolList, entity.getJobType()); return ResponseEntity.ok(Boolean.TRUE); } catch (Exception e) { return ResponseEntity.status(500).body(Boolean.FALSE); @@ -435,13 +435,13 @@ public ResponseEntity launchRegenerateSchoolReports(@PathVariable Long @PreAuthorize(PermissionsConstants.RUN_GRAD_ALGORITHM) @Operation(summary = "Re-Generate School Reports for the given batchJobId", description = "RRe-Generate School Reports for the given batchJobId", tags = { "RE-RUN" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),@ApiResponse(responseCode = "500", description = "Internal Server Error")}) - public ResponseEntity launchRegenerateSchoolReports(@RequestBody StudentSearchRequest searchRequest, @RequestHeader(name="Authorization") String accessToken, @RequestParam(required = false) String type) { + public ResponseEntity launchRegenerateSchoolReports(@RequestBody StudentSearchRequest searchRequest, @RequestParam(required = false) String type) { String schoolReportType = ObjectUtils.defaultIfNull(type, REGALG); logger.info(" Re-Generating School Reports by request for {} --------------------------------------------------------", schoolReportType); try { List finalSchoolDistricts = gradSchoolOfRecordFilter.filterSchoolOfRecords(searchRequest).stream().sorted().toList(); logger.info(" Number of Schools [{}] ---------------------------------------------------------", finalSchoolDistricts.size()); - int numberOfReports = restUtils.createAndStoreSchoolReports(accessToken.replace(BEARER, ""), finalSchoolDistricts, schoolReportType); + int numberOfReports = restUtils.createAndStoreSchoolReports(finalSchoolDistricts, schoolReportType); return ResponseEntity.ok(numberOfReports + " school reports " + schoolReportType + " created successfully"); } catch (Exception e) { return ResponseEntity.status(500).body(e.getLocalizedMessage()); diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/BaseRunCompletionNotificationListener.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/BaseRunCompletionNotificationListener.java index 8f7228a0..d8466496 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/BaseRunCompletionNotificationListener.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/BaseRunCompletionNotificationListener.java @@ -77,7 +77,7 @@ protected void handleSummary(JobExecution jobExecution, String summaryDtoName, b if (!isSpecialRun) { updateBackStudentFlagForErroredStudents(summaryDTO.getErrors(), jobType, obj.getAccess_token()); } - processSchoolList(jobExecutionId, obj.getAccess_token(), jobType); + processSchoolList(jobExecutionId, jobType); } private void processBatchJobHistory(AlgorithmSummaryDTO summaryDTO, Long jobExecutionId, String status, String jobTrigger, String jobType, Date startTime, Date endTime) { @@ -107,11 +107,11 @@ private void updateBackStudentFlagForErroredStudents(Map err } } - private void processSchoolList(Long batchId, String accessToken, String jobType) { + private void processSchoolList(Long batchId, String jobType) { LOGGER.info(" Creating Reports for {}", jobType); List uniqueSchoolList = gradBatchHistoryService.getSchoolListForReport(batchId); LOGGER.info(" Number of Schools [{}]", uniqueSchoolList.size()); - restUtils.createAndStoreSchoolReports(accessToken,uniqueSchoolList,jobType); + restUtils.createAndStoreSchoolReports(uniqueSchoolList,jobType); } private long getTotalReadCount(Long batchId) { diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java index 4be37d85..54c05f6a 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; @Component public class RestUtils { @@ -480,22 +481,25 @@ public GraduationStudentRecordDistribution getStudentData(String studentID, Stri return result; } - public Integer createAndStoreSchoolReports(String accessToken, List uniqueSchools,String type) { + public Integer createAndStoreSchoolReports(List uniqueSchools, String type) { UUID correlationID = UUID.randomUUID(); Integer result = 0; if(uniqueSchools == null || uniqueSchools.isEmpty()) { LOGGER.info("{} Schools selected for School Reports", result); return result; } - int pageSize = 1000; + int pageSize = 10; int pageNum = uniqueSchools.size() / pageSize + 1; for (int i = 0; i < pageNum; i++) { int startIndex = i * pageSize; int endIndex = Math.min(startIndex + pageSize, uniqueSchools.size()); List mincodes = uniqueSchools.subList(startIndex, endIndex); + if(LOGGER.isDebugEnabled()) { + LOGGER.debug("Creating School Reports for schools {}", mincodes.stream().collect(Collectors.joining(",", "{", "}"))); + } result += webClient.post() .uri(String.format(constants.getCreateAndStoreSchoolReports(),type)) - .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, correlationID.toString()); }) + .headers(h -> { h.setBearerAuth(getAccessToken()); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, correlationID.toString()); }) .body(BodyInserters.fromValue(mincodes)) .retrieve() .bodyToMono(Integer.class) diff --git a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java index 20111e2a..4aa61340 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java @@ -822,7 +822,9 @@ public void testcreateAndStoreSchoolReports_null() { when(this.responseMock.bodyToMono(Integer.class)).thenReturn(inputResponseI); when(this.inputResponseI.block()).thenReturn(null); - this.restUtils.createAndStoreSchoolReports("Abc",new ArrayList<>(),type); + mockTokenResponseObject(); + + this.restUtils.createAndStoreSchoolReports(new ArrayList<>(),type); assertNotNull(type); } @@ -838,7 +840,9 @@ public void testcreateAndStoreSchoolReports() { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(Integer.class)).thenReturn(Mono.just(1)); - this.restUtils.createAndStoreSchoolReports("Abc",new ArrayList<>(),type); + mockTokenResponseObject(); + + this.restUtils.createAndStoreSchoolReports(new ArrayList<>(),type); assertNotNull(type); } @@ -854,7 +858,9 @@ public void testcreateAndStoreSchoolReports_0() { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(Integer.class)).thenReturn(Mono.just(0)); - this.restUtils.createAndStoreSchoolReports("Abc",new ArrayList<>(),type); + mockTokenResponseObject(); + + this.restUtils.createAndStoreSchoolReports(new ArrayList<>(),type); assertNotNull(type); }