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 45c28c1b..b71a1289 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 @@ -290,6 +290,31 @@ private void validateInputDeleteStudentReports(StudentSearchRequest studentSearc if(studentSearchRequest == null) { throw new GradBusinessRuleException("Please provide not null student search request"); } + StringBuilder errors = new StringBuilder(); + if(studentSearchRequest.isEmpty() && StringUtils.isBlank(studentSearchRequest.getActivityCode())) { + errors.append("Please provide school of records or set activityCode to ALL to delete all reports").append('\n'); + } + if(studentSearchRequest.getReportTypes().isEmpty()) { + errors.append("Please provide at least 1 report type code").append('\n'); + } + String errorsAsString = errors.toString(); + if(StringUtils.isNotBlank(errorsAsString)) { + throw new GradBusinessRuleException(errorsAsString); + } + } + + private void validateInputArchiveStudents(StudentSearchRequest studentSearchRequest) { + if(studentSearchRequest == null) { + throw new GradBusinessRuleException("Please provide not null student search request"); + } + StringBuilder errors = new StringBuilder(); + if(studentSearchRequest.isEmpty() && StringUtils.isBlank(studentSearchRequest.getActivityCode())) { + errors.append("Please provide school of records or set activityCode to ALL to archive all students").append('\n'); + } + String errorsAsString = errors.toString(); + if(StringUtils.isNotBlank(errorsAsString)) { + throw new GradBusinessRuleException(errorsAsString); + } } private BlankDistributionSummaryDTO validateInputBlankDisRun(BlankCredentialRequest blankCredentialRequest) { @@ -877,9 +902,9 @@ public ResponseEntity launchArchiveSchoolReportsJob(@RequestBo logger.debug("launchArchiveSchoolReporsJob"); BatchJobResponse response = new BatchJobResponse(); JobParametersBuilder builder = new JobParametersBuilder(); - + String userName = ThreadLocalStateUtil.getCurrentUser(); builder.addLong(TIME, System.currentTimeMillis()).toJobParameters(); - builder.addString(RUN_BY, ThreadLocalStateUtil.getCurrentUser()); + builder.addString(RUN_BY, userName); builder.addString(JOB_TRIGGER, MANUAL); builder.addString(JOB_TYPE, ARCHIVE_SCHOOL_REPORTS); @@ -899,12 +924,14 @@ public ResponseEntity launchArchiveSchoolReportsJob(@RequestBo ExecutionContext jobContext = jobExecution.getExecutionContext(); DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); summaryDTO.setBatchId(jobExecution.getId()); + summaryDTO.setUserName(userName); + summaryDTO.setStudentSearchRequest(studentSearchRequest); jobContext.put(DISDTO, summaryDTO); response.setBatchId(jobExecution.getId()); } else { response.setBatchId(jobParameters.getLong("run.id")); } - return ResponseEntity.ok(response); + return ResponseEntity.status(HttpStatus.CREATED).body(response); } catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException | JobParametersInvalidException | NoSuchJobException | IllegalArgumentException e) { response.setException(e.getLocalizedMessage()); @@ -920,9 +947,9 @@ public ResponseEntity launchDeleteStudentReportsJob(@RequestBo logger.debug("launchDeleteStudentReportsJob"); BatchJobResponse response = new BatchJobResponse(); JobParametersBuilder builder = new JobParametersBuilder(); - + String userName = ThreadLocalStateUtil.getCurrentUser(); builder.addLong(TIME, System.currentTimeMillis()).toJobParameters(); - builder.addString(RUN_BY, ThreadLocalStateUtil.getCurrentUser()); + builder.addString(RUN_BY, userName); builder.addString(JOB_TRIGGER, MANUAL); builder.addString(JOB_TYPE, DELETE_STUDENT_REPORTS); @@ -942,12 +969,14 @@ public ResponseEntity launchDeleteStudentReportsJob(@RequestBo ExecutionContext jobContext = jobExecution.getExecutionContext(); DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); summaryDTO.setBatchId(jobExecution.getId()); + summaryDTO.setUserName(userName); + summaryDTO.setStudentSearchRequest(studentSearchRequest); jobContext.put(DISDTO, summaryDTO); response.setBatchId(jobExecution.getId()); } else { response.setBatchId(jobParameters.getLong("run.id")); } - return ResponseEntity.ok(response); + return ResponseEntity.status(HttpStatus.CREATED).body(response); } catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException | JobParametersInvalidException | NoSuchJobException | IllegalArgumentException e) { response.setException(e.getLocalizedMessage()); @@ -963,9 +992,9 @@ public ResponseEntity launchArchiveStudentsJob(@RequestBody St logger.debug("launchArchiveStudentsJob"); BatchJobResponse response = new BatchJobResponse(); JobParametersBuilder builder = new JobParametersBuilder(); - + String userName = ThreadLocalStateUtil.getCurrentUser(); builder.addLong(TIME, System.currentTimeMillis()).toJobParameters(); - builder.addString(RUN_BY, ThreadLocalStateUtil.getCurrentUser()); + builder.addString(RUN_BY, userName); builder.addString(JOB_TRIGGER, MANUAL); builder.addString(JOB_TYPE, ARCHIVE_STUDENTS); @@ -975,6 +1004,7 @@ public ResponseEntity launchArchiveStudentsJob(@RequestBody St response.setStatus(BatchStatusEnum.STARTED.name()); try { + validateInputArchiveStudents(studentSearchRequest); String searchData = jsonTransformer.marshall(studentSearchRequest); builder.addString(SEARCH_REQUEST, StringUtils.defaultString(searchData, "{}")); Job job = jobRegistry.getJob(ARCHIVE_STUDENTS_BATCH_JOB); @@ -984,12 +1014,14 @@ public ResponseEntity launchArchiveStudentsJob(@RequestBody St ExecutionContext jobContext = jobExecution.getExecutionContext(); DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); summaryDTO.setBatchId(jobExecution.getId()); + summaryDTO.setUserName(userName); + summaryDTO.setStudentSearchRequest(studentSearchRequest); jobContext.put(DISDTO, summaryDTO); response.setBatchId(jobExecution.getId()); } else { response.setBatchId(jobParameters.getLong("run.id")); } - return ResponseEntity.ok(response); + return ResponseEntity.status(HttpStatus.CREATED).body(response); } catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException | JobParametersInvalidException | NoSuchJobException | IllegalArgumentException e) { response.setException(e.getLocalizedMessage()); diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/ArchiveStudentsCompletionNotificationListener.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/ArchiveStudentsCompletionNotificationListener.java index 59081d6b..20e6703b 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/ArchiveStudentsCompletionNotificationListener.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/ArchiveStudentsCompletionNotificationListener.java @@ -3,7 +3,6 @@ import ca.bc.gov.educ.api.batchgraduation.model.DistributionSummaryDTO; import ca.bc.gov.educ.api.batchgraduation.model.StudentSearchRequest; import ca.bc.gov.educ.api.batchgraduation.util.DateUtils; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.core.BatchStatus; @@ -49,8 +48,8 @@ public void afterJob(JobExecution jobExecution) { updateUserSchedulingJobs(jobParameters); - StudentSearchRequest searchRequest = (StudentSearchRequest)jsonTransformer.unmarshall(studentSearchRequest, StudentSearchRequest.class); - String userName = StringUtils.defaultString(jobParameters.getString("runBy"), StringUtils.defaultString(searchRequest.getUser(), "Batch Archive Process")); + StudentSearchRequest searchRequest = summaryDTO.getStudentSearchRequest(); + String userName = extractUserName(summaryDTO, jobParameters, searchRequest); String jobParametersDTO = buildJobParametersDTO(jobType, studentSearchRequest, null, null); // save batch job & error history diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/BaseDistributionRunCompletionNotificationListener.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/BaseDistributionRunCompletionNotificationListener.java index 0d5e387f..9a83d42e 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/BaseDistributionRunCompletionNotificationListener.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/BaseDistributionRunCompletionNotificationListener.java @@ -154,4 +154,8 @@ void updateUserSchedulingJobs(JobParameters jobParameters) { taskSchedulingService.updateUserScheduledJobs(userScheduledId); } } + + String extractUserName(BaseSummaryDTO summaryDTO, JobParameters jobParameters, StudentSearchRequest searchRequest) { + return StringUtils.defaultString(StringUtils.defaultString(summaryDTO.getUserName(), jobParameters.getString("runBy")), StringUtils.defaultString(searchRequest.getUser(), "Batch Process")); + } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/BaseRunCompletionNotificationListener.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/BaseRunCompletionNotificationListener.java index 4111760f..b1f5d924 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/BaseRunCompletionNotificationListener.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/BaseRunCompletionNotificationListener.java @@ -88,7 +88,7 @@ protected void handleSummary(JobExecution jobExecution, String summaryDtoName, b if (!isSpecialRun) { updateBackStudentFlagForErroredStudents(summaryDTO.getErrors(), jobType, obj.getAccess_token()); } - if(!StringUtils.equalsAnyIgnoreCase(req.getActivityCode(), TVRCREATE, TVRUPDATE, TVRDELETE)) { + if(!StringUtils.equalsAnyIgnoreCase(req.getActivityCode(), TVRCREATE, TVRUPDATE, TVRDELETE, ALL)) { processSchoolList(jobExecutionId, jobType); } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/DeleteStudentReportsCompletionNotificationListener.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/DeleteStudentReportsCompletionNotificationListener.java index a1ac9a42..bcb4156b 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/DeleteStudentReportsCompletionNotificationListener.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/DeleteStudentReportsCompletionNotificationListener.java @@ -3,7 +3,6 @@ import ca.bc.gov.educ.api.batchgraduation.model.DistributionSummaryDTO; import ca.bc.gov.educ.api.batchgraduation.model.StudentSearchRequest; import ca.bc.gov.educ.api.batchgraduation.util.DateUtils; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.core.BatchStatus; @@ -13,6 +12,8 @@ import org.springframework.stereotype.Component; import java.util.Date; +import java.util.List; +import java.util.UUID; import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.SEARCH_REQUEST; @@ -49,16 +50,23 @@ public void afterJob(JobExecution jobExecution) { updateUserSchedulingJobs(jobParameters); StudentSearchRequest searchRequest = summaryDTO.getStudentSearchRequest(); - String userName = StringUtils.defaultString(jobParameters.getString("runBy"), StringUtils.defaultString(searchRequest.getUser(), "Batch TVR Delete Process")); + String userName = extractUserName(summaryDTO, jobParameters, searchRequest); + summaryDTO.getSchools().forEach((value) -> LOGGER.info("School {} number of Deleted Student Reports : {}", value.getMincode(), value.getNumberOfStudents())); + if(summaryDTO.getProcessedCount() > 0) { + List finalStudentGuids = searchRequest.getStudentIDs(); + int partitionSize = finalStudentGuids.size()/200; + partitionSize = partitionSize == 0 ? finalStudentGuids.size() : partitionSize; + for (int i = 0; i < finalStudentGuids.size(); i += partitionSize) { + List studentGuidsSubList = finalStudentGuids.subList(i, Math.min(i + partitionSize, finalStudentGuids.size())); + restUtils.updateStudentGradRecordHistory(studentGuidsSubList, jobExecutionId, userName, "TVRDELETED"); + } + } String jobParametersDTO = buildJobParametersDTO(jobType, studentSearchRequest, null, null); // save batch job & error history processBatchJobHistory(summaryDTO, jobExecutionId, status, jobTrigger, jobType, startTime, endTime, jobParametersDTO); LOGGER.info(" --------------------------------------------------------------------------------------"); - summaryDTO.getSchools().forEach((value) -> LOGGER.info("School {} number of Deleted Student Reports : {}", value.getMincode(), value.getNumberOfStudents())); - if(summaryDTO.getProcessedCount() > 0) { - restUtils.updateStudentGradRecordHistory(searchRequest.getStudentIDs(), jobExecutionId, userName, "TVRDELETED"); - } + } } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/BaseSummaryDTO.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/BaseSummaryDTO.java index 98175f4b..84d25afe 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/BaseSummaryDTO.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/BaseSummaryDTO.java @@ -18,4 +18,6 @@ public class BaseSummaryDTO implements Serializable { @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) private String accessToken; + + private String userName; } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DeleteStudentReportsProcessor.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DeleteStudentReportsProcessor.java index 46dcebba..8cc1384b 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DeleteStudentReportsProcessor.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DeleteStudentReportsProcessor.java @@ -25,11 +25,11 @@ public class DeleteStudentReportsProcessor implements ItemProcessor, @Override public List process(List uuids) throws Exception { Long batchId = summaryDTO.getBatchId(); + StudentSearchRequest searchRequest = summaryDTO.getStudentSearchRequest(); if(LOGGER.isDebugEnabled()) { - LOGGER.debug("Process Student Reports: {}", uuids.size()); + LOGGER.debug("Process Student Reports: {}", uuids.isEmpty() ? searchRequest.getActivityCode() : uuids.size()); } long countDeletedStudentReports = summaryDTO.getProcessedCount(); - StudentSearchRequest searchRequest = summaryDTO.getStudentSearchRequest(); for(String reportType: searchRequest.getReportTypes()) { countDeletedStudentReports += restUtils.deleteStudentReports(batchId, uuids, reportType, summaryDTO); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/ArchiveSchoolReportsPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/ArchiveSchoolReportsPartitioner.java index ab4cef2a..70185768 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/ArchiveSchoolReportsPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/ArchiveSchoolReportsPartitioner.java @@ -38,6 +38,12 @@ public JobExecution getJobExecution() { @Override public Map 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(); logger.debug("Filter Schools for archiving school reports"); @@ -47,13 +53,9 @@ public Map partition(int gridSize) { logger.debug("Final list of eligible District / School codes {}", String.join(", ", finalSchoolDistricts)); } - DistributionSummaryDTO summaryDTO = (DistributionSummaryDTO)jobExecution.getExecutionContext().get("distributionSummaryDTO"); - if(summaryDTO == null) { - summaryDTO = new DistributionSummaryDTO(); - jobExecution.getExecutionContext().put("distributionSummaryDTO", summaryDTO); - } summaryDTO.setBatchId(jobExecution.getId()); summaryDTO.setStudentSearchRequest(searchRequest); + Long totalSchoolReporsCount = 0L; List reportTypes = searchRequest.getReportTypes(); Long schoolReportsCount = 0L; diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/ArchiveStudentsPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/ArchiveStudentsPartitioner.java index 9600b96d..fe90abd2 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/ArchiveStudentsPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/ArchiveStudentsPartitioner.java @@ -38,6 +38,12 @@ public JobExecution getJobExecution() { @Override public Map 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(); logger.debug("Filter Schools for archiving students"); @@ -48,13 +54,9 @@ public Map partition(int gridSize) { logger.debug("Final list of eligible District / School codes {}", String.join(", ", finalSchoolDistricts)); } - DistributionSummaryDTO summaryDTO = (DistributionSummaryDTO)jobExecution.getExecutionContext().get("distributionSummaryDTO"); - if(summaryDTO == null) { - summaryDTO = new DistributionSummaryDTO(); - jobExecution.getExecutionContext().put("distributionSummaryDTO", summaryDTO); - } summaryDTO.setBatchId(jobExecution.getId()); summaryDTO.setStudentSearchRequest(searchRequest); + List studentStatusCodes = searchRequest.getStatuses(); Long totalStudentsCount = 0L; for(String schoolOfRecord: finalSchoolDistricts) { 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 4b10cfd0..621570f7 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 @@ -121,17 +121,21 @@ protected void saveInputData(List studentIDs) { protected BatchGradAlgorithmJobHistoryEntity createBatchJobHistory() { Long jobExecutionId = getJobExecution().getId(); - JobParameters jobParameters = getJobExecution().getJobParameters(); + return createBatchJobHistory(jobExecutionId, getJobExecution(), 0); + } + + protected BatchGradAlgorithmJobHistoryEntity createBatchJobHistory(Long jobExecutionId, JobExecution jobExecution, long expectedStudentsProcessed) { + JobParameters jobParameters = jobExecution.getJobParameters(); String jobTrigger = jobParameters.getString("jobTrigger"); String jobType = jobParameters.getString("jobType"); String username = jobParameters.getString(RUN_BY); String studentSearchRequest = jobParameters.getString(SEARCH_REQUEST); - String status = getJobExecution().getStatus().toString(); - Date startTime = DateUtils.toDate(getJobExecution().getStartTime()); + String status = jobExecution.getStatus().toString(); + Date startTime = DateUtils.toDate(jobExecution.getStartTime()); BatchGradAlgorithmJobHistoryEntity ent = new BatchGradAlgorithmJobHistoryEntity(); ent.setActualStudentsProcessed(0L); - ent.setExpectedStudentsProcessed(0L); + ent.setExpectedStudentsProcessed(expectedStudentsProcessed); ent.setFailedStudentsProcessed(0); ent.setJobExecutionId(jobExecutionId); ent.setStartTime(DateUtils.toLocalDateTime(startTime)); diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DeleteStudentReportsPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DeleteStudentReportsPartitioner.java index 97281720..34651adf 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DeleteStudentReportsPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DeleteStudentReportsPartitioner.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.batchgraduation.reader; +import ca.bc.gov.educ.api.batchgraduation.entity.BatchGradAlgorithmJobHistoryEntity; import ca.bc.gov.educ.api.batchgraduation.model.DistributionSummaryDTO; import ca.bc.gov.educ.api.batchgraduation.model.School; import ca.bc.gov.educ.api.batchgraduation.model.StudentSearchRequest; @@ -13,12 +14,12 @@ import java.util.*; -import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.SEARCH_REQUEST; - public class DeleteStudentReportsPartitioner extends BasePartitioner { private static final Logger logger = LoggerFactory.getLogger(DeleteStudentReportsPartitioner.class); + public static final Integer DEFAULT_ROW_COUNT = 25000; + @Value("#{stepExecution.jobExecution}") JobExecution jobExecution; @@ -36,74 +37,71 @@ public JobExecution getJobExecution() { @Override public Map partition(int gridSize) { + DistributionSummaryDTO distributionSummaryDTO = (DistributionSummaryDTO)jobExecution.getExecutionContext().get("distributionSummaryDTO"); + if(distributionSummaryDTO == null) { + distributionSummaryDTO = new DistributionSummaryDTO(); + jobExecution.getExecutionContext().put("distributionSummaryDTO", distributionSummaryDTO); + } + StudentSearchRequest searchRequest = getStudentSearchRequest(); long startTime = System.currentTimeMillis(); logger.debug("Filter Schools for deleting student reports"); boolean processAllReports = "ALL".equalsIgnoreCase(searchRequest.getActivityCode()); + Long batchId = jobExecution.getId();; List eligibleStudentSchoolDistricts = gradSchoolOfRecordFilter.filterSchoolOfRecords(searchRequest); List finalSchoolDistricts = eligibleStudentSchoolDistricts.stream().sorted().toList(); if(logger.isDebugEnabled()) { logger.debug("Final list of eligible District / School codes {}", String.join(", ", finalSchoolDistricts)); } - DistributionSummaryDTO distributionSummaryDTO = (DistributionSummaryDTO)jobExecution.getExecutionContext().get("distributionSummaryDTO"); - if(distributionSummaryDTO == null) { - distributionSummaryDTO = new DistributionSummaryDTO(); - jobExecution.getExecutionContext().put("distributionSummaryDTO", distributionSummaryDTO); - } + searchRequest.setSchoolOfRecords(finalSchoolDistricts); if(searchRequest.getReportTypes().isEmpty()) { searchRequest.getReportTypes().add("ACHV"); } + Long totalStudentReportsCount = 0L; + + BatchGradAlgorithmJobHistoryEntity algorithmJobHistory = createBatchJobHistory(); + List finalStudentGuids = new ArrayList<>(); if(processAllReports) { for(String reportType: searchRequest.getReportTypes()) { - List reportTypeGuids = restUtils.getReportStudentIDsByStudentIDsAndReportType(List.of(), reportType, distributionSummaryDTO); + Long studentReportsCount = restUtils.getTotalReportsForProcessing(List.of(), reportType, distributionSummaryDTO); + Integer guidsRowCount = Integer.min(studentReportsCount.intValue(), DEFAULT_ROW_COUNT); + totalStudentReportsCount += guidsRowCount; + List reportTypeGuids = restUtils.getReportStudentIDsByStudentIDsAndReportType(List.of(), reportType, guidsRowCount, distributionSummaryDTO); finalStudentGuids.addAll(reportTypeGuids); } } else { List studentGuidsBySearch = restUtils.getStudentIDsBySearchCriteriaOrAll(searchRequest, distributionSummaryDTO); + List studentGuidsBySearchString = studentGuidsBySearch.stream().map(UUID::toString).toList(); for(String reportType: searchRequest.getReportTypes()) { - List reportTypeGuids = restUtils.getReportStudentIDsByStudentIDsAndReportType(studentGuidsBySearch.stream().map(UUID::toString).toList(), reportType, distributionSummaryDTO); + Long studentReportsCount = restUtils.getTotalReportsForProcessing(studentGuidsBySearchString, reportType, distributionSummaryDTO); + Integer guidsRowCount = Integer.min(studentReportsCount.intValue(), DEFAULT_ROW_COUNT); + totalStudentReportsCount += guidsRowCount; + List reportTypeGuids = restUtils.getReportStudentIDsByStudentIDsAndReportType(studentGuidsBySearchString, reportType, guidsRowCount, distributionSummaryDTO); finalStudentGuids.addAll(reportTypeGuids); } } - searchRequest.setStudentIDs(finalStudentGuids); - Integer totalStudentReportsCount = finalStudentGuids.size(); - distributionSummaryDTO.setBatchId(jobExecution.getId()); + updateBatchJobHistory(algorithmJobHistory, totalStudentReportsCount); + + searchRequest.setStudentIDs(finalStudentGuids); + distributionSummaryDTO.setBatchId(batchId); distributionSummaryDTO.setStudentSearchRequest(searchRequest); long endTime = System.currentTimeMillis(); long diff = (endTime - startTime)/1000; logger.debug("Total {} student reports after filters in {} sec", totalStudentReportsCount, diff); - updateBatchJobHistory(createBatchJobHistory(), totalStudentReportsCount.longValue()); distributionSummaryDTO.setReadCount(0); distributionSummaryDTO.setProcessedCount(0); Map map; - if(processAllReports && totalStudentReportsCount > 0) { - //proceed with all reports - finalStudentGuids.clear(); - map = new HashMap<>(); - ExecutionContext executionContext = new ExecutionContext(); - DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); - School school = new School("ALL_STUDENTS"); - school.setNumberOfStudents(totalStudentReportsCount); - summaryDTO.getSchools().add(school); - summaryDTO.setBatchId(jobExecution.getId()); - summaryDTO.setReadCount(totalStudentReportsCount); - summaryDTO.setStudentSearchRequest(searchRequest); - executionContext.put(SEARCH_REQUEST, searchRequest); - executionContext.put("data", finalStudentGuids); - executionContext.put("summary", summaryDTO); - executionContext.put("readCount", 0); - map.put("partition0", executionContext); - } else if (totalStudentReportsCount > 0) { - int partitionSize = finalStudentGuids.size()/gridSize + 1; - List> partitions = new LinkedList<>(); + List> partitions = new LinkedList<>(); + if(totalStudentReportsCount > 0) { + int partitionSize = Integer.min(finalStudentGuids.size()/gridSize + 1, 1000); for (int i = 0; i < finalStudentGuids.size(); i += partitionSize) { partitions.add(finalStudentGuids.subList(i, Math.min(i + partitionSize, finalStudentGuids.size()))); } @@ -115,10 +113,10 @@ public Map partition(int gridSize) { School school = new School("" + i); school.setNumberOfStudents(data.size()); summaryDTO.getSchools().add(school); - executionContext.put("data", data); - summaryDTO.setBatchId(jobExecution.getId()); + summaryDTO.setBatchId(batchId); summaryDTO.setReadCount(0); summaryDTO.setStudentSearchRequest(searchRequest); + executionContext.put("data", data); executionContext.put("summary", summaryDTO); executionContext.put("readCount", 0); executionContext.put("index",i); @@ -128,7 +126,7 @@ public Map partition(int gridSize) { } else { map = new HashMap<>(); } - logger.info("Found {} in total running on 1 partitions", totalStudentReportsCount); + logger.info("Found {} in total running on {} partitions", totalStudentReportsCount, partitions.size()); return map; } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java index 599fcf33..7500563d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java @@ -710,7 +710,7 @@ public void updateStudentGradRecordHistory(List studentIDs, Long batchId, this.put(url,studentIDs, GraduationStudentRecord.class, accessToken); } } catch (Exception e) { - LOGGER.error("Unable to update student record history"); + LOGGER.error("Unable to update student record history {}", e.getLocalizedMessage()); } } @@ -890,12 +890,12 @@ public Long getTotalReportsForProcessing(List finalSchoolDistricts, Stri summaryDTO.setException(e.getLocalizedMessage()); } if(LOGGER.isDebugEnabled()) { - LOGGER.debug("{} of {} reports for processing", reportsCount, reportType); + LOGGER.debug("Total {} of {} reports available", reportsCount, reportType); } return reportsCount; } - public List getReportStudentIDsByStudentIDsAndReportType(List finalSchoolDistricts, String reportType, DistributionSummaryDTO summaryDTO) { + public List getReportStudentIDsByStudentIDsAndReportType(List finalSchoolDistricts, String reportType, Integer rowCount, DistributionSummaryDTO summaryDTO) { List result = new ArrayList<>(); UUID correlationID = UUID.randomUUID(); try { @@ -903,7 +903,7 @@ public List getReportStudentIDsByStudentIDsAndReportType(List fina final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { }; List guids = this.webClient.post() - .uri(String.format(constants.getGradStudentReportsGuidsUrl(), reportType)) + .uri(String.format(constants.getGradStudentReportsGuidsUrl(), reportType, rowCount)) .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, correlationID.toString()); }) .body(BodyInserters.fromValue(finalSchoolDistricts)) .retrieve().bodyToMono(responseType).block(); @@ -915,16 +915,13 @@ public List getReportStudentIDsByStudentIDsAndReportType(List fina summaryDTO.setException(e.getLocalizedMessage()); } if(LOGGER.isDebugEnabled()) { - LOGGER.debug("{} of {} reports for processing", result.size(), reportType); + LOGGER.debug("Total {} of {} reports for processing", result.size(), reportType); } return result; } public Integer archiveSchoolReports(Long batchId, List finalSchoolDistricts, String reportType, DistributionSummaryDTO summaryDTO) { UUID correlationID = UUID.randomUUID(); - if(LOGGER.isDebugEnabled()) { - LOGGER.debug("Archive {} School Reports for Ministry Codes: {}", reportType, !finalSchoolDistricts.isEmpty() ? String.join(",", finalSchoolDistricts) : summaryDTO.getSchools().stream().map(School::getMincode).collect(Collectors.joining(","))); - } try { String accessToken = getAccessToken(); return this.webClient.post() @@ -958,20 +955,18 @@ public Long getTotalStudentsBySchoolOfRecordAndStudentStatus(List finalS summaryDTO.setException(e.getLocalizedMessage()); } if(LOGGER.isDebugEnabled()) { - LOGGER.debug("{} of {} students for archiving of SoR: {}", studentsCount, studentStatus, String.join(",", finalSchoolDistricts)); + LOGGER.debug("Total {} of {} students for archiving of SoR: {}", studentsCount, studentStatus, String.join(",", finalSchoolDistricts)); } return studentsCount; } public Integer archiveStudents(Long batchId, List finalSchoolDistricts, String studentStatus, DistributionSummaryDTO summaryDTO) { UUID correlationID = UUID.randomUUID(); - if(LOGGER.isDebugEnabled()) { - LOGGER.debug("Archive {} Students for Ministry Codes: {}", studentStatus, String.join(",", finalSchoolDistricts)); - } try { String accessToken = getAccessToken(); + String userName = StringUtils.defaultString(summaryDTO.getUserName(), "Batch Archive Process"); return this.webClient.post() - .uri(String.format(constants.getGradArchiveStudentsUrl(), batchId, studentStatus)) + .uri(String.format(constants.getGradArchiveStudentsUrl(), batchId, studentStatus, userName)) .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, correlationID.toString()); }) .body(BodyInserters.fromValue(finalSchoolDistricts)) .retrieve().bodyToMono(Integer.class).block(); @@ -986,9 +981,6 @@ public Integer archiveStudents(Long batchId, List finalSchoolDistricts, public List getStudentIDsBySearchCriteriaOrAll(StudentSearchRequest searchRequest, DistributionSummaryDTO summaryDTO) { UUID correlationID = UUID.randomUUID(); - if(LOGGER.isDebugEnabled()) { - LOGGER.debug("Get Students for Ministry Codes: {}", String.join(",", searchRequest.getSchoolOfRecords())); - } try { String accessToken = getAccessToken(); final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/util/EducGradBatchGraduationApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/util/EducGradBatchGraduationApiConstants.java index bcbf3a71..2fa7b0d8 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/util/EducGradBatchGraduationApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/util/EducGradBatchGraduationApiConstants.java @@ -28,9 +28,9 @@ public class EducGradBatchGraduationApiConstants { public static final String EXECUTE_YEARLY_NON_GRAD_DIS_RUN_BATCH_JOB = "/executenongraddisrunbatchjob"; public static final String EXECUTE_CERT_REGEN_BATCH_JOB = "/executecertregenbatchjob"; public static final String EXECUTE_EDW_SNAPSHOT_BATCH_JOB = "/executeedwsnapshotbatchjob"; - public static final String EXECUTE_ARCHIVE_SCHOOL_REPORTS_RUN_BATCH_JOB = "/executearchivebatchjobschoolreports"; - public static final String EXECUTE_DELETE_STUDENT_REPORTS_RUN_BATCH_JOB = "/executedeletebatchjobstudentreports"; - public static final String EXECUTE_YEARLY_ARCHIVE_STUDENTS_RUN_BATCH_JOB = "/executeyearlyarchivebatchjobstudents"; + public static final String EXECUTE_ARCHIVE_SCHOOL_REPORTS_RUN_BATCH_JOB = "/report/school/archive"; + public static final String EXECUTE_DELETE_STUDENT_REPORTS_RUN_BATCH_JOB = "/report/student/delete"; + public static final String EXECUTE_YEARLY_ARCHIVE_STUDENTS_RUN_BATCH_JOB = "/student/archive"; // Special Run public static final String EXECUTE_SPECIALIZED_RUNS = "/specialrun"; @@ -91,6 +91,7 @@ public class EducGradBatchGraduationApiConstants { public static final String TVRCREATE = "tvrCreated"; public static final String TVRUPDATE = "tvrUpdated"; public static final String TVRDELETE = "tvrDeleted"; + public static final String ALL = "all"; @Value("${authorization.user}") private String userName; diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index 64ed3aac..6a954e90 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -170,7 +170,7 @@ endpoint: url: ${GRAD_GRADUATION_API}api/v1/graduate/edw/snapshot grad-student-api: get-students-count: ${GRAD_STUDENT_API}api/v1/student/count?studentStatus=%S - archive-students: ${GRAD_STUDENT_API}api/v1/student/archive?batchId=%s&studentStatus=%S + archive-students: ${GRAD_STUDENT_API}api/v1/student/archive?batchId=%s&studentStatus=%S&userName=%s grad-status: ${GRAD_STUDENT_API}api/v1/student/studentid/%s student-for-grad-list: ${GRAD_STUDENT_API}api/v1/student/recalculate student-for-projectedgrad-list: ${GRAD_STUDENT_API}api/v1/student/projected @@ -192,11 +192,11 @@ endpoint: get-deceased-student-id-list: ${GRAD_STUDENT_API}api/v1/student/deceasedstudentid grad-graduation-report-api: get-school-reports-count: - url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/count?reportType=%S + url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/count?reportType=%s get-student-reports-guid: - url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/studentreportsbystudentid?reportType=%S + url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/studentreportsbystudentid?reportType=%s&rowCount=%s archive-school-reports: - url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/archive?batchId=%s&reportType=%S + url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/archive?batchId=%s&reportType=%s get-transcript-list: yearly: url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/gettranscriptsfordistributionyearly diff --git a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/controller/JobLauncherControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/controller/JobLauncherControllerTest.java index f1c3cded..fa3b2918 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/controller/JobLauncherControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/controller/JobLauncherControllerTest.java @@ -448,7 +448,7 @@ public void testArchiveSchoolReportsBatchJob() { try { createJob(210L, "archiveSchoolReportsBatchJob", builder.toJobParameters()); ResponseEntity result = jobLauncherController.launchArchiveSchoolReportsJob(request); - assertThat(result.getStatusCode().value()).isEqualTo(200); + assertThat(result.getStatusCode().value()).isEqualTo(201); } catch (Exception e) { exceptionIsThrown = true; } @@ -460,6 +460,7 @@ public void testDeleteStudentReportsBatchJob() { ThreadLocalStateUtil.setCurrentUser("Batch Process"); StudentSearchRequest request = new StudentSearchRequest(); request.setSchoolOfRecords(List.of("12345678")); + request.setReportTypes(List.of("ACHV")); String searchData = jsonTransformer.marshall(request); @@ -476,7 +477,7 @@ public void testDeleteStudentReportsBatchJob() { try { createJob(210L, "deleteStudentReportsBatchJob", builder.toJobParameters()); ResponseEntity result = jobLauncherController.launchDeleteStudentReportsJob(request); - assertThat(result.getStatusCode().value()).isEqualTo(200); + assertThat(result.getStatusCode().value()).isEqualTo(201); } catch (Exception e) { exceptionIsThrown = true; } @@ -504,7 +505,7 @@ public void testArchiveStudentsBatchJob() { try { createJob(210L, "archiveStudentsBatchJob", builder.toJobParameters()); ResponseEntity result = jobLauncherController.launchArchiveStudentsJob(request); - assertThat(result.getStatusCode().value()).isEqualTo(200); + assertThat(result.getStatusCode().value()).isEqualTo(201); } catch (Exception e) { exceptionIsThrown = true; } diff --git a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java index 4d10cf19..21e949e5 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java @@ -130,6 +130,10 @@ public void testGetStudentByPen_givenValues_returnsStudent_with_APICallSuccess() assertThat(result).isNotNull(); assertThat(result.size()).isPositive(); assertThat(result.get(0).getPen()).isEqualTo(pen); + + val result2 = this.restUtils.getStudentIDByPen(pen, "abc"); + assertThat(result2).isNotNull(); + } @Test @@ -857,6 +861,7 @@ public void testcreateAndStoreSchoolReports() { @Test public void testProcessStudentReports() { final String studentReportType = "TVRRUN"; + UUID studentID = UUID.randomUUID(); when(this.webClient.post()).thenReturn(this.requestBodyUriMock); when(this.requestBodyUriMock.uri(String.format(constants.getUpdateStudentReport(), studentReportType))).thenReturn(this.requestBodyUriMock); @@ -868,7 +873,7 @@ public void testProcessStudentReports() { mockTokenResponseObject(); - var result = this.restUtils.processStudentReports(new ArrayList<>(),studentReportType); + var result = this.restUtils.processStudentReports(List.of(studentID),studentReportType); assertNotNull(studentReportType); assertNotNull(result); } @@ -1127,6 +1132,40 @@ public void testGetStudentsForUserReqDisRun() { assertThat(result.size()).isPositive(); } + @Test + public void testGetStudentsForUserReqDisRunWithNullDistributionDate() { + String activityCode = "USERDISTRC"; + DistributionResponse req = new DistributionResponse(); + req.setMergeProcessResponse("Merged"); + Long batchId = 3344L; + + List scdList = new ArrayList<>(); + StudentCredentialDistribution scd = new StudentCredentialDistribution(); + scd.setSchoolOfRecord("1212211"); + scd.setPaperType("YED2"); + scd.setCredentialTypeCode("E"); + scd.setId(new UUID(1,1)); + scdList.add(scd); + + mockTokenResponseObject(); + + final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { + }; + + when(this.webClient.post()).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(String.format(constants.getStudentDataForUserReqDisRunWithNullDistributionDate(),activityCode))).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(scdList)); + + StudentSearchRequest searchRequest = new StudentSearchRequest(); + searchRequest.setActivityCode(activityCode); + + val result = this.restUtils.getStudentsForUserReqDisRunWithNullDistributionDate(activityCode,searchRequest); + assertThat(result).isNotNull(); + } + @Test public void testCreateReprintAndUpload() { String activityCode = "USERDISTRC"; @@ -1704,7 +1743,7 @@ public void testGetReportStudentIDsByStudentIDsAndReportType() { }; when(this.webClient.post()).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.uri(String.format(constants.getGradStudentReportsGuidsUrl(), "ACHV"))).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(String.format(constants.getGradStudentReportsGuidsUrl(), "ACHV", 1))).thenReturn(this.requestBodyUriMock); when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); when(this.requestBodyMock.contentType(any())).thenReturn(this.requestBodyMock); when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); @@ -1713,7 +1752,7 @@ public void testGetReportStudentIDsByStudentIDsAndReportType() { DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); - val result = this.restUtils.getReportStudentIDsByStudentIDsAndReportType(studentIDsIn, "ACHV", summaryDTO); + val result = this.restUtils.getReportStudentIDsByStudentIDsAndReportType(studentIDsIn, "ACHV", 1, summaryDTO); assertThat(result).isNotEmpty(); } @@ -1729,7 +1768,7 @@ public void testGetReportStudentIDsByStudentIDsAndReportTypeError() { }; when(this.webClient.post()).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.uri(String.format(constants.getGradStudentReportsGuidsUrl(), "ACHV"))).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(String.format(constants.getGradStudentReportsGuidsUrl(), "ACHV", 1))).thenReturn(this.requestBodyUriMock); when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); when(this.requestBodyMock.contentType(any())).thenReturn(this.requestBodyMock); when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); @@ -1738,7 +1777,7 @@ public void testGetReportStudentIDsByStudentIDsAndReportTypeError() { DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); - val result = this.restUtils.getReportStudentIDsByStudentIDsAndReportType(studentIDsIn, "ACHV", summaryDTO); + val result = this.restUtils.getReportStudentIDsByStudentIDsAndReportType(studentIDsIn, "ACHV", 1, summaryDTO); assertThat(result).isEmpty(); assertThat(summaryDTO.getErrors()).isNotEmpty(); } @@ -1941,7 +1980,7 @@ public void testArchiveStudents() { mockTokenResponseObject(); when(this.webClient.post()).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.uri(String.format(constants.getGradArchiveStudentsUrl(), 12345678L, "CUR"))).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(String.format(constants.getGradArchiveStudentsUrl(), 12345678L, "CUR", "USER"))).thenReturn(this.requestBodyUriMock); when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); when(this.requestBodyMock.contentType(any())).thenReturn(this.requestBodyMock); when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); @@ -1949,6 +1988,7 @@ public void testArchiveStudents() { when(this.responseMock.bodyToMono(Integer.class)).thenReturn(Mono.just(1)); DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); + summaryDTO.setUserName("USER"); val result = this.restUtils.archiveStudents(12345678L, schools,"CUR", summaryDTO); assertThat(result).isEqualTo(1); @@ -1961,7 +2001,7 @@ public void testArchiveStudentsError() { mockTokenResponseObject(); when(this.webClient.post()).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.uri(String.format(constants.getGradArchiveStudentsUrl(), 12345678L, "CUR"))).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(String.format(constants.getGradArchiveStudentsUrl(), 12345678L, "CUR", "USER"))).thenReturn(this.requestBodyUriMock); when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); when(this.requestBodyMock.contentType(any())).thenReturn(this.requestBodyMock); when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); @@ -1969,6 +2009,7 @@ public void testArchiveStudentsError() { when(this.responseMock.bodyToMono(Integer.class)).thenReturn(Mono.just(0)); DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); + summaryDTO.setUserName("USER"); val result = this.restUtils.archiveStudents(12345678L, schools,"CUR", summaryDTO); assertThat(result).isNotNull(); @@ -2028,6 +2069,32 @@ public void testProcessSnapshot() { assertThat(result.getPen()).isEqualTo(snapshot.getPen()); } + @Test + public void testProcessSnapshotException() { + final Integer gradYear = Integer.parseInt("2023"); + final String mincode = "12345678"; + + EdwGraduationSnapshot snapshot = new EdwGraduationSnapshot(); + snapshot.setStudentID(UUID.randomUUID()); + snapshot.setPen("123456789"); + snapshot.setGradYear(gradYear); + snapshot.setSchoolOfRecord(mincode); + + when(this.webClient.post()).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(constants.getSnapshotGraduationStatusForEdwUrl())).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.contentType(any())).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.body(any(BodyInserter.class))).thenThrow(new RuntimeException()); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(EdwGraduationSnapshot.class)).thenReturn(Mono.just(snapshot)); + + EdwSnapshotSummaryDTO summaryDTO = new EdwSnapshotSummaryDTO(); + + val result = this.restUtils.processSnapshot(snapshot, summaryDTO); + assertThat(result).isNull(); + assertThat(summaryDTO.getErrors()).isNotEmpty(); + } + @Test public void testGetDeceasedStudentIDs() { diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index 960cd57a..aa738a89 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -136,7 +136,7 @@ endpoint: url: https://educ-grad-graduation-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduate/edw/snapshot grad-student-api: get-students-count: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/count?studentStatus=%S - archive-students: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/archive??batchId=%s&studentStatus=%S + archive-students: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/archive??batchId=%s&studentStatus=%S&userName=%s grad-status: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/studentid/%s student-for-grad-list: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/recalculate student-for-projectedgrad-list: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/projected @@ -158,11 +158,11 @@ endpoint: get-deceased-student-id-list: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/deceasedstudentid grad-graduation-report-api: get-school-reports-count: - url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/count?reportType=%S + url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/count?reportType=%s get-student-reports-guid: - url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/studentreportsbystudentid?reportType=%S + url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/studentreportsbystudentid?reportType=%s&rowCount=%s archive-school-reports: - url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/archive?batchId=%s&reportType=%S + url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/archive?batchId=%s&reportType=%s get-transcript-list: yearly: url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/gettranscriptsfordistributionyearly