Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop/alex-GRAD2-2339-2 #442

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading