diff --git a/api/pom.xml b/api/pom.xml index 4cb180d3..a8c712c6 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,7 +6,7 @@ ca.bc.gov.educ educ-grad-batch-graduation-api - 1.8.60 + 1.8.61 educ-grad-batch-graduation-api Ministry of Education GRAD BATCH GRADUATION API diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/config/BatchJobConfig.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/config/BatchJobConfig.java index ac7ba394..ac0d0d78 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/config/BatchJobConfig.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/config/BatchJobConfig.java @@ -519,6 +519,12 @@ public DistributionRunProcessor itemProcessorDisRun() { return new DistributionRunProcessor(); } + @Bean + @StepScope + public DistributionRunYearlyProcessor itemProcessorYearlyDisRun() { + return new DistributionRunYearlyProcessor(); + } + @Bean @StepScope public DistributionRunYearlyNonGradProcessor itemProcessorDisRunYearlyNonGradByMincode() { @@ -571,7 +577,7 @@ public Step slaveStepDisRunYearly(JobRepository jobRepository, PlatformTransacti return new StepBuilder("slaveStepDisRun", jobRepository) .chunk(1, transactionManager) .reader(itemReaderDisRun()) - .processor(itemProcessorDisRun()) + .processor(itemProcessorYearlyDisRun()) .writer(itemWriterDisRun()) .build(); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/config/RestWebClient.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/config/RestWebClient.java index 2535789d..4d1cf748 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/config/RestWebClient.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/config/RestWebClient.java @@ -27,7 +27,7 @@ public WebClient webClient() { return WebClient.builder().exchangeStrategies(ExchangeStrategies.builder() .codecs(configurer -> configurer .defaultCodecs() - .maxInMemorySize(300 * 1024 * 1024)) // 100 MB + .maxInMemorySize(300 * 1024 * 1024)) // 300 MB .build()).build(); } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/entity/BatchJobExecutionEntity.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/entity/BatchJobExecutionEntity.java index 094b9b9a..a46d5a74 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/entity/BatchJobExecutionEntity.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/entity/BatchJobExecutionEntity.java @@ -4,7 +4,6 @@ import lombok.Data; import lombok.EqualsAndHashCode; -import java.time.Instant; import java.time.LocalDateTime; @Data diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqDistributionRunCompletionNotificationListener.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqDistributionRunCompletionNotificationListener.java index a74d51da..f00e5040 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqDistributionRunCompletionNotificationListener.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqDistributionRunCompletionNotificationListener.java @@ -128,7 +128,7 @@ private void processGlobalList(DistributionSummaryDTO summaryDTO, Long batchId, DistributionResponse disres = null; String activityCode = null; if(credentialType != null) { - if(credentialType.equalsIgnoreCase("OC")) { + if("OC".equalsIgnoreCase(credentialType)) { activityCode = "USERDISTOC"; /** GRADT-553 * User Request Distribution Run - Original Certificate OC @@ -136,7 +136,7 @@ private void processGlobalList(DistributionSummaryDTO summaryDTO, Long batchId, */ addTranscriptsToDistributionRequest(cList,summaryDTO,batchId,properName); } else { - activityCode = credentialType.equalsIgnoreCase("OT")?"USERDISTOT":"USERDISTRC"; + activityCode = "OT".equalsIgnoreCase(credentialType) ? "USERDISTOT" : "USERDISTRC"; } if(!cList.isEmpty()) { DistributionRequest distributionRequest = DistributionRequest.builder().mapDist(mapDist).activityCode(activityCode).studentSearchRequest(summaryDTO.getStudentSearchRequest()).build(); @@ -164,7 +164,7 @@ private void addTranscriptsToDistributionRequest(List transcriptDistributionList = restUtils.getStudentsForUserReqDisRun("OT",searchRequest,restUtils.getTokenResponseObject().getAccess_token()); + List transcriptDistributionList = restUtils.getStudentsForUserReqDisRun("OT",searchRequest); for(StudentCredentialDistribution certScd: uniqueCertificateList) { for(StudentCredentialDistribution trScd: transcriptDistributionList) { if(certScd.getStudentID().equals(trScd.getStudentID())) { @@ -196,8 +196,7 @@ private void updateBackStudentRecords(List cList, }); List studentIDs = cList.stream().map(StudentCredentialDistribution::getStudentID).distinct().collect(Collectors.toList()); studentIDs.forEach(sid-> { - String accessToken = restUtils.fetchAccessToken(); - restUtils.updateStudentGradRecord(sid,batchId,activityCode,accessToken); + restUtils.updateStudentGradRecord(sid,batchId,activityCode); }); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqPsiDistributionRunCompletionNotificationListener.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqPsiDistributionRunCompletionNotificationListener.java index d453ca64..03f2b722 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqPsiDistributionRunCompletionNotificationListener.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqPsiDistributionRunCompletionNotificationListener.java @@ -110,7 +110,7 @@ private void updateBackStudentRecords(List cList, Lon cList.forEach(scd-> { LOGGER.debug("Update back Student Record {}", scd.getStudentID()); String accessToken = restUtils.fetchAccessToken(); - restUtils.updateStudentGradRecord(scd.getStudentID(),batchId,activityCode,accessToken); + restUtils.updateStudentGradRecord(scd.getStudentID(),batchId,activityCode); }); } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/CertificateRegenerationRequest.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/CertificateRegenerationRequest.java index add4d234..1f8a3e88 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/CertificateRegenerationRequest.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/CertificateRegenerationRequest.java @@ -1,20 +1,22 @@ package ca.bc.gov.educ.api.batchgraduation.model; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; -import java.io.Serializable; -import java.util.List; - @Data @Component @NoArgsConstructor @AllArgsConstructor -@Builder -public class CertificateRegenerationRequest implements Serializable { - private List pens; +public class CertificateRegenerationRequest extends StudentSearchRequest { private String runMode; // "Y" or "N" + + public boolean runForAll () { + return (getPens() == null || getPens().isEmpty()) && + (getDistricts() == null || getDistricts().isEmpty()) && + (getSchoolOfRecords() == null || getSchoolOfRecords().isEmpty()) && + (getSchoolCategoryCodes() == null || getSchoolCategoryCodes().isEmpty()) && + (getStudentIDs() == null || getStudentIDs().isEmpty()); + } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/GraduationStudentRecordDistribution.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/GraduationStudentRecordDistribution.java index 6b72d27a..c589545f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/GraduationStudentRecordDistribution.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/GraduationStudentRecordDistribution.java @@ -18,6 +18,7 @@ public class GraduationStudentRecordDistribution extends BaseModel{ private String legalMiddleNames; private String legalLastName; private String schoolOfRecord; + private String schoolAtGrad; private String programCompletionDate; private String honoursStanding; private String program; diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/JobProperName.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/JobProperName.java index ce8f8715..6eaf21af 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/JobProperName.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/JobProperName.java @@ -9,7 +9,8 @@ public enum JobProperName { NDBJ("Non-Grad Distribution Batch Job"), URDBJ ("User Req Distribution Batch Job"), URPDBJ("PSI Distribution Batch Job"), - BDBJ ("Blank Distribution Batch Job"); + BDBJ ("Blank Distribution Batch Job"), + RCBJ ("Regenerate Certificates Batch Job"); private final String value; diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/JobSelection.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/JobSelection.java index 7849917f..88d6f439 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/JobSelection.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/JobSelection.java @@ -9,7 +9,8 @@ public enum JobSelection { NDBJ("NONGRADRUN"), URDBJ ("DISTRUNUSER"), URPDBJ ("PSIRUN"), - BDBJ ("DISTRUNUSER"); + BDBJ ("DISTRUNUSER"), + RCBJ ("CERT_REGEN"); private final String value; diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/StudentCredentialDistribution.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/StudentCredentialDistribution.java index ffd4aaba..ee3cc93f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/StudentCredentialDistribution.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/StudentCredentialDistribution.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.batchgraduation.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import java.io.Serializable; @@ -27,4 +28,9 @@ public class StudentCredentialDistribution implements Serializable { private String studentGrade; private List nonGradReasons; + @JsonIgnore + private String schoolAtGrad; + @JsonIgnore + private String schoolOfRecordOrigin; + } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/StudentSearchRequest.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/StudentSearchRequest.java index 8bff9ac9..ae37c4fb 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/StudentSearchRequest.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/StudentSearchRequest.java @@ -8,7 +8,7 @@ import org.springframework.stereotype.Component; import java.io.Serializable; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import java.util.UUID; @@ -29,9 +29,9 @@ public class StudentSearchRequest implements Serializable { private Address address; @JsonFormat(pattern = "yyyy-MM-dd") - Date gradDateFrom; + LocalDate gradDateFrom; @JsonFormat(pattern = "yyyy-MM-dd") - Date gradDateTo; + LocalDate gradDateTo; Boolean validateInput; String localDownload; diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/TaskSelection.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/TaskSelection.java index 9309d64a..c2cc737d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/TaskSelection.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/TaskSelection.java @@ -9,7 +9,8 @@ public enum TaskSelection { NDBJ ("YearlyNonGradDistributionBatchJob"), URDBJ ("UserReqDistributionBatchJob"), URPDBJ("psiDistributionBatchJob"), - BDBJ ("blankDistributionBatchJob"); + BDBJ ("blankDistributionBatchJob"), + RCBJ ("certRegenBatchJob"); private final String value; diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DistributionRunProcessor.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DistributionRunProcessor.java index e2efbc65..33b84cf1 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DistributionRunProcessor.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DistributionRunProcessor.java @@ -27,7 +27,7 @@ public class DistributionRunProcessor implements ItemProcessor updateBackStudentRecords(List studentIDs = cList.stream().map(StudentCredentialDistribution::getStudentID).toList(); cList.forEach(scd-> { try { - final String token = restUtils.getAccessToken(); + final String accessToken = restUtils.getAccessToken(); restUtils.updateStudentCredentialRecord(scd.getStudentID(),scd.getCredentialTypeCode(),scd.getPaperType(), - "NONGRADYERUN".equalsIgnoreCase(activityCode)? "IP" : scd.getDocumentStatusCode(),activityCode,token); + "NONGRADYERUN".equalsIgnoreCase(activityCode)? "IP" : scd.getDocumentStatusCode(),activityCode,accessToken); LOGGER.debug("Dist Job [{}] / [{}] - update {} of {} student credential record: studentID, credentials, document status [{}, {}, {}]", batchId, activityCode, processedCount[0] + 1, totalCount, scd.getStudentID(), scd.getCredentialTypeCode(), scd.getDocumentStatusCode()); - if(!StringUtils.equalsAnyIgnoreCase(jobType, "DISTRUN_YE", "NONGRADRUN", "REGALG", "TVRRUN")) { - restUtils.updateStudentGradRecord(scd.getStudentID(), batchId, activityCode, token); - LOGGER.debug("Dist Job [{}] / [{}] - update {} of {} student grad record: studentID, credentials, document status [{}, {}, {}]", batchId, activityCode, processedCount[0] + 1, totalCount, scd.getStudentID(), scd.getCredentialTypeCode(), scd.getDocumentStatusCode()); - } processedCount[0]++; } catch (Exception e) { unprocessedStudents.put(scd.getStudentID().toString(), new ServiceException(e)); } }); + studentIDs.forEach(uuid-> { + try { + if(!StringUtils.equalsAnyIgnoreCase(jobType, "REGALG", "TVRRUN")) { + restUtils.updateStudentGradRecord(uuid, batchId, activityCode); + LOGGER.debug("Dist Job [{}] / [{}] - update {} of {} student grad record: studentID [{}]", batchId, activityCode, processedCount[0] + 1, totalCount, uuid); + } + processedCount[0]++; + } catch (Exception e) { + unprocessedStudents.put(uuid.toString(), new ServiceException(e)); + } + }); return unprocessedStudents; } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DistributionRunYearlyProcessor.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DistributionRunYearlyProcessor.java index bee5190b..17e1f3c8 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DistributionRunYearlyProcessor.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DistributionRunYearlyProcessor.java @@ -26,7 +26,7 @@ public class DistributionRunYearlyProcessor implements ItemProcessor>>> { @@ -31,7 +30,7 @@ public class EDWSnapshotSchoolProcessor implements ItemProcessor>> process(String mincode) throws Exception { summaryDTO.setBatchId(batchId); LOGGER.debug("Processing partitionData for School: {} ", mincode); - List edwStudents = restUtils.getEDWSnapshotStudents(summaryDTO.getGradYear(), mincode, summaryDTO.getAccessToken()); + List edwStudents = restUtils.getEDWSnapshotStudents(summaryDTO.getGradYear(), mincode); if ("L".equals(summaryDTO.getOption())) { List list = edwStudents.stream().filter(s -> StringUtils.isNotBlank(s.getGraduatedDate()) || ("12".equals(s.getStudentGrade()) || "AD".equals(s.getStudentGrade()))).toList(); diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/RunCertificateRegenerationProcessor.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/RunCertificateRegenerationProcessor.java index 94cfaa9a..479cc100 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/RunCertificateRegenerationProcessor.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/RunCertificateRegenerationProcessor.java @@ -26,15 +26,15 @@ public class RunCertificateRegenerationProcessor implements ItemProcessor 0) { - restUtils.updateStudentGradRecord(key, batchId, "CERTREGEN", summaryDTO.getAccessToken()); + restUtils.updateStudentGradRecord(key, batchId, "CERTREGEN"); } return count; } catch(Exception e) { 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 8c8fd18b..13c98a3f 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 @@ -227,24 +227,29 @@ void filterByStudentSearchRequest(List eligibleSt } } eligibleStudentSchoolDistricts.removeIf(scr->StringUtils.isNotBlank(scr.getSchoolOfRecord()) && !useFilterSchoolDistricts.contains(scr.getSchoolOfRecord())); + LOGGER.debug("Student Credential Distribution filtered by schoolCategory code {}: ", searchRequest.getSchoolCategoryCodes()); } if(searchRequest != null && searchRequest.getDistricts() != null && !searchRequest.getDistricts().isEmpty()) { eligibleStudentSchoolDistricts.removeIf(scr->StringUtils.isNotBlank(scr.getSchoolOfRecord()) && !searchRequest.getDistricts().contains(StringUtils.substring(scr.getSchoolOfRecord(), 0, 3))); + LOGGER.debug("Student Credential Distribution filtered by district code {}: ", searchRequest.getDistricts()); } if(searchRequest != null && searchRequest.getSchoolOfRecords() != null && !searchRequest.getSchoolOfRecords().isEmpty()) { eligibleStudentSchoolDistricts.removeIf(scr->StringUtils.isNotBlank(scr.getSchoolOfRecord()) && !searchRequest.getSchoolOfRecords().contains(scr.getSchoolOfRecord())); + LOGGER.debug("Student Credential Distribution filtered by schoolOfRecord code {}: ", searchRequest.getSchoolOfRecords()); } if(searchRequest != null && searchRequest.getStudentIDs() != null && !searchRequest.getStudentIDs().isEmpty()) { eligibleStudentSchoolDistricts.removeIf(scr->scr.getStudentID() != null && !searchRequest.getStudentIDs().contains(scr.getStudentID())); + LOGGER.debug("Student Credential Distribution filtered by student ID {}: ", searchRequest.getStudentIDs()); } if(searchRequest != null && searchRequest.getPens() != null && !searchRequest.getPens().isEmpty()) { eligibleStudentSchoolDistricts.removeIf(scr->StringUtils.isNotBlank(scr.getPen()) && !searchRequest.getPens().contains(scr.getPen())); + LOGGER.debug("Student Credential Distribution filtered by pen {}: ", searchRequest.getPens()); } } void filterOutDeceasedStudents(List credentialList) { LOGGER.debug("Total size of credential list: {}", credentialList.size()); - List deceasedIDs = restUtils.getDeceasedStudentIDs(credentialList.stream().map(StudentCredentialDistribution::getStudentID).distinct().toList(), restUtils.getAccessToken()); + List deceasedIDs = restUtils.getDeceasedStudentIDs(credentialList.stream().map(StudentCredentialDistribution::getStudentID).distinct().toList()); if (!deceasedIDs.isEmpty()) { LOGGER.debug("Deceased students: {}", deceasedIDs.size()); credentialList.removeIf(cr -> deceasedIDs.contains(cr.getStudentID())); diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitioner.java index 8580c37c..d5c17405 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitioner.java @@ -35,14 +35,14 @@ public Map partition(int gridSize) { // Clean up existing reports before running new one logger.debug("Delete School Reports for Monthly Distribution"); long startTime = System.currentTimeMillis(); - restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_SCHL", restUtils.getAccessToken()); + restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_SCHL"); long endTime = System.currentTimeMillis(); long diff = (endTime - startTime)/1000; logger.debug("Old School Reports deleted in {} sec", diff); startTime = System.currentTimeMillis(); logger.debug("Retrieve students for Monthly Distribution"); - Mono parallelDTOMono = parallelDataFetch.fetchDistributionRequiredData(restUtils.getAccessToken()); + Mono parallelDTOMono = parallelDataFetch.fetchDistributionRequiredData(); DistributionDataParallelDTO parallelDTO = parallelDTOMono.block(); List credentialList = new ArrayList<>(); if(parallelDTO != null) { @@ -62,7 +62,6 @@ public Map partition(int gridSize) { return new HashMap<>(); } - @Override protected JobExecution getJobExecution() { return context; diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerPsiUserReq.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerPsiUserReq.java index 7a79fd2a..750e900b 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerPsiUserReq.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerPsiUserReq.java @@ -33,7 +33,7 @@ public Map partition(int gridSize) { String transmissionType = jobParameters.getString("transmissionType"); PsiCredentialRequest req = (PsiCredentialRequest)jsonTransformer.unmarshall(searchRequest, PsiCredentialRequest.class); String accessToken = restUtils.getAccessToken(); - restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_PSI", accessToken); + restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_PSI"); List credentialList = getRecordsForPSIUserReqDisRun(req,transmissionType,accessToken); if(!credentialList.isEmpty()) { diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerUserReq.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerUserReq.java index d989d458..3688fc77 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerUserReq.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerUserReq.java @@ -1,6 +1,5 @@ package ca.bc.gov.educ.api.batchgraduation.reader; -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.model.StudentSearchRequest; import org.slf4j.Logger; @@ -23,15 +22,10 @@ public class DistributionRunPartitionerUserReq extends BasePartitioner { @Override public Map partition(int gridSize) { - ResponseObj res = restUtils.getTokenResponseObject(); - String accessToken = null; - if (res != null) { - accessToken = res.getAccess_token(); - } JobParameters jobParameters = context.getJobParameters(); String credentialType = jobParameters.getString("credentialType"); StudentSearchRequest req = getStudentSearchRequest(); - List credentialList = restUtils.getStudentsForUserReqDisRun(credentialType,req,accessToken); + List credentialList = restUtils.getStudentsForUserReqDisRun(credentialType,req); if(!credentialList.isEmpty()) { Map map = getStringExecutionContextMap(gridSize, credentialList, credentialType); LOGGER.info("Found {} in total running on {} partitions",credentialList.size(),map.size()); diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunSupplementalPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunSupplementalPartitioner.java index 7d500b41..f4fe9aca 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunSupplementalPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunSupplementalPartitioner.java @@ -1,6 +1,5 @@ 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.StudentCredentialDistribution; import ca.bc.gov.educ.api.batchgraduation.service.ParallelDataFetch; import org.slf4j.Logger; @@ -9,9 +8,10 @@ import org.springframework.batch.item.ExecutionContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import reactor.core.publisher.Mono; -import java.util.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class DistributionRunSupplementalPartitioner extends BasePartitioner { @@ -29,8 +29,8 @@ public Map partition(int gridSize) { logger.debug("Delete School Reports for Supplemental Distribution"); long startTime = System.currentTimeMillis(); // Clean up existing reports before running new one - restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_SCHL", restUtils.getAccessToken()); - restUtils.deleteSchoolReportRecord("", "DISTREP_SC", restUtils.getAccessToken()); + restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_SCHL"); + restUtils.deleteSchoolReportRecord("", "DISTREP_SC"); long endTime = System.currentTimeMillis(); long diff = (endTime - startTime)/1000; logger.debug("Old School Reports deleted in {} sec", diff); diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunYearlyNonGradPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunYearlyNonGradPartitioner.java index b0afd1ec..be4e8f60 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunYearlyNonGradPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunYearlyNonGradPartitioner.java @@ -34,10 +34,10 @@ public Map partition(int gridSize) { // Clean up existing reports before running new one logger.debug("Delete School Reports for Yearly Distribution"); long startTime = System.currentTimeMillis(); - restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_SCHL", restUtils.getAccessToken()); - restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_YE", restUtils.getAccessToken()); - restUtils.deleteSchoolReportRecord("", "NONGRADDISTREP_SC", restUtils.getAccessToken()); - restUtils.deleteSchoolReportRecord("", "NONGRADDISTREP_SD", restUtils.getAccessToken()); + restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_SCHL"); + restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_YE"); + restUtils.deleteSchoolReportRecord("", "NONGRADDISTREP_SC"); + restUtils.deleteSchoolReportRecord("", "NONGRADDISTREP_SD"); long endTime = System.currentTimeMillis(); long diff = (endTime - startTime)/1000; logger.debug("Old School Reports deleted in {} sec", diff); @@ -52,7 +52,7 @@ public Map partition(int gridSize) { if(eligibleStudentSchoolDistricts.isEmpty() ) { logger.debug("No filter found, retrieve all districts"); startTime = System.currentTimeMillis(); - eligibleStudentSchoolDistricts = parallelDataFetch.fetchDistributionRequiredDataDistrictsNonGradYearly(restUtils.getAccessToken()); + eligibleStudentSchoolDistricts = parallelDataFetch.fetchDistributionRequiredDataDistrictsNonGradYearly(); endTime = System.currentTimeMillis(); diff = (endTime - startTime)/1000; logger.debug("All {} districts retrieved in {} sec", eligibleStudentSchoolDistricts.size(), diff); diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunYearlyPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunYearlyPartitioner.java index 4acd136c..523537d6 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunYearlyPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunYearlyPartitioner.java @@ -29,10 +29,10 @@ public Map partition(int gridSize) { // Clean up existing reports before running new one logger.debug("Delete School Reports for Yearly Distribution"); long startTime = System.currentTimeMillis(); - restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_SCHL", restUtils.getAccessToken()); - restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_YE", restUtils.getAccessToken()); - restUtils.deleteSchoolReportRecord("", "DISTREP_YE_SC", restUtils.getAccessToken()); - restUtils.deleteSchoolReportRecord("", "DISTREP_YE_SD", restUtils.getAccessToken()); + restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_SCHL"); + restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_YE"); + restUtils.deleteSchoolReportRecord("", "DISTREP_YE_SC"); + restUtils.deleteSchoolReportRecord("", "DISTREP_YE_SD"); long endTime = System.currentTimeMillis(); long diff = (endTime - startTime)/1000; logger.debug("Old School Reports deleted in {} sec", diff); diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/EDWSnapshotSchoolPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/EDWSnapshotSchoolPartitioner.java index c47e37c0..a2eab877 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/EDWSnapshotSchoolPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/EDWSnapshotSchoolPartitioner.java @@ -1,7 +1,6 @@ package ca.bc.gov.educ.api.batchgraduation.reader; import ca.bc.gov.educ.api.batchgraduation.model.EdwSnapshotSchoolSummaryDTO; -import ca.bc.gov.educ.api.batchgraduation.model.ResponseObj; import ca.bc.gov.educ.api.batchgraduation.model.SnapshotRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,11 +25,6 @@ public class EDWSnapshotSchoolPartitioner extends BasePartitioner { @Override public Map partition(int gridSize) { - ResponseObj res = restUtils.getTokenResponseObject(); - String accessToken = null; - if (res != null) { - accessToken = res.getAccess_token(); - } long startTime = System.currentTimeMillis(); logger.debug("Retrieve schools for EDW Snapshot"); JobParameters jobParameters = context.getJobParameters(); @@ -40,7 +34,7 @@ public Map partition(int gridSize) { if (req.getSchoolOfRecords() != null && !req.getSchoolOfRecords().isEmpty()) { schools = req.getSchoolOfRecords(); } else { - schools = restUtils.getEDWSnapshotSchools(req.getGradYear(), accessToken); + schools = restUtils.getEDWSnapshotSchools(req.getGradYear()); } long endTime = System.currentTimeMillis(); long diff = (endTime - startTime)/1000; diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegGradAlgPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegGradAlgPartitioner.java index fcec33b2..be76349c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegGradAlgPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegGradAlgPartitioner.java @@ -2,7 +2,6 @@ import ca.bc.gov.educ.api.batchgraduation.entity.BatchGradAlgorithmJobHistoryEntity; import ca.bc.gov.educ.api.batchgraduation.model.AlgorithmSummaryDTO; -import ca.bc.gov.educ.api.batchgraduation.model.ResponseObj; import ca.bc.gov.educ.api.batchgraduation.model.RunTypeEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,12 +33,7 @@ public Map partition(int gridSize) { BatchGradAlgorithmJobHistoryEntity jobHistory = createBatchJobHistory(); List studentList; if (runType == RunTypeEnum.NORMAL_JOB_PROCESS) { - ResponseObj res = restUtils.getTokenResponseObject(); - String accessToken = null; - if (res != null) { - accessToken = res.getAccess_token(); - } - studentList = restUtils.getStudentsForAlgorithm(accessToken); + studentList = restUtils.getStudentsForAlgorithm(); } else { studentList = getInputDataFromPreviousJob(); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegenerateCertificatePartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegenerateCertificatePartitioner.java index 34bcf843..a79cf92a 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegenerateCertificatePartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegenerateCertificatePartitioner.java @@ -2,9 +2,7 @@ import ca.bc.gov.educ.api.batchgraduation.model.*; import ca.bc.gov.educ.api.batchgraduation.service.ParallelDataFetch; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.lang3.StringUtils; +import ca.bc.gov.educ.api.batchgraduation.util.JsonTransformer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.core.JobExecution; @@ -29,24 +27,24 @@ public class RegenerateCertificatePartitioner extends BasePartitioner { @Autowired ParallelDataFetch parallelDataFetch; + @Autowired + JsonTransformer jsonTransformer; + @Override public Map partition(int gridSize) { - ResponseObj res = restUtils.getTokenResponseObject(); - String accessToken = null; - if (res != null) { - accessToken = res.getAccess_token(); - } + createBatchJobHistory(); List credentialList = new ArrayList<>(); JobParameters jobParameters = context.getJobParameters(); String searchRequest = jobParameters.getString(SEARCH_REQUEST); - if (StringUtils.isBlank(searchRequest)) { - Mono parallelDTOMono = parallelDataFetch.fetchDistributionRequiredData(accessToken); + CertificateRegenerationRequest certificateRegenerationRequest = (CertificateRegenerationRequest)jsonTransformer.unmarshall(searchRequest, CertificateRegenerationRequest.class); + if (certificateRegenerationRequest == null || certificateRegenerationRequest.runForAll()) { + Mono parallelDTOMono = parallelDataFetch.fetchDistributionRequiredData(); DistributionDataParallelDTO parallelDTO = parallelDTOMono.block(); if(parallelDTO != null) { credentialList.addAll(parallelDTO.certificateList()); } } else { - credentialList.addAll(getStudentsForUserReqRun(searchRequest, accessToken)); + credentialList.addAll(getStudentsForUserReqRun(certificateRegenerationRequest)); } Set studentSet = new HashSet<>(); @@ -82,30 +80,12 @@ public Map partition(int gridSize) { return new HashMap<>(); } - private List getStudentsForDistRun(String accessToken) { - List credentialList = new ArrayList<>(); - Mono parallelDTOMono = parallelDataFetch.fetchDistributionRequiredData(accessToken); - DistributionDataParallelDTO parallelDTO = parallelDTOMono.block(); - if(parallelDTO != null) { - credentialList.addAll(parallelDTO.certificateList()); - } - return credentialList; - } - // retrieve students based on the search criteria requested by user - private List getStudentsForUserReqRun(String searchRequest, String accessToken) { - CertificateRegenerationRequest certRegenReq = null; - try { - certRegenReq = new ObjectMapper().readValue(searchRequest, CertificateRegenerationRequest.class); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - if (certRegenReq != null && "Y".equalsIgnoreCase(certRegenReq.getRunMode())) { - StudentSearchRequest req = new StudentSearchRequest(); - req.setPens(certRegenReq.getPens()); - return restUtils.getStudentsForUserReqDisRun("OC", req, accessToken); + private List getStudentsForUserReqRun(CertificateRegenerationRequest certificateRegenerationRequest) { + if(certificateRegenerationRequest != null && "Y".equalsIgnoreCase(certificateRegenerationRequest.getRunMode())) { + return restUtils.getStudentsForUserReqDisRunWithNullDistributionDate("OC", certificateRegenerationRequest); } else { - return getStudentsForDistRun(accessToken); + return new ArrayList<>(); } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/SpcRegGradAlgPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/SpcRegGradAlgPartitioner.java index 8adadbf4..c3109cfb 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/SpcRegGradAlgPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/SpcRegGradAlgPartitioner.java @@ -2,7 +2,6 @@ import ca.bc.gov.educ.api.batchgraduation.entity.BatchGradAlgorithmJobHistoryEntity; import ca.bc.gov.educ.api.batchgraduation.model.AlgorithmSummaryDTO; -import ca.bc.gov.educ.api.batchgraduation.model.ResponseObj; import ca.bc.gov.educ.api.batchgraduation.model.RunTypeEnum; import ca.bc.gov.educ.api.batchgraduation.model.StudentSearchRequest; import org.slf4j.Logger; @@ -38,15 +37,10 @@ public Map partition(int gridSize) { BatchGradAlgorithmJobHistoryEntity jobHistory = createBatchJobHistory(); List studentList; if (runType == RunTypeEnum.NORMAL_JOB_PROCESS) { - ResponseObj res = restUtils.getTokenResponseObject(); - String accessToken = null; - if (res != null) { - accessToken = res.getAccess_token(); - } JobParameters jobParameters = jobExecution.getJobParameters(); String searchRequest = jobParameters.getString(SEARCH_REQUEST, "{}"); StudentSearchRequest req = (StudentSearchRequest)jsonTransformer.unmarshall(searchRequest, StudentSearchRequest.class); - studentList = restUtils.getStudentsForSpecialGradRun(req, accessToken); + studentList = restUtils.getStudentsForSpecialGradRun(req); } else { studentList = getInputDataFromPreviousJob(); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/TvrRunPartitioner.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/TvrRunPartitioner.java index b76e6f62..5f9d2b5f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/TvrRunPartitioner.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/TvrRunPartitioner.java @@ -2,7 +2,6 @@ import ca.bc.gov.educ.api.batchgraduation.entity.BatchGradAlgorithmJobHistoryEntity; import ca.bc.gov.educ.api.batchgraduation.model.AlgorithmSummaryDTO; -import ca.bc.gov.educ.api.batchgraduation.model.ResponseObj; import ca.bc.gov.educ.api.batchgraduation.model.RunTypeEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,12 +33,7 @@ public Map partition(int gridSize) { BatchGradAlgorithmJobHistoryEntity jobHistory = createBatchJobHistory(); List studentList; if (runType == RunTypeEnum.NORMAL_JOB_PROCESS) { - ResponseObj res = restUtils.getTokenResponseObject(); - String accessToken = null; - if (res != null) { - accessToken = res.getAccess_token(); - } - studentList = restUtils.getStudentsForProjectedAlgorithm(accessToken); + studentList = restUtils.getStudentsForProjectedAlgorithm(); } else { studentList = getInputDataFromPreviousJob(); } 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 ae480f35..605bffb1 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 @@ -7,6 +7,7 @@ import ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiUtils; import ca.bc.gov.educ.api.batchgraduation.util.ThreadLocalStateUtil; import io.github.resilience4j.retry.annotation.Retry; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -254,17 +255,19 @@ public List fetchDistributionRequiredDataStudents } - public Integer runRegenerateStudentCertificate(String pen, String accessToken) { + public Integer runRegenerateStudentCertificate(String pen) { UUID correlationID = UUID.randomUUID(); + String accessToken = getAccessToken(); return this.webClient.get() .uri(String.format(constants.getStudentCertificateRegeneration(), pen), - uri -> uri.queryParam("isOverwrite", "Y").build()) + uri -> uri.queryParam("isOverwrite", "N").build()) .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, correlationID.toString()); }) .retrieve().bodyToMono(Integer.class).block(); } - public List getStudentsForAlgorithm(String accessToken) { + public List getStudentsForAlgorithm() { UUID correlationID = UUID.randomUUID(); + String accessToken = getAccessToken(); final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { }; return this.webClient.get() @@ -273,8 +276,9 @@ public List getStudentsForAlgorithm(String accessToken) { .retrieve().bodyToMono(responseType).block(); } - public List getStudentsForProjectedAlgorithm(String accessToken) { + public List getStudentsForProjectedAlgorithm() { UUID correlationID = UUID.randomUUID(); + String accessToken = getAccessToken(); final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { }; return this.webClient.get() @@ -294,8 +298,9 @@ public GraduationStudentRecord saveGraduationStudentRecord(GraduationStudentReco .retrieve().bodyToMono(GraduationStudentRecord.class).block(); } - public List getStudentsForSpecialGradRun(StudentSearchRequest req,String accessToken) { + public List getStudentsForSpecialGradRun(StudentSearchRequest req) { UUID correlationID = UUID.randomUUID(); + String accessToken = getAccessToken(); GraduationStudentRecordSearchResult res = this.webClient.post() .uri(constants.getGradStudentApiStudentForSpcGradListUrl()) .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, correlationID.toString()); }) @@ -377,19 +382,20 @@ public Integer getStudentByPenFromStudentAPI(List loadStudentDa gradStu.setRecalculateGradStatus("Y"); gradStu.setStudentStatus(student.getStudentStatus()); gradStu.setStudentID(UUID.fromString(st.getStudentID())); - this.saveGraduationStudentRecord(gradStu, accessToken); + saveGraduationStudentRecord(gradStu, accessToken); recordsAdded.getAndSet(recordsAdded.get() + 1); }); }); return recordsAdded.get(); } - public List getStudentData(List studentIds, String accessToken) { + public List getStudentData(List studentIds) { UUID correlationID = UUID.randomUUID(); final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { }; StudentList stuList = new StudentList(); stuList.setStudentids(studentIds); + String accessToken = getAccessToken(); return this.webClient.post() .uri(constants.getGradStudentApiStudentDataListUrl()) .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, correlationID.toString()); }) @@ -397,26 +403,32 @@ public List getStudentData(List studentIds, Strin .retrieve().bodyToMono(responseType).block(); } - public StudentCredentialDistribution processDistribution(StudentCredentialDistribution item, DistributionSummaryDTO summary) { + public StudentCredentialDistribution processDistribution(StudentCredentialDistribution item, DistributionSummaryDTO summary, boolean useSchoolAtGrad) { LOGGER.info(STUDENT_PROCESS,item.getStudentID()); summary.setProcessedCount(summary.getProcessedCount() + 1L); - String accessToken = summary.getAccessToken(); - StudentCredentialDistribution scObj = summary.getGlobalList().stream().filter(pr -> pr.getStudentID().compareTo(item.getStudentID()) == 0) .findAny() .orElse(null); if(scObj != null) { - item.setSchoolOfRecord(scObj.getSchoolOfRecord()); + if(useSchoolAtGrad) { + item.setSchoolOfRecord(StringUtils.isBlank(scObj.getSchoolAtGrad()) ? scObj.getSchoolOfRecord() : scObj.getSchoolAtGrad()); + } else { + item.setSchoolOfRecord(scObj.getSchoolOfRecord()); + } item.setPen(scObj.getPen()); item.setLegalLastName(scObj.getLegalLastName()); item.setLegalFirstName(scObj.getLegalFirstName()); item.setLegalMiddleNames(scObj.getLegalMiddleNames()); } else { - GraduationStudentRecordDistribution stuRec =this.getStudentData(item.getStudentID().toString(),accessToken); + GraduationStudentRecordDistribution stuRec = getStudentData(item.getStudentID().toString()); if (stuRec != null) { item.setProgram(stuRec.getProgram()); item.setHonoursStanding(stuRec.getHonoursStanding()); - item.setSchoolOfRecord(stuRec.getSchoolOfRecord()); + if(useSchoolAtGrad) { + item.setSchoolOfRecord(StringUtils.isBlank(stuRec.getSchoolAtGrad()) ? stuRec.getSchoolOfRecord() : stuRec.getSchoolAtGrad()); + } else { + item.setSchoolOfRecord(stuRec.getSchoolOfRecord()); + } item.setProgramCompletionDate(stuRec.getProgramCompletionDate()); item.setStudentID(stuRec.getStudentID()); item.setPen(stuRec.getPen()); @@ -496,8 +508,9 @@ public GraduationStudentRecord getStudentDataForBatch(String studentID, String a return result; } - public GraduationStudentRecordDistribution getStudentData(String studentID, String accessToken) { + public GraduationStudentRecordDistribution getStudentData(String studentID) { UUID correlationID = UUID.randomUUID(); + String accessToken = getAccessToken(); GraduationStudentRecordDistribution result = webClient.get() .uri(String.format(constants.getStudentInfo(),studentID)) .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, correlationID.toString()); }) @@ -624,15 +637,17 @@ public void updateSchoolReportRecord(String schoolOfRecord, String reportTypeCod .retrieve().bodyToMono(boolean.class).block(); } - public void deleteSchoolReportRecord(String schoolOfRecord, String reportTypeCode, String accessToken) { + public void deleteSchoolReportRecord(String schoolOfRecord, String reportTypeCode) { UUID correlationID = UUID.randomUUID(); + String accessToken = getAccessToken(); webClient.delete().uri(String.format(constants.getUpdateSchoolReport(),schoolOfRecord,reportTypeCode)) .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, correlationID.toString()); }) .retrieve().bodyToMono(boolean.class).block(); } - public List getStudentsForUserReqDisRun(String credentialType, StudentSearchRequest req, String accessToken) { + public List getStudentsForUserReqDisRun(String credentialType, StudentSearchRequest req) { UUID correlationID = UUID.randomUUID(); + String accessToken = getAccessToken(); final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { }; return this.webClient.post() @@ -644,10 +659,25 @@ public List getStudentsForUserReqDisRun(String cr .block(); } - public void updateStudentGradRecord(UUID studentID, Long batchId,String activityCode, String accessToken) { + public List getStudentsForUserReqDisRunWithNullDistributionDate(String credentialType, StudentSearchRequest req) { + UUID correlationID = UUID.randomUUID(); + String accessToken = getAccessToken(); + final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { + }; + return this.webClient.post() + .uri(String.format(constants.getStudentDataForUserReqDisRunWithNullDistributionDate(),credentialType)) + .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, correlationID.toString()); }) + .body(BodyInserters.fromValue(req)) + .retrieve() + .bodyToMono(responseType) + .block(); + } + + public void updateStudentGradRecord(UUID studentID, Long batchId,String activityCode) { //Grad2-1931 not updating the school record if student id does not exist. try { if (studentID != null) { + String accessToken = getAccessToken(); String url = String.format(constants.getUpdateStudentRecord(), studentID, batchId, activityCode); this.post(url, "{}", GraduationStudentRecord.class, accessToken); } @@ -688,7 +718,8 @@ public Boolean checkSccpCertificateExists (UUID studentID, String accessToken) { .retrieve().bodyToMono(Boolean.class).block(); } - public List getEDWSnapshotSchools(Integer gradYear, String accessToken) { + public List getEDWSnapshotSchools(Integer gradYear) { + String accessToken = getAccessToken(); final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { }; String url = String.format(constants.getEdwSnapshotSchoolsUrl(), gradYear); @@ -699,7 +730,8 @@ public List getEDWSnapshotSchools(Integer gradYear, String accessToken) .retrieve().bodyToMono(responseType).block(); } - public List getEDWSnapshotStudents(Integer gradYear, String mincode, String accessToken) { + public List getEDWSnapshotStudents(Integer gradYear, String mincode) { + String accessToken = getAccessToken(); final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { }; String url = String.format(constants.getEdwSnapshotStudentsByMincodeUrl(), gradYear, mincode); @@ -777,8 +809,9 @@ public TraxSchool getTraxSchool(String mincode) { return get(String.format(constants.getTraxSchoolByMincode(), mincode), TraxSchool.class, getAccessToken()); } - public List getDeceasedStudentIDs(List studentIDs, String accessToken) { + public List getDeceasedStudentIDs(List studentIDs) { UUID correlationID = UUID.randomUUID(); + String accessToken = getAccessToken(); final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { }; return this.webClient.post() diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/DistributionService.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/DistributionService.java index 16634af9..f5d8660e 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/DistributionService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/DistributionService.java @@ -75,12 +75,14 @@ public void saveStudentCredentialDistribution(Long batchId, String jobType, Stud public void updateDistributionBatchJobStatus(Long batchId, int failedCount, String status) { log.debug("updateDistributionBatchJobStatus - retrieve the batch job history: batchId = {}", batchId); BatchGradAlgorithmJobHistoryEntity jobHistory = gradBatchHistoryService.getGradAlgorithmJobHistory(batchId); - jobHistory.setEndTime(LocalDateTime.now()); - jobHistory.setStatus(status); - jobHistory.setActualStudentsProcessed(jobHistory.getExpectedStudentsProcessed() - failedCount); - log.debug("updateDistributionBatchJobStatus - save the batch job history: batchId = {}, status = {}. actual processed count = {}", batchId, status, jobHistory.getActualStudentsProcessed()); - gradBatchHistoryService.saveGradAlgorithmJobHistory(jobHistory); - log.debug("updateDistributionBatchJobStatus - save the batch job history is completed!"); + if(jobHistory != null) { + jobHistory.setEndTime(LocalDateTime.now()); + jobHistory.setStatus(status); + jobHistory.setActualStudentsProcessed(jobHistory.getExpectedStudentsProcessed() - failedCount); + log.debug("updateDistributionBatchJobStatus - save the batch job history: batchId = {}, status = {}. actual processed count = {}", batchId, status, jobHistory.getActualStudentsProcessed()); + gradBatchHistoryService.saveGradAlgorithmJobHistory(jobHistory); + log.debug("updateDistributionBatchJobStatus - save the batch job history is completed!"); + } } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/GradDashboardService.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/GradDashboardService.java index 3aaacb28..c3f8d195 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/GradDashboardService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/GradDashboardService.java @@ -89,7 +89,7 @@ public ErrorDashBoard getErrorInfo(Long batchId, Integer pageNumber, Integer pag List studentIds = list.stream().map(BatchGradAlgorithmStudentEntity::getStudentID).toList(); List eList = new ArrayList<>(); if(!studentIds.isEmpty()) { - List studentList = restUtils.getStudentData(studentIds, accessToken); + List studentList = restUtils.getStudentData(studentIds); for (GraduationStudentRecord gRec : studentList) { ErrorBoard eD = new ErrorBoard(); diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/GraduationReportService.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/GraduationReportService.java index c1e80391..0c432552 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/GraduationReportService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/GraduationReportService.java @@ -5,6 +5,8 @@ import ca.bc.gov.educ.api.batchgraduation.model.StudentCredentialDistribution; import ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.ParameterizedTypeReference; import org.springframework.stereotype.Service; @@ -18,6 +20,8 @@ @Service public class GraduationReportService { + private static final Logger LOGGER = LoggerFactory.getLogger(GraduationReportService.class); + @Autowired WebClient webClient; @@ -98,7 +102,9 @@ private StudentCredentialDistribution populateStudentCredentialDistribution(Repo } dist.setStudentID(data.getGraduationStudentRecordId()); dist.setPaperType(paperType); - dist.setSchoolOfRecord(data.getMincode()); + dist.setSchoolOfRecord(StringUtils.isBlank(data.getMincodeAtGrad()) ? data.getMincode() : data.getMincodeAtGrad()); + dist.setSchoolAtGrad(data.getMincodeAtGrad()); + dist.setSchoolOfRecordOrigin(data.getMincode()); dist.setDocumentStatusCode("COMPL"); dist.setPen(data.getPen()); dist.setLegalFirstName(data.getFirstName()); @@ -110,6 +116,7 @@ private StudentCredentialDistribution populateStudentCredentialDistribution(Repo dist.setStudentGrade(data.getStudentGrade()); dist.setNonGradReasons(data.getNonGradReasons()); dist.setLastUpdateDate(data.lastUpdateDateAsString()); + LOGGER.info("Populate Student Credential Distribution for pen {}: SchoolOfRecordOrigin->{}, SchoolAtGrad->{}, SchoolOfRecord->{}", dist.getPen(), dist.getSchoolOfRecordOrigin(), dist.getSchoolAtGrad(), dist.getSchoolOfRecord()); return dist; } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/ParallelDataFetch.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/ParallelDataFetch.java index 7f067852..2fb93575 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/ParallelDataFetch.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/ParallelDataFetch.java @@ -19,15 +19,19 @@ public class ParallelDataFetch { RestUtils restUtils; // Monthly distribution - public Mono fetchDistributionRequiredData(String accessToken) { + public Mono fetchDistributionRequiredData() { + String accessToken = restUtils.getAccessToken(); Mono> transcriptList = graduationReportService.getTranscriptList(accessToken); + accessToken = restUtils.getAccessToken(); Mono> certificateList = graduationReportService.getCertificateList(accessToken); return Mono.zip(transcriptList,certificateList).map(tuple -> new DistributionDataParallelDTO(tuple.getT1(),tuple.getT2())); } // Supplemental distribution - public Mono fetchDistributionRequiredDataYearly(String accessToken) { + public Mono fetchDistributionRequiredDataYearly() { + String accessToken = restUtils.getAccessToken(); Mono> transcriptList = graduationReportService.getTranscriptListYearly(accessToken); + accessToken = restUtils.getAccessToken(); Mono> certificateList = graduationReportService.getCertificateList(accessToken); return Mono.zip(transcriptList,certificateList).map(tuple -> new DistributionDataParallelDTO(tuple.getT1(),tuple.getT2())); } @@ -41,11 +45,13 @@ public List fetchStudentCredentialsDistributionDa return restUtils.fetchDistributionRequiredDataStudentsNonGradYearly(); } - public List fetchDistributionRequiredDataSchoolsNonGradYearly(String accessToken) { + public List fetchDistributionRequiredDataSchoolsNonGradYearly() { + String accessToken = restUtils.getAccessToken(); return graduationReportService.getSchoolsNonGradYearly(accessToken); } - public List fetchDistributionRequiredDataDistrictsNonGradYearly(String accessToken) { + public List fetchDistributionRequiredDataDistrictsNonGradYearly() { + String accessToken = restUtils.getAccessToken(); return graduationReportService.getDistrictsNonGradYearly(accessToken); } 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 cde6a5cb..152b6959 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 @@ -213,6 +213,9 @@ public class EducGradBatchGraduationApiConstants { @Value("${endpoint.grad-graduation-report-api.user-req-dis-run.url}") private String studentDataForUserReqDisRun; + @Value("${endpoint.grad-graduation-report-api.user-req-dis-run-for-not-yet-distributed.url}") + private String studentDataForUserReqDisRunWithNullDistributionDate; + @Value("${endpoint.grad-graduation-api.schoolreport.url}") private String createAndStoreSchoolReports; diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index f4a20368..4136a68f 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -224,6 +224,8 @@ endpoint: url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/studentcredential?studentID=%s&credentialTypeCode=%s&paperType=%s&documentStatusCode=%s&activityCode=%s user-req-dis-run: url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/userrequest/%s + user-req-dis-run-for-not-yet-distributed: + url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/userrequest/notyetdistributed/%s get-district-data-yearly: url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/districtdataearly get-certificate-types: diff --git a/api/src/main/resources/db/migration/1.0/V1.0.46__DDL-ALTER_TABLES-for-institution-api.sql b/api/src/main/resources/db/migration/1.0/V1.0.46__DDL-ALTER_TABLES-for-institution-api.sql new file mode 100644 index 00000000..fd10c9fa --- /dev/null +++ b/api/src/main/resources/db/migration/1.0/V1.0.46__DDL-ALTER_TABLES-for-institution-api.sql @@ -0,0 +1,6 @@ +ALTER TABLE BATCH_GRAD_ALG_STUDENT ADD SCHOOL_OF_RECORD_ID RAW(16); +ALTER TABLE STUDENT_CREDENTIAL_DISTRIBUTION ADD SCHOOL_OF_RECORD_ID RAW(16); + + + + diff --git a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/listener/DistributionRunCompletionNotificationListenerTest.java b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/listener/DistributionRunCompletionNotificationListenerTest.java index debc564f..047462e4 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/listener/DistributionRunCompletionNotificationListenerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/listener/DistributionRunCompletionNotificationListenerTest.java @@ -208,8 +208,8 @@ public void testAfterJob() throws JobInstanceAlreadyCompleteException, JobExecut Mockito.when(restUtils.getTokenResponseObject()).thenReturn(obj); Mockito.when(graduationReportService.getTranscriptList(null)).thenReturn(Mono.just(tList)); Mockito.when(graduationReportService.getCertificateList(null)).thenReturn(Mono.just(cList)); - Mockito.when(parallelDataFetch.fetchDistributionRequiredData(summaryDTO.getAccessToken())).thenReturn(Mono.just(dp)); - Mockito.when(parallelDataFetch.fetchDistributionRequiredDataYearly(summaryDTO.getAccessToken())).thenReturn(Mono.just(dp)); + Mockito.when(parallelDataFetch.fetchDistributionRequiredData()).thenReturn(Mono.just(dp)); + Mockito.when(parallelDataFetch.fetchDistributionRequiredDataYearly()).thenReturn(Mono.just(dp)); Mockito.when(restUtils.mergeAndUpload(121L, distributionRequest,"YEARENDDIST",null)).thenReturn(new DistributionResponse()); distributionRunCompletionNotificationListener.afterJob(jobExecution); diff --git a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqDistributionRunCompletionNotificationListenerTest.java b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqDistributionRunCompletionNotificationListenerTest.java index 22c88d1d..87a70033 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqDistributionRunCompletionNotificationListenerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqDistributionRunCompletionNotificationListenerTest.java @@ -194,7 +194,7 @@ public void testAfterJob() throws JobInstanceAlreadyCompleteException, JobExecut Mockito.when(restUtils.getTokenResponseObject()).thenReturn(obj); Mockito.when(graduationReportService.getTranscriptList(null)).thenReturn(Mono.just(tList)); Mockito.when(graduationReportService.getCertificateList(null)).thenReturn(Mono.just(cList)); - Mockito.when(parallelDataFetch.fetchDistributionRequiredData(summaryDTO.getAccessToken())).thenReturn(Mono.just(dp)); + Mockito.when(parallelDataFetch.fetchDistributionRequiredData()).thenReturn(Mono.just(dp)); userReqDistributionRunCompletionNotificationListener.afterJob(jobExecution); assertThat(ent.getActualStudentsProcessed()).isEqualTo(10); @@ -329,8 +329,8 @@ public void testAfterJob_OC() throws JobInstanceAlreadyCompleteException, JobExe Mockito.when(restUtils.getTokenResponseObject()).thenReturn(obj); Mockito.when(graduationReportService.getTranscriptList(null)).thenReturn(Mono.just(tList)); Mockito.when(graduationReportService.getCertificateList(null)).thenReturn(Mono.just(cList)); - Mockito.when(parallelDataFetch.fetchDistributionRequiredData(summaryDTO.getAccessToken())).thenReturn(Mono.just(dp)); - Mockito.when(parallelDataFetch.fetchDistributionRequiredDataYearly(summaryDTO.getAccessToken())).thenReturn(Mono.just(dp)); + Mockito.when(parallelDataFetch.fetchDistributionRequiredData()).thenReturn(Mono.just(dp)); + Mockito.when(parallelDataFetch.fetchDistributionRequiredDataYearly()).thenReturn(Mono.just(dp)); userReqDistributionRunCompletionNotificationListener.afterJob(jobExecution); assertThat(ent.getActualStudentsProcessed()).isEqualTo(10); diff --git a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/service/GradDashboardServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/service/GradDashboardServiceTest.java index 00963e97..04375dc9 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/service/GradDashboardServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/service/GradDashboardServiceTest.java @@ -201,7 +201,7 @@ public void testGetErrorInfo() { rec.setPen("673213121"); Mockito.when(batchGradAlgorithmStudentRepository.findByJobExecutionIdAndStatusIn(batchId,Arrays.asList("STARTED", "FAILED"), paging)).thenReturn(pagedData); - Mockito.when(restUtils.getStudentData(List.of(studentId), "accessToken")).thenReturn(List.of(rec)); + Mockito.when(restUtils.getStudentData(List.of(studentId))).thenReturn(List.of(rec)); Mockito.when(batchGradAlgorithmStudentRepository.findByStudentIDAndJobExecutionId(rec.getStudentID(),batchId)).thenReturn(Optional.of(ent)); ErrorDashBoard res = gradDashboardService.getErrorInfo(batchId,0,10,"accessToken"); diff --git a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/service/ParallelDataFetchTest.java b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/service/ParallelDataFetchTest.java index 53c6d52a..d2d36b9a 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/service/ParallelDataFetchTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/service/ParallelDataFetchTest.java @@ -92,7 +92,7 @@ public void testFetchDistributionRequiredDataSchoolsNonGradYearly() { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(new ParameterizedTypeReference>(){})).thenReturn(Mono.just(List.of("1234567"))); - List result = parallelDataFetch.fetchDistributionRequiredDataSchoolsNonGradYearly("accessToken"); + List result = parallelDataFetch.fetchDistributionRequiredDataSchoolsNonGradYearly(); assertThat(result).isNotEmpty(); } @@ -108,7 +108,7 @@ public void testFetchDistributionRequiredDataDistrictsNonGradYearly() { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(new ParameterizedTypeReference>(){})).thenReturn(Mono.just(List.of("123"))); - List result = parallelDataFetch.fetchDistributionRequiredDataDistrictsNonGradYearly("accessToken"); + List result = parallelDataFetch.fetchDistributionRequiredDataDistrictsNonGradYearly(); assertThat(result).isNotEmpty(); } 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 bfc8b39a..393aa392 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 @@ -174,6 +174,7 @@ public void testGetStudentsForSpecialGradRun_with_APICallSuccess() { GraduationStudentRecordSearchResult res = new GraduationStudentRecordSearchResult(); res.setStudentIDs(Arrays.asList(graduationStatus.getStudentID())); + mockTokenResponseObject(); when(this.webClient.post()).thenReturn(this.requestBodyUriMock); when(this.requestBodyUriMock.uri(String.format(constants.getGradStudentApiStudentForSpcGradListUrl(), studentID))).thenReturn(this.requestBodyUriMock); @@ -184,7 +185,7 @@ public void testGetStudentsForSpecialGradRun_with_APICallSuccess() { when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); - var result = this.restUtils.getStudentsForSpecialGradRun(req, "123"); + var result = this.restUtils.getStudentsForSpecialGradRun(req); assertThat(result).isNotNull(); assertThat(result.get(0)).isEqualTo(studentID); } @@ -204,6 +205,7 @@ public void testGetStudentsForSpecialGradRun_with_APICallSuccess_null() { GraduationStudentRecordSearchResult res = new GraduationStudentRecordSearchResult(); res.setStudentIDs(Arrays.asList(graduationStatus.getStudentID())); + mockTokenResponseObject(); when(this.webClient.post()).thenReturn(this.requestBodyUriMock); when(this.requestBodyUriMock.uri(String.format(constants.getGradStudentApiStudentForSpcGradListUrl(), studentID))).thenReturn(this.requestBodyUriMock); @@ -214,7 +216,7 @@ public void testGetStudentsForSpecialGradRun_with_APICallSuccess_null() { when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(inputResponseSR); when(this.inputResponseSR.block()).thenReturn(null); - var result = this.restUtils.getStudentsForSpecialGradRun(req, "123"); + var result = this.restUtils.getStudentsForSpecialGradRun(req); assertThat(result).isNotNull().isEmpty(); } @@ -376,6 +378,8 @@ public void testProcessProjectedStudent_witherrors2() { AlgorithmSummaryDTO summary = new AlgorithmSummaryDTO(); summary.setBatchId(batchId); + mockTokenResponseObject(); + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); when(this.requestHeadersUriMock.uri(String.format(constants.getGraduationApiProjectedGradUrl(), studentID,batchId))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); @@ -398,6 +402,8 @@ public void testGetStudentData_withlist() { graduationStatus.setStudentID(studentID); graduationStatus.setPen(pen); + mockTokenResponseObject(); + final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { }; @@ -409,7 +415,7 @@ public void testGetStudentData_withlist() { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(Arrays.asList(graduationStatus))); - List resList = this.restUtils.getStudentData(studentList,"abc"); + List resList = this.restUtils.getStudentData(studentList); assertNotNull(resList); assertThat(resList).hasSize(1); } @@ -438,7 +444,7 @@ public void testProcessDistribution() { summary.setBatchId(batchId); summary.setGlobalList(globalList); - StudentCredentialDistribution res = this.restUtils.processDistribution(scd,summary); + StudentCredentialDistribution res = this.restUtils.processDistribution(scd,summary, false); assertNotNull(res); } @@ -473,6 +479,8 @@ public void testProcessDistribution_elsecase() { grd.setStudentGrade("12"); grd.setSchoolOfRecord("454445444"); + mockTokenResponseObject(); + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); when(this.requestHeadersUriMock.uri(String.format(constants.getStudentInfo(),studentID2))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); @@ -483,7 +491,7 @@ public void testProcessDistribution_elsecase() { summary.setBatchId(batchId); summary.setGlobalList(globalList); - StudentCredentialDistribution res = this.restUtils.processDistribution(scd2,summary); + StudentCredentialDistribution res = this.restUtils.processDistribution(scd2,summary, false); assertNotNull(res); } @@ -511,6 +519,7 @@ public void testProcessDistribution_elsecase_null() { scd2.setSchoolOfRecord(mincode); scd2.setStudentID(studentID2); + mockTokenResponseObject(); GraduationStudentRecordDistribution grd = new GraduationStudentRecordDistribution(); grd.setStudentID(studentID2); @@ -529,7 +538,7 @@ public void testProcessDistribution_elsecase_null() { summary.setBatchId(batchId); summary.setGlobalList(globalList); - StudentCredentialDistribution res = this.restUtils.processDistribution(scd2,summary); + StudentCredentialDistribution res = this.restUtils.processDistribution(scd2,summary, false); assertNotNull(res); } @@ -942,6 +951,8 @@ public void testGetStudentsForAlgorithm() { grd.setStudentID(new UUID(1,1)); grd.setProgram("2018-EN"); + mockTokenResponseObject(); + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); when(this.requestHeadersUriMock.uri(constants.getGradStudentApiStudentForGradListUrl())).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); @@ -951,7 +962,7 @@ public void testGetStudentsForAlgorithm() { }; when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(Arrays.asList(grd.getStudentID()))); - val result = this.restUtils.getStudentsForAlgorithm("abc"); + val result = this.restUtils.getStudentsForAlgorithm(); assertThat(result).isNotNull(); assertThat(result.size() > 0).isTrue(); } @@ -963,6 +974,8 @@ public void testGetStudentsForProjectedAlgorithm() { grd.setStudentID(new UUID(1,1)); grd.setProgram("2018-EN"); + mockTokenResponseObject(); + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); when(this.requestHeadersUriMock.uri(constants.getGradStudentApiStudentForProjectedGradListUrl())).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); @@ -972,7 +985,7 @@ public void testGetStudentsForProjectedAlgorithm() { }; when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(Arrays.asList(grd.getStudentID()))); - val result = this.restUtils.getStudentsForProjectedAlgorithm("abc"); + val result = this.restUtils.getStudentsForProjectedAlgorithm(); assertThat(result).isNotNull(); assertThat(result.size() > 0).isTrue(); } @@ -1074,6 +1087,8 @@ public void testGetStudentsForUserReqDisRun() { scd.setId(new UUID(1,1)); scdList.add(scd); + mockTokenResponseObject(); + final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { }; @@ -1085,7 +1100,7 @@ public void testGetStudentsForUserReqDisRun() { when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(scdList)); - val result = this.restUtils.getStudentsForUserReqDisRun(credentialType,req,null); + val result = this.restUtils.getStudentsForUserReqDisRun(credentialType,req); assertThat(result).isNotNull(); assertThat(result.size() > 0).isTrue(); } @@ -1244,13 +1259,15 @@ public void testGetStudentData() { grd.setStudentID(studentID); grd.setProgram("2018-EN"); + mockTokenResponseObject(); + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); when(this.requestHeadersUriMock.uri(String.format(constants.getStudentInfo(),studentID))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(GraduationStudentRecordDistribution.class)).thenReturn(Mono.just(grd)); - GraduationStudentRecordDistribution res = this.restUtils.getStudentData(studentID.toString(),null); + GraduationStudentRecordDistribution res = this.restUtils.getStudentData(studentID.toString()); assertThat(res).isNotNull(); } @@ -1330,6 +1347,8 @@ public void testupdateStudentGradRecord() { final String activityCode = "USERDISOC"; final Long batchId = 4567L; + mockTokenResponseObject(); + GraduationStudentRecord rec = new GraduationStudentRecord(); rec.setStudentID(studentID); when(this.webClient.post()).thenReturn(this.requestBodyUriMock); @@ -1341,7 +1360,7 @@ public void testupdateStudentGradRecord() { when(this.responseMock.onStatus(any(), any())).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(GraduationStudentRecord.class)).thenReturn(Mono.just(rec)); - this.restUtils.updateStudentGradRecord(studentID,batchId,activityCode,"acb"); + this.restUtils.updateStudentGradRecord(studentID,batchId,activityCode); assertNotNull(rec); } @@ -1380,6 +1399,8 @@ public void testUpdateSchoolReportRecord() { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(boolean.class)).thenReturn(Mono.just(true)); + mockTokenResponseObject(); + restUtils.updateSchoolReportRecord(mincode,reportTypeCode,null); assertThat(reportTypeCode).isEqualTo("E"); @@ -1389,7 +1410,7 @@ public void testUpdateSchoolReportRecord() { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(boolean.class)).thenReturn(Mono.just(true)); - restUtils.deleteSchoolReportRecord(mincode,reportTypeCode,null); + restUtils.deleteSchoolReportRecord(mincode,reportTypeCode); assertThat(reportTypeCode).isEqualTo("E"); } @@ -1398,13 +1419,15 @@ public void testDeleteSchoolReportRecord() { final String mincode = "123213123"; String reportTypeCode = "E"; + mockTokenResponseObject(); + when(this.webClient.delete()).thenReturn(this.requestHeadersUriMock); when(this.requestHeadersUriMock.uri(String.format(constants.getUpdateSchoolReport(),mincode,reportTypeCode))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(boolean.class)).thenReturn(Mono.just(true)); - this.restUtils.deleteSchoolReportRecord(mincode,reportTypeCode,null); + this.restUtils.deleteSchoolReportRecord(mincode,reportTypeCode); assertThat(reportTypeCode).isEqualTo("E"); } @@ -1435,6 +1458,7 @@ public void testGetStudentByPenFromStudentAPI() { }; when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(Arrays.asList(student))); + mockTokenResponseObject(); GraduationStudentRecord graduationStatus = new GraduationStudentRecord(); graduationStatus.setStudentID(studentID); @@ -1449,7 +1473,7 @@ public void testGetStudentByPenFromStudentAPI() { when(this.responseMock.bodyToMono(GraduationStudentRecord.class)).thenReturn(Mono.just(graduationStatus)); - Integer res = this.restUtils.getStudentByPenFromStudentAPI(loadStudentData,"abc"); + Integer res = this.restUtils.getStudentByPenFromStudentAPI(loadStudentData, "accessToken"); assertThat(res).isEqualTo(1); } @@ -1524,6 +1548,8 @@ public void testIsReportOnly_when_programCompletionDate_isNotInFuture_and_SCCPce public void testRunRegenerateStudentCertificates() { final String pen = "123456789"; + mockTokenResponseObject(); + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); when(this.requestHeadersUriMock.uri(eq(String.format(constants.getStudentCertificateRegeneration(), pen)), any(Function.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); @@ -1531,7 +1557,7 @@ public void testRunRegenerateStudentCertificates() { when(this.responseMock.bodyToMono(Integer.class)).thenReturn(Mono.just(Integer.valueOf(1))); - val result = this.restUtils.runRegenerateStudentCertificate(pen, "abc"); + val result = this.restUtils.runRegenerateStudentCertificate(pen); assertThat(result).isEqualTo(1); } @@ -1590,6 +1616,8 @@ public void testGetEDWSnapshotSchools() { List schools = Arrays.asList("12345678","11223344"); + mockTokenResponseObject(); + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); when(this.requestHeadersUriMock.uri(String.format(constants.getEdwSnapshotSchoolsUrl(), gradYear))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); @@ -1599,7 +1627,7 @@ public void testGetEDWSnapshotSchools() { }; when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(schools)); - val result = this.restUtils.getEDWSnapshotSchools(gradYear, "abc"); + val result = this.restUtils.getEDWSnapshotSchools(gradYear); assertThat(result).hasSize(2); } @@ -1615,6 +1643,8 @@ public void testGetEDWSnapshotStudents() { snapshotResponse.setGpa(BigDecimal.valueOf(3.75)); snapshotResponse.setHonourFlag("N"); + mockTokenResponseObject(); + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); when(this.requestHeadersUriMock.uri(String.format(constants.getEdwSnapshotStudentsByMincodeUrl(), gradYear, mincode))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); @@ -1624,7 +1654,7 @@ public void testGetEDWSnapshotStudents() { }; when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(Arrays.asList(snapshotResponse))); - val result = this.restUtils.getEDWSnapshotStudents(gradYear, mincode, "abc"); + val result = this.restUtils.getEDWSnapshotStudents(gradYear, mincode); assertThat(result).hasSize(1); } @@ -1661,6 +1691,8 @@ public void testGetDeceasedStudentIDs() { List studentIDs = Arrays.asList(studentID1, studentID2); + mockTokenResponseObject(); + when(this.webClient.post()).thenReturn(this.requestBodyUriMock); when(this.requestBodyUriMock.uri(constants.getDeceasedStudentIDList())).thenReturn(this.requestBodyUriMock); when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); @@ -1671,7 +1703,7 @@ public void testGetDeceasedStudentIDs() { }; when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(studentIDs)); - val result = this.restUtils.getDeceasedStudentIDs(studentIDs, "abc"); + val result = this.restUtils.getDeceasedStudentIDs(studentIDs); assertThat(result).hasSize(2); } diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index add51811..4dbad8a7 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -154,6 +154,8 @@ endpoint: url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/studentcredential?studentID=%s&credentialTypeCode=%s&paperType=%s&documentStatusCode=%s&activityCode=%s user-req-dis-run: url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/userrequest/%s + user-req-dis-run-for-not-yet-distributed: + url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/userrequest/notyetdistributed/%s get-district-data-yearly: url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/districtdataearly get-certificate-types: