-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GRAD2-2822: School Report Regeneration Process - Backend Changes
- Loading branch information
1 parent
9838576
commit e5e7552
Showing
12 changed files
with
374 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...v/educ/api/batchgraduation/listener/RegenSchoolReportsCompletionNotificationListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package ca.bc.gov.educ.api.batchgraduation.listener; | ||
|
||
import ca.bc.gov.educ.api.batchgraduation.model.DistributionSummaryDTO; | ||
import ca.bc.gov.educ.api.batchgraduation.util.DateUtils; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.batch.core.BatchStatus; | ||
import org.springframework.batch.core.JobExecution; | ||
import org.springframework.batch.core.JobParameters; | ||
import org.springframework.batch.item.ExecutionContext; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Date; | ||
|
||
import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.SEARCH_REQUEST; | ||
|
||
@Slf4j | ||
@Component | ||
public class RegenSchoolReportsCompletionNotificationListener extends BaseDistributionRunCompletionNotificationListener { | ||
|
||
@Override | ||
public void afterJob(JobExecution jobExecution) { | ||
if (jobExecution.getStatus() == BatchStatus.COMPLETED) { | ||
long elapsedTimeMillis = getElapsedTimeMillis(jobExecution); | ||
log.info("======================================================================================="); | ||
JobParameters jobParameters = jobExecution.getJobParameters(); | ||
ExecutionContext jobContext = jobExecution.getExecutionContext(); | ||
Long jobExecutionId = jobExecution.getId(); | ||
String jobType = jobParameters.getString("jobType"); | ||
log.info("{} Regen School Reports Job {} completed in {} s with jobExecution status {}", jobType, jobExecutionId, elapsedTimeMillis / 1000, jobExecution.getStatus()); | ||
|
||
String status = jobExecution.getStatus().toString(); | ||
Date startTime = DateUtils.toDate(jobExecution.getStartTime()); | ||
Date endTime = DateUtils.toDate(jobExecution.getEndTime()); | ||
String jobTrigger = jobParameters.getString("jobTrigger"); | ||
|
||
DistributionSummaryDTO summaryDTO = (DistributionSummaryDTO)jobContext.get("distributionSummaryDTO"); | ||
|
||
String studentSearchRequest = jobParameters.getString(SEARCH_REQUEST, "{}"); | ||
// display Summary Details | ||
log.info("Records read : {}", summaryDTO.getReadCount()); | ||
log.info("Processed count: {}", summaryDTO.getProcessedCount()); | ||
log.info(" --------------------------------------------------------------------------------------"); | ||
log.info("Errors:{}", summaryDTO.getErrors().size()); | ||
|
||
updateUserSchedulingJobs(jobParameters); | ||
|
||
String jobParametersDTO = buildJobParametersDTO(jobType, studentSearchRequest, null, null); | ||
// save batch job & error history | ||
processBatchJobHistory(summaryDTO, jobExecutionId, status, jobTrigger, jobType, startTime, endTime, jobParametersDTO); | ||
log.info(" --------------------------------------------------------------------------------------"); | ||
summaryDTO.getSchools().forEach((value) -> log.info("School {} number of Regen School Reports : {}", value.getMincode(), value.getNumberOfSchoolReports())); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
.../main/java/ca/bc/gov/educ/api/batchgraduation/model/SchoolReportsRegenerationRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ca.bc.gov.educ.api.batchgraduation.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Data | ||
@Component | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class SchoolReportsRegenerationRequest extends StudentSearchRequest { | ||
private String runMode; // "Y" or "N" | ||
|
||
public boolean runForAll () { | ||
return (getSchoolOfRecords() == null || getSchoolOfRecords().isEmpty()) && | ||
(getSchoolCategoryCodes() == null || getSchoolCategoryCodes().isEmpty()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...n/java/ca/bc/gov/educ/api/batchgraduation/processor/RegenerateSchoolReportsProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ca.bc.gov.educ.api.batchgraduation.processor; | ||
|
||
import ca.bc.gov.educ.api.batchgraduation.model.*; | ||
import ca.bc.gov.educ.api.batchgraduation.rest.RestUtils; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.batch.item.ItemProcessor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
public class RegenerateSchoolReportsProcessor implements ItemProcessor<List<String>, List<String>> { | ||
|
||
@Autowired | ||
RestUtils restUtils; | ||
|
||
@Value("#{stepExecutionContext['summary']}") | ||
DistributionSummaryDTO summaryDTO; | ||
|
||
@Override | ||
public List<String> process(List<String> minCodes) throws Exception { | ||
Long batchId = summaryDTO.getBatchId(); | ||
StudentSearchRequest searchRequest = summaryDTO.getStudentSearchRequest(); | ||
long countRegeneratedSchoolReports = 0l; | ||
List<String> reportTypes = searchRequest.getReportTypes(); | ||
if(log.isDebugEnabled()) { | ||
log.debug("Process Schools: {}", !minCodes.isEmpty() ? String.join(",", minCodes) : summaryDTO.getSchools().stream().map(School::getMincode).collect(Collectors.joining(","))); | ||
} | ||
|
||
String reportType; | ||
if(reportTypes != null && !reportTypes.isEmpty() && "NONGRADPRJ".compareToIgnoreCase(reportTypes.get(0)) == 0) | ||
reportType = "TVRRUN"; | ||
else | ||
reportType = "GRADREG and NONGRADREG"; | ||
|
||
for (String mincode : minCodes) { | ||
countRegeneratedSchoolReports += restUtils.createAndStoreSchoolReports(batchId, minCodes, reportType, summaryDTO); | ||
} | ||
|
||
summaryDTO.setProcessedCount(countRegeneratedSchoolReports); | ||
return minCodes; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...in/java/ca/bc/gov/educ/api/batchgraduation/reader/RegenerateSchoolReportsPartitioner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package ca.bc.gov.educ.api.batchgraduation.reader; | ||
|
||
import ca.bc.gov.educ.api.batchgraduation.model.*; | ||
import ca.bc.gov.educ.api.batchgraduation.util.GradSchoolOfRecordFilter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.batch.core.JobExecution; | ||
import org.springframework.batch.item.ExecutionContext; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
import java.util.*; | ||
|
||
import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.SEARCH_REQUEST; | ||
|
||
@Slf4j | ||
public class RegenerateSchoolReportsPartitioner extends BasePartitioner { | ||
|
||
@Value("#{stepExecution.jobExecution}") | ||
JobExecution jobExecution; | ||
|
||
@Autowired | ||
GradSchoolOfRecordFilter gradSchoolOfRecordFilter; | ||
|
||
public RegenerateSchoolReportsPartitioner() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public JobExecution getJobExecution() { | ||
return jobExecution; | ||
} | ||
|
||
@Override | ||
public Map<String, ExecutionContext> partition(int gridSize) { | ||
DistributionSummaryDTO summaryDTO = (DistributionSummaryDTO)jobExecution.getExecutionContext().get("distributionSummaryDTO"); | ||
if(summaryDTO == null) { | ||
summaryDTO = new DistributionSummaryDTO(); | ||
jobExecution.getExecutionContext().put("distributionSummaryDTO", summaryDTO); | ||
} | ||
|
||
StudentSearchRequest searchRequest = getStudentSearchRequest(); | ||
long startTime = System.currentTimeMillis(); | ||
log.debug("Filter Schools for school reports regeneration"); | ||
boolean processAllStudents = "ALL".equalsIgnoreCase(searchRequest.getActivityCode()); | ||
List<String> eligibleStudentSchoolDistricts = gradSchoolOfRecordFilter.filterSchoolOfRecords(searchRequest); | ||
List<String> finalSchoolDistricts = eligibleStudentSchoolDistricts.stream().sorted().toList(); | ||
if(log.isDebugEnabled()) { | ||
log.debug("Final list of eligible District / School codes {}", String.join(", ", finalSchoolDistricts)); | ||
} | ||
|
||
summaryDTO.setBatchId(jobExecution.getId()); | ||
summaryDTO.setStudentSearchRequest(searchRequest); | ||
|
||
long endTime = System.currentTimeMillis(); | ||
long diff = (endTime - startTime)/1000; | ||
log.debug("Total {} schools after filters in {} sec", finalSchoolDistricts.size(), diff); | ||
|
||
updateBatchJobHistory(createBatchJobHistory(), (long)finalSchoolDistricts.size()); | ||
summaryDTO.setReadCount((long)finalSchoolDistricts.size()); | ||
summaryDTO.setProcessedCount(0); | ||
|
||
Map<String, ExecutionContext> map = new HashMap<>(); | ||
ExecutionContext executionContext = new ExecutionContext(); | ||
executionContext.put(SEARCH_REQUEST, searchRequest); | ||
executionContext.put("data", finalSchoolDistricts); | ||
executionContext.put("summary", summaryDTO); | ||
executionContext.put("readCount", 0); | ||
map.put("partition0", executionContext); | ||
|
||
log.info("Found {} in total running on 1 partitions", finalSchoolDistricts); | ||
return map; | ||
} | ||
} |
Oops, something went wrong.