Skip to content

Commit

Permalink
Merge pull request #442 from bcgov/develop/alex-GRAD2-2339-2
Browse files Browse the repository at this point in the history
Develop/alex-GRAD2-2339-2
  • Loading branch information
kamal-mohammed authored Nov 7, 2023
2 parents c8a42b7 + bfc3a81 commit 77db3e3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,24 @@ public ResponseEntity<DistributionSummaryDTO> 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<DistributionSummaryDTO> 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<DistributionSummaryDTO> launchDistributionRunJob(@RequestBody StudentSearchRequest request) {
logger.debug("launchDistributionRunJob");
JobParametersBuilder builder = new JobParametersBuilder();
builder.addLong(TIME, System.currentTimeMillis()).toJobParameters();
builder.addString(RUN_BY, ThreadLocalStateUtil.getCurrentUser());
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);
Expand All @@ -483,7 +494,7 @@ public ResponseEntity<DistributionSummaryDTO> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,19 @@ void filterByStudentSearchRequest(List<StudentCredentialDistribution> 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()));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -50,6 +52,7 @@ public Map<String, ExecutionContext> 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);
updateBatchJobHistory(createBatchJobHistory(), (long) credentialList.size());
Expand Down

0 comments on commit 77db3e3

Please sign in to comment.