From e015ee664c2ccc2aa834a6ca303f9755f31f6524 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 6 Nov 2023 12:06:43 -0700 Subject: [PATCH 1/2] Added filters to monthly distribution by studentID --- .../controller/JobLauncherController.java | 13 ++++++++++++- .../api/batchgraduation/reader/BasePartitioner.java | 11 +++++++---- .../reader/DistributionRunPartitioner.java | 7 +++++-- 3 files changed, 24 insertions(+), 7 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 6b1f195f..1b72e427 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 @@ -466,6 +466,14 @@ public ResponseEntity launchMonthlyDistributionRunJob() @Operation(summary = "Run Distribution Runs", description = "Run Distribution Runs", tags = { "Distribution" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),@ApiResponse(responseCode = "500", description = "Internal Server Error")}) public ResponseEntity launchDistributionRunJob() { + return launchDistributionRunJob(null); + } + + @PostMapping(EducGradBatchGraduationApiConstants.EXECUTE_DIS_RUN_BATCH_JOB) + @PreAuthorize(PermissionsConstants.RUN_GRAD_ALGORITHM) + @Operation(summary = "Run Distribution Runs", description = "Run Distribution Runs", tags = { "Distribution" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),@ApiResponse(responseCode = "500", description = "Internal Server Error")}) + public ResponseEntity launchDistributionRunJob(@RequestBody StudentSearchRequest request) { logger.debug("launchDistributionRunJob"); JobParametersBuilder builder = new JobParametersBuilder(); builder.addLong(TIME, System.currentTimeMillis()).toJobParameters(); @@ -473,6 +481,9 @@ public ResponseEntity launchDistributionRunJob() { builder.addString(JOB_TRIGGER, MANUAL); builder.addString(JOB_TYPE, DISTRUN); try { + if(request != null) { + builder.addString(SEARCH_REQUEST, jsonTransformer.marshall(request)); + } JobExecution jobExecution = asyncJobLauncher.run(jobRegistry.getJob("DistributionBatchJob"), builder.toJobParameters()); ExecutionContext jobContext = jobExecution.getExecutionContext(); DistributionSummaryDTO summaryDTO = (DistributionSummaryDTO)jobContext.get(DISDTO); @@ -483,7 +494,7 @@ public ResponseEntity launchDistributionRunJob() { summaryDTO.setBatchId(jobExecution.getId()); return ResponseEntity.ok(summaryDTO); } catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException - | JobParametersInvalidException | NoSuchJobException e) { + | JobParametersInvalidException | NoSuchJobException e) { DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); summaryDTO.setException(e.getLocalizedMessage()); return ResponseEntity.status(500).body(summaryDTO); diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/BasePartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/BasePartitioner.java index bba796f7..8c8fd18b 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/BasePartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/BasePartitioner.java @@ -226,16 +226,19 @@ void filterByStudentSearchRequest(List eligibleSt useFilterSchoolDistricts.add(school.getMincode()); } } - eligibleStudentSchoolDistricts.removeIf(scr->!useFilterSchoolDistricts.contains(scr.getSchoolOfRecord())); + eligibleStudentSchoolDistricts.removeIf(scr->StringUtils.isNotBlank(scr.getSchoolOfRecord()) && !useFilterSchoolDistricts.contains(scr.getSchoolOfRecord())); } if(searchRequest != null && searchRequest.getDistricts() != null && !searchRequest.getDistricts().isEmpty()) { - eligibleStudentSchoolDistricts.removeIf(scr->!searchRequest.getDistricts().contains(StringUtils.substring(scr.getSchoolOfRecord(), 0, 3))); + eligibleStudentSchoolDistricts.removeIf(scr->StringUtils.isNotBlank(scr.getSchoolOfRecord()) && !searchRequest.getDistricts().contains(StringUtils.substring(scr.getSchoolOfRecord(), 0, 3))); } if(searchRequest != null && searchRequest.getSchoolOfRecords() != null && !searchRequest.getSchoolOfRecords().isEmpty()) { - eligibleStudentSchoolDistricts.removeIf(scr->!searchRequest.getSchoolOfRecords().contains(scr.getSchoolOfRecord())); + eligibleStudentSchoolDistricts.removeIf(scr->StringUtils.isNotBlank(scr.getSchoolOfRecord()) && !searchRequest.getSchoolOfRecords().contains(scr.getSchoolOfRecord())); + } + if(searchRequest != null && searchRequest.getStudentIDs() != null && !searchRequest.getStudentIDs().isEmpty()) { + eligibleStudentSchoolDistricts.removeIf(scr->scr.getStudentID() != null && !searchRequest.getStudentIDs().contains(scr.getStudentID())); } if(searchRequest != null && searchRequest.getPens() != null && !searchRequest.getPens().isEmpty()) { - eligibleStudentSchoolDistricts.removeIf(scr->!searchRequest.getPens().contains(scr.getPen())); + eligibleStudentSchoolDistricts.removeIf(scr->StringUtils.isNotBlank(scr.getPen()) && !searchRequest.getPens().contains(scr.getPen())); } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitioner.java index a279dd8a..e671f5b6 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitioner.java @@ -1,7 +1,6 @@ package ca.bc.gov.educ.api.batchgraduation.reader; import ca.bc.gov.educ.api.batchgraduation.model.DistributionDataParallelDTO; -import ca.bc.gov.educ.api.batchgraduation.model.ResponseObj; import ca.bc.gov.educ.api.batchgraduation.model.StudentCredentialDistribution; import ca.bc.gov.educ.api.batchgraduation.service.ParallelDataFetch; import org.slf4j.Logger; @@ -12,7 +11,10 @@ import org.springframework.beans.factory.annotation.Value; import reactor.core.publisher.Mono; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Monthly Distribution Partitioner @@ -52,6 +54,7 @@ public Map partition(int gridSize) { logger.debug("Total {} eligible StudentCredentialDistributions found in {} sec", credentialList.size(), diff); if(!credentialList.isEmpty()) { filterOutDeceasedStudents(credentialList); + filterByStudentSearchRequest(credentialList); updateBatchJobHistory(createBatchJobHistory(), (long) credentialList.size()); return getStringExecutionContextMap(gridSize, credentialList, null); } From bfc3a81e18bbde0785adeb9ef16a45d0025d7aae Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 6 Nov 2023 16:46:11 -0700 Subject: [PATCH 2/2] GRAD2-2339 HD-22855 Year-End Graduation Run - Distribution Report Counts Error --- .../api/batchgraduation/reader/DistributionRunPartitioner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitioner.java index e671f5b6..8580c37c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitioner.java @@ -52,9 +52,9 @@ public Map partition(int gridSize) { endTime = System.currentTimeMillis(); diff = (endTime - startTime)/1000; logger.debug("Total {} eligible StudentCredentialDistributions found in {} sec", credentialList.size(), diff); + filterByStudentSearchRequest(credentialList); if(!credentialList.isEmpty()) { filterOutDeceasedStudents(credentialList); - filterByStudentSearchRequest(credentialList); updateBatchJobHistory(createBatchJobHistory(), (long) credentialList.size()); return getStringExecutionContextMap(gridSize, credentialList, null); }