Skip to content

Commit

Permalink
GRAD2-2312
Browse files Browse the repository at this point in the history
HD-21648-GRAD - P3 - Regeneration of the Graduated Student SCHOOL Report
  • Loading branch information
arybakov-cgi committed Sep 19, 2023
1 parent 63d3e25 commit 495904f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,14 @@ public ResponseEntity<BatchJobResponse> 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<Boolean> launchRegenerateSchoolReports(@PathVariable Long batchId, @RequestHeader(name="Authorization") String accessToken) {
public ResponseEntity<Boolean> launchRegenerateSchoolReports(@PathVariable Long batchId) {
BatchGradAlgorithmJobHistoryEntity entity = gradBatchHistoryService.getGradAlgorithmJobHistory(batchId);
if (entity != null) {
try {
logger.info(" Re-Generating School Reports for {} --------------------------------------------------------", entity.getJobType());
List<String> 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);
Expand All @@ -435,13 +435,13 @@ public ResponseEntity<Boolean> 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<String> launchRegenerateSchoolReports(@RequestBody StudentSearchRequest searchRequest, @RequestHeader(name="Authorization") String accessToken, @RequestParam(required = false) String type) {
public ResponseEntity<String> 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<String> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -107,11 +107,11 @@ private void updateBackStudentFlagForErroredStudents(Map<UUID, ProcessError> err
}
}

private void processSchoolList(Long batchId, String accessToken, String jobType) {
private void processSchoolList(Long batchId, String jobType) {
LOGGER.info(" Creating Reports for {}", jobType);
List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -480,22 +481,25 @@ public GraduationStudentRecordDistribution getStudentData(String studentID, Stri
return result;
}

public Integer createAndStoreSchoolReports(String accessToken, List<String> uniqueSchools,String type) {
public Integer createAndStoreSchoolReports(List<String> 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<String> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 495904f

Please sign in to comment.