From 528d32b52aac3ac5054b1b4425137bdf825acf32 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 16 Apr 2024 14:37:45 -0600 Subject: [PATCH 1/7] GRAD2-2377 HD-22859 (GRAD) YE Distribution run should direct Certificates to School at Graduation, not School of Record --- api/pom.xml | 5 ++ .../graduation/config/GradCommonConfig.java | 7 +- .../model/dto/ResponseObjCache.java | 42 ++++++++++ .../graduation/service/GraduationService.java | 4 +- .../api/graduation/service/ReportService.java | 4 +- .../service/SchoolReportsService.java | 39 ++++++---- .../api/graduation/service/SchoolService.java | 15 +++- .../educ/api/graduation/util/TokenUtils.java | 30 ++++++-- .../service/GraduationServiceTest.java | 6 +- .../service/SchooReportsServiceTest.java | 32 +++++++- .../graduation/service/SchoolServiceTest.java | 45 +++++++++-- .../graduation/service/TokenUtilsTest.java | 76 +++++++++++++++++++ 12 files changed, 261 insertions(+), 44 deletions(-) create mode 100644 api/src/main/java/ca/bc/gov/educ/api/graduation/model/dto/ResponseObjCache.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/graduation/service/TokenUtilsTest.java diff --git a/api/pom.xml b/api/pom.xml index de681f2b..de732c9d 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -213,6 +213,11 @@ pdfbox 2.0.26 + + org.json + json + 20220320 + diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/config/GradCommonConfig.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/config/GradCommonConfig.java index 9e222f6f..ca2de734 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/config/GradCommonConfig.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/config/GradCommonConfig.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.graduation.config; +import ca.bc.gov.educ.api.graduation.model.dto.ResponseObjCache; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -7,8 +8,6 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import ca.bc.gov.educ.api.graduation.util.MessageHelper; - @Configuration @PropertySource("classpath:messages.properties") public class GradCommonConfig implements WebMvcConfigurer { @@ -26,4 +25,8 @@ public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(requestInterceptor).addPathPatterns("/**"); } + @Bean + public ResponseObjCache createResponseObjCache() { + return new ResponseObjCache(30); + } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/model/dto/ResponseObjCache.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/model/dto/ResponseObjCache.java new file mode 100644 index 00000000..8177a2fc --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/model/dto/ResponseObjCache.java @@ -0,0 +1,42 @@ +package ca.bc.gov.educ.api.graduation.model.dto; + +import org.json.JSONObject; + +import java.util.Base64; + +public class ResponseObjCache { + + private long tokenExpiry = 0; + private ResponseObj responseObj; + + // tokenExpiry-[seconds] provides a slight offset, if token WILL expire in + // [seconds], obtain a new one + private int offset; + + public ResponseObjCache(int offset) { + this.offset = offset; + } + + public ResponseObj getResponseObj() { + return responseObj; + } + + public void setResponseObj(ResponseObj responseObj) { + this.setTokenExpiry(responseObj); + this.responseObj = responseObj; + } + + public boolean isExpired(){ + // tokenExpiry-[seconds] provides a slight offset, if token WILL expire in + // 10 seconds, obtain a new one + return (responseObj == null) || (tokenExpiry-offset) < (System.currentTimeMillis() / 1000); + } + + private void setTokenExpiry(ResponseObj responseObj){ + String[] parts = responseObj.getAccess_token().split("\\."); + JSONObject payload = new JSONObject(new String(Base64.getUrlDecoder().decode(parts[1]))); + this.tokenExpiry = payload.getLong("exp"); + } + + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/GraduationService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/GraduationService.java index d64c4103..f721ca3a 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/GraduationService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/GraduationService.java @@ -215,7 +215,7 @@ public byte[] getSchoolReports(List uniqueSchoolList, String type, Strin try { List stdList = gradStatusService.getStudentListByMinCode(usl, accessToken); - SchoolTrax schoolDetails = schoolService.getSchoolDetails(usl, accessToken, new ExceptionMessage()); + SchoolTrax schoolDetails = schoolService.getTraxSchoolDetails(usl, accessToken, new ExceptionMessage()); if (schoolDetails != null) { School schoolObj = new School(); schoolObj.setMincode(schoolDetails.getMinCode()); @@ -266,7 +266,7 @@ public Integer createAndStoreSchoolReports(List uniqueSchoolList, String String listOfStudents = jsonTransformer.marshall(stdList); logger.debug("*** Student List of {} Acquired {}", totalStudents, listOfStudents); } - SchoolTrax schoolDetails = schoolService.getSchoolDetails(usl, accessToken, exception); + SchoolTrax schoolDetails = schoolService.getTraxSchoolDetails(usl, accessToken, exception); if (schoolDetails != null) { logger.debug("*** School Details Acquired {}", schoolDetails.getSchoolName()); if (stdList != null && !stdList.isEmpty()) { diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java index 17ab9d76..003568c3 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java @@ -164,7 +164,7 @@ public ReportData prepareTranscriptData(ca.bc.gov.educ.api.graduation.model.dto. SchoolTrax traxSchool = null; if(schoolAtGrad != null) { String mincode = schoolAtGrad.getMincode(); - traxSchool = schoolService.getSchoolDetails(mincode, accessToken, exception); + traxSchool = schoolService.getTraxSchoolDetails(mincode, accessToken, exception); } GraduationStatus graduationStatus = getGraduationStatus(graduationDataStatus, schoolAtGrad, schoolOfRecord); GraduationData graduationData = getGraduationData(graduationDataStatus, gradResponse, accessToken); @@ -769,7 +769,7 @@ private Student getStudentData(GradSearchStudent gradStudent, GraduationStudentR private School getSchoolAtGradData(ca.bc.gov.educ.api.graduation.model.dto.GraduationData graduationDataStatus, String accessToken, ExceptionMessage exception) { if (graduationDataStatus.getGradStatus() != null && !StringUtils.isBlank(graduationDataStatus.getGradStatus().getSchoolAtGrad())) { - SchoolTrax schoolDetails = schoolService.getSchoolDetails(graduationDataStatus.getGradStatus().getSchoolAtGrad(), accessToken, exception); + SchoolTrax schoolDetails = schoolService.getTraxSchoolDetails(graduationDataStatus.getGradStatus().getSchoolAtGrad(), accessToken, exception); if (schoolDetails != null) { return getSchoolData(schoolDetails); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java index 24e04061..7dd659db 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java @@ -2,6 +2,7 @@ import ca.bc.gov.educ.api.graduation.model.dto.ReportGradStudentData; import ca.bc.gov.educ.api.graduation.model.dto.SchoolReports; +import ca.bc.gov.educ.api.graduation.model.dto.SchoolTrax; import ca.bc.gov.educ.api.graduation.model.report.*; import ca.bc.gov.educ.api.graduation.util.*; import lombok.SneakyThrows; @@ -151,9 +152,15 @@ public Integer createAndStoreSchoolDistrictYearEndReports(String accessToken, St logger.debug("***** {} Students Retrieved *****", reportGradStudentDataList.size()); if(schools != null && !schools.isEmpty()) { boolean isDistrictSchool = schools.get(0).length() == 3; + if(isDistrictSchool) { + reportGradStudentDataList.removeIf(st -> ((StringUtils.isBlank(st.getMincodeAtGrad()) || StringUtils.equals(st.getMincode(), st.getMincodeAtGrad())) && !schools.contains(StringUtils.substring(st.getMincode(), 0, 3)))); + reportGradStudentDataList.removeIf(st -> ((StringUtils.isNotBlank(st.getMincodeAtGrad()) && !StringUtils.equals(st.getMincode(), st.getMincodeAtGrad())) && !schools.contains(StringUtils.substring(st.getMincodeAtGrad(), 0, 3)))); + } boolean isSchoolSchool = schools.get(0).length() > 3; - reportGradStudentDataList.removeIf(st->isDistrictSchool && !schools.contains(StringUtils.substring(st.getMincode(), 0, 3))); - reportGradStudentDataList.removeIf(st->isSchoolSchool && !schools.contains(st.getMincode())); + if(isSchoolSchool) { + reportGradStudentDataList.removeIf(st -> ((StringUtils.isBlank(st.getMincodeAtGrad()) || StringUtils.equals(st.getMincode(), st.getMincodeAtGrad())) && !schools.contains(StringUtils.trimToEmpty(st.getMincode())))); + reportGradStudentDataList.removeIf(st -> ((StringUtils.isNotBlank(st.getMincodeAtGrad()) && !StringUtils.equals(st.getMincode(), st.getMincodeAtGrad())) && !schools.contains(StringUtils.trimToEmpty(st.getMincodeAtGrad())))); + } } return createAndStoreReports(reportGradStudentDataList, accessToken, slrt, drt, srt, null); } @@ -443,7 +450,8 @@ private String getReportOrgCode(String mincode) { private School populateDistrictObjectByReportGradStudentData(Map> districtSchoolsMap, ReportGradStudentData reportGradStudentData) { //district data, not school - String distcode = StringUtils.substring(reportGradStudentData.getMincode(), 0, 3); + String mincode = StringUtils.isBlank(reportGradStudentData.getMincodeAtGrad()) ? reportGradStudentData.getMincode() : reportGradStudentData.getMincodeAtGrad(); + String distcode = StringUtils.substring(mincode, 0, 3); boolean addNewDistrict = true; School district = null; for (var entry : districtSchoolsMap.entrySet()) { @@ -464,25 +472,27 @@ private School populateDistrictObjectByReportGradStudentData(Map()); return school; } private School populateSchoolObjectByReportGradStudentData(Map schoolMap, ReportGradStudentData reportGradStudentData) { - String mincode = reportGradStudentData.getMincode(); + String mincode = StringUtils.isBlank(reportGradStudentData.getMincodeAtGrad()) ? reportGradStudentData.getMincode() : reportGradStudentData.getMincodeAtGrad(); School school = schoolMap.get(mincode); if (school == null) { school = populateSchoolObjectByReportGradStudentData(reportGradStudentData); @@ -570,7 +580,8 @@ private Student populateStudentObjectByReportGradStudentData(ReportGradStudentDa GraduationStatus gradStatus = new GraduationStatus(); gradStatus.setProgramCompletionDate(reportGradStudentData.getProgramCompletionDate()); - gradStatus.setSchoolAtGrad(reportGradStudentData.getMincode()); + gradStatus.setSchoolOfRecord(StringUtils.isBlank(reportGradStudentData.getMincodeAtGrad()) ? reportGradStudentData.getMincode() : reportGradStudentData.getMincodeAtGrad()); + gradStatus.setSchoolAtGrad(reportGradStudentData.getMincodeAtGrad()); gradStatus.setProgramName(reportGradStudentData.getProgramCode()); gradStatus.setCertificates(reportGradStudentData.getCertificateTypeCode()); student.setGraduationStatus(gradStatus); diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolService.java index 1bcc981d..b8b3bda6 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolService.java @@ -3,6 +3,7 @@ import ca.bc.gov.educ.api.graduation.model.dto.ExceptionMessage; import ca.bc.gov.educ.api.graduation.model.dto.SchoolTrax; import ca.bc.gov.educ.api.graduation.util.EducGraduationApiConstants; +import ca.bc.gov.educ.api.graduation.util.TokenUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -10,16 +11,26 @@ public class SchoolService { EducGraduationApiConstants educGraduationApiConstants; RESTService restService; + TokenUtils tokenUtils; @Autowired - public SchoolService(EducGraduationApiConstants educGraduationApiConstants, RESTService restService) { + public SchoolService(EducGraduationApiConstants educGraduationApiConstants, RESTService restService, TokenUtils tokenUtils) { this.educGraduationApiConstants = educGraduationApiConstants; this.restService = restService; + this.tokenUtils = tokenUtils; } - public SchoolTrax getSchoolDetails(String mincode, String accessToken, ExceptionMessage message) { + public SchoolTrax getTraxSchoolDetails(String mincode, String accessToken, ExceptionMessage message) { return this.restService.get(String.format(educGraduationApiConstants.getSchoolDetails(),mincode, accessToken), SchoolTrax.class, accessToken); } + + public SchoolTrax getTraxSchoolDetails(String mincode) { + String accessToken = tokenUtils.getAccessToken(); + return this.restService.get(String.format(educGraduationApiConstants.getSchoolDetails(),mincode, accessToken), + SchoolTrax.class, + accessToken); + } + } diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/util/TokenUtils.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/util/TokenUtils.java index 63419985..f33cc8b9 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/util/TokenUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/util/TokenUtils.java @@ -2,6 +2,7 @@ import ca.bc.gov.educ.api.graduation.model.dto.ProcessorData; import ca.bc.gov.educ.api.graduation.model.dto.ResponseObj; +import ca.bc.gov.educ.api.graduation.model.dto.ResponseObjCache; import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,15 +17,17 @@ @Component public class TokenUtils { - private static Logger logger = LoggerFactory.getLogger(TokenUtils.class); + private static final Logger LOGGER = LoggerFactory.getLogger(TokenUtils.class); + private ResponseObjCache responseObjCache; private final EducGraduationApiConstants constants; private final WebClient webClient; @Autowired - public TokenUtils(final EducGraduationApiConstants constants, final WebClient webClient) { + public TokenUtils(final EducGraduationApiConstants constants, final WebClient webClient, final ResponseObjCache responseObjCache) { this.constants = constants; this.webClient = webClient; + this.responseObjCache = responseObjCache; } public Pair checkAndGetAccessToken(Pair req) { @@ -32,9 +35,9 @@ public Pair checkAndGetAccessToken(Pair req) { long startTime = req.getRight(); long diff = (currentTime - startTime)/1000; - logger.debug("=========> Check Duration: {} sec <===========", diff); + LOGGER.debug("=========> Check Duration: {} sec <===========", diff); if (diff > 120) { // if the previous step took more than 2 minutes, treat it as a long process, and get the new access token - logger.debug("=========> Getting the new Access Token after 2 minutes <==========="); + LOGGER.debug("=========> Getting the new Access Token after 2 minutes <==========="); ResponseObj responseObj = getTokenResponseObject(); if (responseObj != null) { return Pair.of(responseObj.getAccess_token(), currentTime); @@ -52,13 +55,16 @@ public Pair getAccessToken(String accessToken) { return Pair.of(accessToken, startTime); } + public String getAccessToken() { + return this.getTokenResponseObject().getAccess_token(); + } + public void checkAndSetAccessToken(ProcessorData processorData) { long currentTime = System.currentTimeMillis(); long diff = (currentTime - processorData.getStartTime())/1000; - - logger.debug("=========> Check Duration: {} sec <===========", diff); + LOGGER.debug("=========> Check Duration: {} sec <===========", diff); if (diff > 120) { // if the previous step took more than 2 minutes, treat it as a long process, and get the new access token - logger.debug("=========> Getting the new Access Token after 2 minutes <==========="); + LOGGER.debug("=========> Getting the new Access Token after 2 minutes <==========="); ResponseObj responseObj = getTokenResponseObject(); if (responseObj != null) { processorData.setAccessToken(responseObj.getAccess_token()); @@ -76,7 +82,15 @@ public void setAccessToken(ProcessorData processorData) { } } - private ResponseObj getTokenResponseObject() { + public ResponseObj getTokenResponseObject() { + if(responseObjCache.isExpired()){ + responseObjCache.setResponseObj(getResponseObj()); + } + return responseObjCache.getResponseObj(); + } + + public ResponseObj getResponseObj() { + LOGGER.debug("Fetch token"); HttpHeaders httpHeadersKC = EducGraduationApiUtils.getHeaders( constants.getUserName(), constants.getPassword()); MultiValueMap map= new LinkedMultiValueMap<>(); diff --git a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/GraduationServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/GraduationServiceTest.java index 1d475cb4..a44d93a7 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/GraduationServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/GraduationServiceTest.java @@ -2028,7 +2028,7 @@ public void testCreateAndStoreSchoolReports() { when(this.tokenUtils.checkAndGetAccessToken(any())).thenReturn(Pair.of("accessToken", System.currentTimeMillis())); Mockito.when(gradStatusService.getStudentListByMinCode(mincode, "accessToken")).thenReturn(sList); - Mockito.when(schoolService.getSchoolDetails(mincode, "accessToken", exception)).thenReturn(sTrax); + Mockito.when(schoolService.getTraxSchoolDetails(mincode, "accessToken", exception)).thenReturn(sTrax); int numberOfRecord = graduationService.createAndStoreSchoolReports(uniqueList,"REGALG","accessToken"); assertEquals(2,numberOfRecord); } @@ -2192,7 +2192,7 @@ public void testGetSchoolReports() { when(this.restService.post(any(String.class), any(), any(), any())).thenReturn(bytesSAR3); when(gradStatusService.getStudentListByMinCode(mincode, "accessToken")).thenReturn(sList); - when(schoolService.getSchoolDetails(mincode, "accessToken", exception)).thenReturn(sTrax); + when(schoolService.getTraxSchoolDetails(mincode, "accessToken", exception)).thenReturn(sTrax); when(this.tokenUtils.getAccessToken(any())).thenReturn(Pair.of("accessToken", System.currentTimeMillis())); byte[] result = graduationService.getSchoolReports(uniqueList,"GRADREG","accessToken"); @@ -2266,7 +2266,7 @@ public void testCreateAndStoreSchoolReports_TVR() { when(this.tokenUtils.getAccessToken(any())).thenReturn(Pair.of("accessToken", System.currentTimeMillis())); Mockito.when(gradStatusService.getStudentListByMinCode(mincode, "accessToken")).thenReturn(sList); - Mockito.when(schoolService.getSchoolDetails(mincode, "accessToken", exception)).thenReturn(sTrax); + Mockito.when(schoolService.getTraxSchoolDetails(mincode, "accessToken", exception)).thenReturn(sTrax); int numberOfRecord = graduationService.createAndStoreSchoolReports(uniqueList,"TVRRUN","accessToken"); assertEquals(1,numberOfRecord); } diff --git a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchooReportsServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchooReportsServiceTest.java index 73223b5b..5fd8cdea 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchooReportsServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchooReportsServiceTest.java @@ -1,8 +1,6 @@ package ca.bc.gov.educ.api.graduation.service; -import ca.bc.gov.educ.api.graduation.model.dto.GraduationStudentRecord; -import ca.bc.gov.educ.api.graduation.model.dto.ReportGradStudentData; -import ca.bc.gov.educ.api.graduation.model.dto.SchoolReports; +import ca.bc.gov.educ.api.graduation.model.dto.*; import ca.bc.gov.educ.api.graduation.model.report.School; import ca.bc.gov.educ.api.graduation.util.EducGraduationApiConstants; import ca.bc.gov.educ.api.graduation.util.GradValidation; @@ -58,6 +56,9 @@ public class SchooReportsServiceTest { @MockBean private ReportService reportService; + @MockBean + RESTService restService; + @MockBean private TokenUtils tokenUtils; @@ -142,6 +143,14 @@ public void testSchoolReports() { when(this.tokenUtils.getAccessToken(any())).thenReturn(Pair.of("accessToken", System.currentTimeMillis())); + SchoolTrax traxSchool = new SchoolTrax(); + traxSchool.setMinCode("12345678"); + traxSchool.setAddress1("1231"); + + when(this.restService.get(any(String.class), any(), any())).thenReturn(traxSchool); + + mockTokenResponseObject(); + School school = new School(); school.setMincode("005994567"); school.setName("Test School Name"); @@ -233,4 +242,21 @@ private String readInputStream(InputStream is) throws Exception { } return sb.toString(); } + + private String mockTokenResponseObject() { + final ResponseObj tokenObject = new ResponseObj(); + String mockToken = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJtbUhsTG4tUFlpdTl3MlVhRnh5Yk5nekQ3d2ZIb3ZBRFhHSzNROTk0cHZrIn0.eyJleHAiOjE2NjMxODg1MzMsImlhdCI6MTY2MzE4ODIzMywianRpIjoiZjA2ZWJmZDUtMzRlMi00NjY5LTg0MDktOThkNTc3OGZiYmM3IiwiaXNzIjoiaHR0cHM6Ly9zb2FtLWRldi5hcHBzLnNpbHZlci5kZXZvcHMuZ292LmJjLmNhL2F1dGgvcmVhbG1zL21hc3RlciIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiI4ZGFjNmM3Yy0xYjU5LTQ5ZDEtOTMwNC0wZGRkMTdlZGE0YWQiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJncmFkLWFkbWluLWNsaWVudCIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiaHR0cHM6Ly9kZXYuZ3JhZC5nb3YuYmMuY2EiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6IldSSVRFX1NUVURFTlQgR1JBRF9CVVNJTkVTU19SIENSRUFURV9TVFVERU5UX1hNTF9UUkFOU0NSSVBUX1JFUE9SVCBDUkVBVEVfR1JBRF9BU1NFU1NNRU5UX1JFUVVJUkVNRU5UX0RBVEEgUkVBRF9TVFVERU5UIFJFQURfU0NIT09MIGVtYWlsIHByb2ZpbGUiLCJjbGllbnRJZCI6ImdyYWQtYWRtaW4tY2xpZW50IiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJjbGllbnRIb3N0IjoiMTQyLjMxLjQwLjE1NiIsInByZWZlcnJlZF91c2VybmFtZSI6InNlcnZpY2UtYWNjb3VudC1ncmFkLWFkbWluLWNsaWVudCIsImNsaWVudEFkZHJlc3MiOiIxNDIuMzEuNDAuMTU2In0.AqSxYzfanjhxCEuxLVHcJWA528AglXezS0-6EBohLsAJ4W1prdcrcS7p6yv1mSBs9GEkCu7SZhjl97xWaNXf7Emd4O0ieawgfXhDdgCtWtpLc0X2NjRTcZmv9kCpr__LmX4Zl3temUShNLVsSI95iBD7GKQmx_qTMpf3fiXdmmBvpZIibEly9RBbrio5DirqdYKuj0CO3x7xruBdBQnutr_GK7_vkmpw-X4RAyxsCwxSDequot1cCgMcJvPb6SxOL0BHx01OjM84FPwf2DwDrLvhXXhh4KucykUJ7QfiA5unmlLQ0wfG-bBJDwpjlXazF8jOQNEcasABVTftW6s8NA"; + tokenObject.setAccess_token(mockToken); + tokenObject.setRefresh_token("456"); + + when(this.webClient.post()).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(constants.getTokenUrl())).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); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(ResponseObj.class)).thenReturn(Mono.just(tokenObject)); + + return mockToken; + } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchoolServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchoolServiceTest.java index 48d8e559..e59fc25b 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchoolServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchoolServiceTest.java @@ -1,7 +1,9 @@ package ca.bc.gov.educ.api.graduation.service; -import ca.bc.gov.educ.api.graduation.exception.ServiceException; -import ca.bc.gov.educ.api.graduation.model.dto.*; +import ca.bc.gov.educ.api.graduation.model.dto.ExceptionMessage; +import ca.bc.gov.educ.api.graduation.model.dto.GraduationStudentRecord; +import ca.bc.gov.educ.api.graduation.model.dto.ResponseObj; +import ca.bc.gov.educ.api.graduation.model.dto.SchoolTrax; import ca.bc.gov.educ.api.graduation.util.EducGraduationApiConstants; import ca.bc.gov.educ.api.graduation.util.GradValidation; import org.junit.After; @@ -12,19 +14,16 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.scheduling.config.ScheduledTaskHolder; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; import java.util.function.Consumer; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.openMocks; @@ -81,9 +80,39 @@ public void testGetSchoolDetails() { schtrax.setMinCode(mincode); schtrax.setAddress1("1231"); when(this.restService.get(any(String.class), any(), any())).thenReturn(schtrax); - SchoolTrax res = schoolService.getSchoolDetails(mincode, accessToken, new ExceptionMessage()); + SchoolTrax res = schoolService.getTraxSchoolDetails(mincode, accessToken, new ExceptionMessage()); assertNotNull(res); assertEquals(res.getMinCode(),mincode); } + @Test + public void testGetSchoolDetailsNoToken() { + String mincode = "213123131"; + SchoolTrax schtrax = new SchoolTrax(); + schtrax.setMinCode(mincode); + schtrax.setAddress1("1231"); + mockTokenResponseObject(); + when(this.restService.get(any(String.class), any(), any())).thenReturn(schtrax); + SchoolTrax res = schoolService.getTraxSchoolDetails(mincode); + assertNotNull(res); + assertEquals(res.getMinCode(),mincode); + } + + private String mockTokenResponseObject() { + final ResponseObj tokenObject = new ResponseObj(); + String mockToken = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJtbUhsTG4tUFlpdTl3MlVhRnh5Yk5nekQ3d2ZIb3ZBRFhHSzNROTk0cHZrIn0.eyJleHAiOjE2NjMxODg1MzMsImlhdCI6MTY2MzE4ODIzMywianRpIjoiZjA2ZWJmZDUtMzRlMi00NjY5LTg0MDktOThkNTc3OGZiYmM3IiwiaXNzIjoiaHR0cHM6Ly9zb2FtLWRldi5hcHBzLnNpbHZlci5kZXZvcHMuZ292LmJjLmNhL2F1dGgvcmVhbG1zL21hc3RlciIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiI4ZGFjNmM3Yy0xYjU5LTQ5ZDEtOTMwNC0wZGRkMTdlZGE0YWQiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJncmFkLWFkbWluLWNsaWVudCIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiaHR0cHM6Ly9kZXYuZ3JhZC5nb3YuYmMuY2EiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6IldSSVRFX1NUVURFTlQgR1JBRF9CVVNJTkVTU19SIENSRUFURV9TVFVERU5UX1hNTF9UUkFOU0NSSVBUX1JFUE9SVCBDUkVBVEVfR1JBRF9BU1NFU1NNRU5UX1JFUVVJUkVNRU5UX0RBVEEgUkVBRF9TVFVERU5UIFJFQURfU0NIT09MIGVtYWlsIHByb2ZpbGUiLCJjbGllbnRJZCI6ImdyYWQtYWRtaW4tY2xpZW50IiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJjbGllbnRIb3N0IjoiMTQyLjMxLjQwLjE1NiIsInByZWZlcnJlZF91c2VybmFtZSI6InNlcnZpY2UtYWNjb3VudC1ncmFkLWFkbWluLWNsaWVudCIsImNsaWVudEFkZHJlc3MiOiIxNDIuMzEuNDAuMTU2In0.AqSxYzfanjhxCEuxLVHcJWA528AglXezS0-6EBohLsAJ4W1prdcrcS7p6yv1mSBs9GEkCu7SZhjl97xWaNXf7Emd4O0ieawgfXhDdgCtWtpLc0X2NjRTcZmv9kCpr__LmX4Zl3temUShNLVsSI95iBD7GKQmx_qTMpf3fiXdmmBvpZIibEly9RBbrio5DirqdYKuj0CO3x7xruBdBQnutr_GK7_vkmpw-X4RAyxsCwxSDequot1cCgMcJvPb6SxOL0BHx01OjM84FPwf2DwDrLvhXXhh4KucykUJ7QfiA5unmlLQ0wfG-bBJDwpjlXazF8jOQNEcasABVTftW6s8NA"; + tokenObject.setAccess_token(mockToken); + tokenObject.setRefresh_token("456"); + + when(this.webClient.post()).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(constants.getTokenUrl())).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); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(ResponseObj.class)).thenReturn(Mono.just(tokenObject)); + + return mockToken; + } + } diff --git a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/TokenUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/TokenUtilsTest.java new file mode 100644 index 00000000..548798f6 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/TokenUtilsTest.java @@ -0,0 +1,76 @@ +package ca.bc.gov.educ.api.graduation.service; + +import ca.bc.gov.educ.api.graduation.model.dto.ResponseObj; +import ca.bc.gov.educ.api.graduation.util.EducGraduationApiConstants; +import ca.bc.gov.educ.api.graduation.util.TokenUtils; +import lombok.val; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.BodyInserter; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.function.Consumer; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@RunWith(SpringRunner.class) +@SpringBootTest +@ActiveProfiles("test") +public class TokenUtilsTest { + + @Autowired + TokenUtils restUtils; + + @MockBean + WebClient webClient; + + @Autowired + EducGraduationApiConstants educDistributionApiConstants; + + @Mock + private WebClient.RequestHeadersSpec requestHeadersMock; + @Mock + private WebClient.RequestHeadersUriSpec requestHeadersUriMock; + @Mock + private WebClient.RequestBodySpec requestBodyMock; + @Mock + private WebClient.RequestBodyUriSpec requestBodyUriMock; + @Mock + private WebClient.ResponseSpec responseMock; + + @Test + public void testGetTokenResponseObject_returnsToken_with_APICallSuccess() { + String mockToken = mockTokenResponseObject(); + val result = this.restUtils.getTokenResponseObject(); + assertThat(result).isNotNull(); + assertThat(result.getAccess_token()).isEqualTo(mockToken); + assertThat(result.getRefresh_token()).isEqualTo("456"); + } + + private String mockTokenResponseObject() { + final ResponseObj tokenObject = new ResponseObj(); + String mockToken = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJtbUhsTG4tUFlpdTl3MlVhRnh5Yk5nekQ3d2ZIb3ZBRFhHSzNROTk0cHZrIn0.eyJleHAiOjE2NjMxODg1MzMsImlhdCI6MTY2MzE4ODIzMywianRpIjoiZjA2ZWJmZDUtMzRlMi00NjY5LTg0MDktOThkNTc3OGZiYmM3IiwiaXNzIjoiaHR0cHM6Ly9zb2FtLWRldi5hcHBzLnNpbHZlci5kZXZvcHMuZ292LmJjLmNhL2F1dGgvcmVhbG1zL21hc3RlciIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiI4ZGFjNmM3Yy0xYjU5LTQ5ZDEtOTMwNC0wZGRkMTdlZGE0YWQiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJncmFkLWFkbWluLWNsaWVudCIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiaHR0cHM6Ly9kZXYuZ3JhZC5nb3YuYmMuY2EiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6IldSSVRFX1NUVURFTlQgR1JBRF9CVVNJTkVTU19SIENSRUFURV9TVFVERU5UX1hNTF9UUkFOU0NSSVBUX1JFUE9SVCBDUkVBVEVfR1JBRF9BU1NFU1NNRU5UX1JFUVVJUkVNRU5UX0RBVEEgUkVBRF9TVFVERU5UIFJFQURfU0NIT09MIGVtYWlsIHByb2ZpbGUiLCJjbGllbnRJZCI6ImdyYWQtYWRtaW4tY2xpZW50IiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJjbGllbnRIb3N0IjoiMTQyLjMxLjQwLjE1NiIsInByZWZlcnJlZF91c2VybmFtZSI6InNlcnZpY2UtYWNjb3VudC1ncmFkLWFkbWluLWNsaWVudCIsImNsaWVudEFkZHJlc3MiOiIxNDIuMzEuNDAuMTU2In0.AqSxYzfanjhxCEuxLVHcJWA528AglXezS0-6EBohLsAJ4W1prdcrcS7p6yv1mSBs9GEkCu7SZhjl97xWaNXf7Emd4O0ieawgfXhDdgCtWtpLc0X2NjRTcZmv9kCpr__LmX4Zl3temUShNLVsSI95iBD7GKQmx_qTMpf3fiXdmmBvpZIibEly9RBbrio5DirqdYKuj0CO3x7xruBdBQnutr_GK7_vkmpw-X4RAyxsCwxSDequot1cCgMcJvPb6SxOL0BHx01OjM84FPwf2DwDrLvhXXhh4KucykUJ7QfiA5unmlLQ0wfG-bBJDwpjlXazF8jOQNEcasABVTftW6s8NA"; + tokenObject.setAccess_token(mockToken); + tokenObject.setRefresh_token("456"); + + when(this.webClient.post()).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(educDistributionApiConstants.getTokenUrl())).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); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(ResponseObj.class)).thenReturn(Mono.just(tokenObject)); + + return mockToken; + } + +} From 1202bfd27e974cb570a2f611b8daba1e240b2234 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 16 Apr 2024 14:48:41 -0600 Subject: [PATCH 2/7] GRAD2-2377 HD-22859 (GRAD) YE Distribution run should direct Certificates to School at Graduation, not School of Record --- .../api/graduation/service/SchooReportsServiceTest.java | 9 +++++---- .../resources/json/studentSchoolYearEndResponse.json | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchooReportsServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchooReportsServiceTest.java index 5fd8cdea..e22781fa 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchooReportsServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchooReportsServiceTest.java @@ -151,10 +151,6 @@ public void testSchoolReports() { mockTokenResponseObject(); - School school = new School(); - school.setMincode("005994567"); - school.setName("Test School Name"); - Integer reportsCount = schoolReportsService.createAndStoreSchoolReports(DISTREP_YE_SC, "accessToken"); assertTrue(reportsCount > 0); @@ -173,8 +169,13 @@ public void testSchoolReports() { reportsCount = schoolReportsService.createAndStoreSchoolDistrictYearEndReports("accessToken", ADDRESS_LABEL_YE, DISTREP_YE_SD, DISTREP_YE_SC); assertTrue(reportsCount > 0); + School school = new School(); + school.setMincode("005994567"); + school.setName("Test School Name"); + List schools = new ArrayList<>(); schools.add(school.getMincode()); + schools.add("005"); reportsCount = schoolReportsService.createAndStoreSchoolDistrictYearEndReports("accessToken", ADDRESS_LABEL_YE, DISTREP_YE_SD, DISTREP_YE_SC, schools); assertTrue(reportsCount > 0); diff --git a/api/src/test/resources/json/studentSchoolYearEndResponse.json b/api/src/test/resources/json/studentSchoolYearEndResponse.json index 1be51ff9..d677ee52 100644 --- a/api/src/test/resources/json/studentSchoolYearEndResponse.json +++ b/api/src/test/resources/json/studentSchoolYearEndResponse.json @@ -2,6 +2,7 @@ { "graduationStudentRecordId": "ac339d70-7649-1a2e-8176-4a1f06df5d06", "mincode": "02396738", + "mincodeAtGrad": "12345678", "pen": "118701325", "firstName": "ROBERT", "middleName": "LYNNEA", @@ -25,6 +26,7 @@ { "graduationStudentRecordId": "ac339d70-7649-1a2e-8176-4a3356591819", "mincode": "02396738", + "mincodeAtGrad": "02396738", "pen": "128320223", "firstName": "MARVIN", "middleName": "RICHARD", From eecb0d43b0c4d560aca95e5c2d7e5915e926e1ca Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 16 Apr 2024 15:00:37 -0600 Subject: [PATCH 3/7] GRAD2-2377 HD-22859 (GRAD) YE Distribution run should direct Certificates to School at Graduation, not School of Record --- .../ca/bc/gov/educ/api/graduation/config/GradCommonConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/config/GradCommonConfig.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/config/GradCommonConfig.java index ca2de734..66f38e2c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/config/GradCommonConfig.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/config/GradCommonConfig.java @@ -27,6 +27,6 @@ public void addInterceptors(InterceptorRegistry registry) { @Bean public ResponseObjCache createResponseObjCache() { - return new ResponseObjCache(30); + return new ResponseObjCache(60); } } From 63d1eae7aeb14b83c3c450e8abb77fe53cc3593e Mon Sep 17 00:00:00 2001 From: arybakov Date: Fri, 19 Apr 2024 17:22:23 -0600 Subject: [PATCH 4/7] GRAD2-2377 HD-22859 (GRAD) YE Distribution run should direct Certificates to School at Graduation, not School of Record --- .../educ/api/graduation/service/SchoolReportsService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java index 7dd659db..d55aa68c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java @@ -240,6 +240,12 @@ private Integer createAndStoreSchoolReports(String reportType, List issuedTranscriptsSchoolMap = new HashMap<>(); From 3ac6672708d94a070d222ca002dc47bf10b30bb3 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 22 Apr 2024 13:02:42 -0600 Subject: [PATCH 5/7] GRAD2-2377 HD-22859 (GRAD) YE Distribution run should direct Certificates to School at Graduation, not School of Record --- .../graduation/model/dto/DistrictTrax.java | 57 +++++++++++++++++++ .../service/SchoolReportsService.java | 16 ++++-- .../api/graduation/service/SchoolService.java | 8 +++ .../util/EducGraduationApiConstants.java | 3 + api/src/main/resources/application.yaml | 2 + 5 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 api/src/main/java/ca/bc/gov/educ/api/graduation/model/dto/DistrictTrax.java diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/model/dto/DistrictTrax.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/model/dto/DistrictTrax.java new file mode 100644 index 00000000..5219fafe --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/model/dto/DistrictTrax.java @@ -0,0 +1,57 @@ +package ca.bc.gov.educ.api.graduation.model.dto; + +import lombok.Data; +import org.springframework.stereotype.Component; + +@Data +@Component +public class DistrictTrax { + + private String districtNumber; + private String districtName; + private String districtSeq; + private String schoolETPSystem; + private String superIntendent; + private String djdeFlash; + private String activeFlag; + private String address1; + private String address2; + private String city; + private String provCode; + private String countryCode; + private String postal; + + public String getDistrictName() { + return districtName != null ? districtName.trim(): null; + } + + public String getDistrictSeq() { return districtSeq != null ? districtSeq.trim(): null; } + + public String getSchoolETPSystem() { return schoolETPSystem != null ? schoolETPSystem.trim(): null; } + + public String getSuperIntendent() {return superIntendent != null ? superIntendent.trim(): null;} + + public String getDjdeFlash() { return djdeFlash != null ? djdeFlash.trim(): null; } + + public String getActiveFlag() { return activeFlag != null ? activeFlag.trim(): null; } + + public String getAddress1() { return address1 != null ? address1.trim(): null; } + + public String getAddress2() { return address2 != null ? address2.trim(): null; } + + public String getCity() { return postal != null ? city.trim(): null; } + + public String getPostal() { return postal != null ? postal.trim(): null; } + + @Override + public String toString() { + return "District [districtNumber=" + districtNumber + ", districtName=" + districtName + ", districtSeq=" + + districtSeq + ", schoolETPSystem=" + schoolETPSystem + ", superIntendent=" + superIntendent + + ", djdeFlash=" + djdeFlash + ", activeFlag=" + activeFlag + ", address1=" + address1 + ", address2=" + + address2 + ", city=" + city + ", provCode=" + provCode + ", countryCode=" + countryCode + ", postal=" + + postal + "]"; + } + + +} + diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java index d55aa68c..e303437f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.graduation.service; +import ca.bc.gov.educ.api.graduation.model.dto.DistrictTrax; import ca.bc.gov.educ.api.graduation.model.dto.ReportGradStudentData; import ca.bc.gov.educ.api.graduation.model.dto.SchoolReports; import ca.bc.gov.educ.api.graduation.model.dto.SchoolTrax; @@ -149,7 +150,7 @@ private Integer createAndStoreReports(List reportGradStud public Integer createAndStoreSchoolDistrictYearEndReports(String accessToken, String slrt, String drt, String srt, List schools) { logger.debug("***** Get Students for School Year End Reports Starts *****"); List reportGradStudentDataList = reportService.getStudentsForSchoolYearEndReport(accessToken, schools); - logger.debug("***** {} Students Retrieved *****", reportGradStudentDataList.size()); + logger.debug("***** {} Students Retrieved *****", reportGradStudentDataList.size()); if(schools != null && !schools.isEmpty()) { boolean isDistrictSchool = schools.get(0).length() == 3; if(isDistrictSchool) { @@ -468,10 +469,11 @@ private School populateDistrictObjectByReportGradStudentData(Map()); } return district; @@ -509,18 +511,20 @@ private School populateSchoolObjectByReportGradStudentData(Map s private void processDistrictSchoolMap(List schools, ReportGradStudentData reportGradStudentData) { boolean addNewSchool = true; - String distNo = StringUtils.substring(reportGradStudentData.getMincode(), 0, 3); + String mincode = StringUtils.isBlank(reportGradStudentData.getMincodeAtGrad()) ? reportGradStudentData.getMincode() : reportGradStudentData.getMincodeAtGrad(); + String distNo = StringUtils.substring(mincode, 0, 3); for (School school : schools) { - if (StringUtils.equals(school.getMincode(), reportGradStudentData.getMincode())) { + if (StringUtils.equals(school.getMincode(), mincode)) { addNewSchool = false; processDistrictSchool(school, reportGradStudentData); } } if (addNewSchool) { + SchoolTrax schoolTrax = schoolService.getTraxSchoolDetails(mincode); School school = new School(); school.setDistno(distNo); - school.setMincode(reportGradStudentData.getMincode()); - school.setName(reportGradStudentData.getSchoolName()); + school.setMincode(mincode); + school.setName(schoolTrax != null ? schoolTrax.getSchoolName() : reportGradStudentData.getSchoolName()); school.setTypeBanner("Principal"); schools.add(processDistrictSchool(school, reportGradStudentData)); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolService.java index b8b3bda6..76cca761 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolService.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.graduation.service; +import ca.bc.gov.educ.api.graduation.model.dto.DistrictTrax; import ca.bc.gov.educ.api.graduation.model.dto.ExceptionMessage; import ca.bc.gov.educ.api.graduation.model.dto.SchoolTrax; import ca.bc.gov.educ.api.graduation.util.EducGraduationApiConstants; @@ -33,4 +34,11 @@ public SchoolTrax getTraxSchoolDetails(String mincode) { accessToken); } + public DistrictTrax getTraxDistrictDetails(String districtCode) { + String accessToken = tokenUtils.getAccessToken(); + return this.restService.get(String.format(educGraduationApiConstants.getDistrictDetails(), districtCode, accessToken), + DistrictTrax.class, + accessToken); + } + } diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/util/EducGraduationApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/util/EducGraduationApiConstants.java index 2cea7f93..c5bc3b7a 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/util/EducGraduationApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/util/EducGraduationApiConstants.java @@ -164,6 +164,9 @@ public class EducGraduationApiConstants { @Value("${endpoint.grad-trax-api.school-by-min-code.url}") private String schoolDetails; + @Value("${endpoint.grad-trax-api.district-by-min-code.url}") + private String districtDetails; + @Value("${endpoint.grad-graduation-report-api.update-grad-school-report.url}") private String updateSchoolReport; diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index 5af2a1b0..1ecbfb58 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -133,6 +133,8 @@ endpoint: grad-trax-api: school-by-min-code: url: ${GRAD_TRAX_API}api/v1/trax/school/%s + district-by-min-code: + url: ${GRAD_TRAX_API}api/v1/trax/district/%s #Splunk LogHelper splunk: From 8c7d09dda8999c3951f30e980792de4fc0c3c89b Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 22 Apr 2024 13:36:17 -0600 Subject: [PATCH 6/7] GRAD2-2377 HD-22859 (GRAD) YE Distribution run should direct Certificates to School at Graduation, not School of Record --- .../service/SchoolReportsService.java | 27 ++++++++++--------- .../graduation/service/ReportServiceTest.java | 11 ++++++++ .../service/SchooReportsServiceTest.java | 12 +++++++++ .../graduation/service/SchoolServiceTest.java | 18 ++++++++++--- api/src/test/resources/application.yaml | 2 ++ 5 files changed, 54 insertions(+), 16 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java index e303437f..1bf76609 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/SchoolReportsService.java @@ -483,19 +483,22 @@ private School populateSchoolObjectByReportGradStudentData(ReportGradStudentData String mincode = StringUtils.isBlank(reportGradStudentData.getMincodeAtGrad()) ? reportGradStudentData.getMincode() : reportGradStudentData.getMincodeAtGrad(); SchoolTrax traxSchool = schoolService.getTraxSchoolDetails(mincode); School school = new School(); - school.setDistno(StringUtils.substring(traxSchool.getMinCode(), 0, 3)); - school.setMincode(traxSchool.getMinCode()); - school.setName(traxSchool.getSchoolName()); - school.setTypeBanner("Principal"); - Address address = new Address(); - address.setStreetLine1(traxSchool.getAddress1()); - address.setStreetLine2(traxSchool.getAddress2()); - address.setCity(traxSchool.getCity()); - address.setRegion(traxSchool.getProvCode()); - address.setCountry(traxSchool.getCountryName()); - address.setCode(traxSchool.getPostal()); - school.setAddress(address); school.setStudents(new ArrayList<>()); + if(traxSchool != null) { + school.setDistno(StringUtils.substring(traxSchool.getMinCode(), 0, 3)); + school.setMincode(traxSchool.getMinCode()); + school.setName(traxSchool.getSchoolName()); + school.setTypeBanner("Principal"); + Address address = new Address(); + address.setStreetLine1(traxSchool.getAddress1()); + address.setStreetLine2(traxSchool.getAddress2()); + address.setCity(traxSchool.getCity()); + address.setRegion(traxSchool.getProvCode()); + address.setCountry(traxSchool.getCountryName()); + address.setCode(traxSchool.getPostal()); + school.setAddress(address); + return school; + } return school; } diff --git a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/ReportServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/ReportServiceTest.java index 5c494d76..ed646b4d 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/ReportServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/ReportServiceTest.java @@ -1802,6 +1802,17 @@ public void testReportDataByPen() throws Exception { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(SchoolTrax.class)).thenReturn(Mono.just(schtrax)); + DistrictTrax disttrax = new DistrictTrax(); + disttrax.setDistrictNumber("005"); + disttrax.setDistrictName("My District"); + disttrax.setAddress1("My Address"); + + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getDistrictDetails(),schtrax.getMinCode()))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(DistrictTrax.class)).thenReturn(Mono.just(disttrax)); + List programRequirementCodes = new ArrayList<>(); ProgramRequirementCode programRequirementCode = new ProgramRequirementCode(); diff --git a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchooReportsServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchooReportsServiceTest.java index e22781fa..90985b8f 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchooReportsServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchooReportsServiceTest.java @@ -59,6 +59,9 @@ public class SchooReportsServiceTest { @MockBean RESTService restService; + @MockBean + SchoolService schoolService; + @MockBean private TokenUtils tokenUtils; @@ -148,6 +151,7 @@ public void testSchoolReports() { traxSchool.setAddress1("1231"); when(this.restService.get(any(String.class), any(), any())).thenReturn(traxSchool); + when(this.schoolService.getTraxSchoolDetails(traxSchool.getMinCode())).thenReturn(traxSchool); mockTokenResponseObject(); @@ -157,6 +161,14 @@ public void testSchoolReports() { reportsCount = schoolReportsService.createAndStoreSchoolReports(DISTREP_SC, "accessToken"); assertTrue(reportsCount > 0); + DistrictTrax disttrax = new DistrictTrax(); + disttrax.setDistrictNumber("005"); + disttrax.setDistrictName("My District"); + disttrax.setAddress1("My Address"); + + when(this.schoolService.getTraxSchoolDetails(traxSchool.getMinCode())).thenReturn(traxSchool); + when(this.schoolService.getTraxDistrictDetails(disttrax.getDistrictNumber())).thenReturn(disttrax); + reportsCount = schoolReportsService.createAndStoreDistrictReports(DISTREP_YE_SD, "accessToken"); assertTrue(reportsCount > 0); diff --git a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchoolServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchoolServiceTest.java index e59fc25b..e1304588 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchoolServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/graduation/service/SchoolServiceTest.java @@ -1,9 +1,6 @@ package ca.bc.gov.educ.api.graduation.service; -import ca.bc.gov.educ.api.graduation.model.dto.ExceptionMessage; -import ca.bc.gov.educ.api.graduation.model.dto.GraduationStudentRecord; -import ca.bc.gov.educ.api.graduation.model.dto.ResponseObj; -import ca.bc.gov.educ.api.graduation.model.dto.SchoolTrax; +import ca.bc.gov.educ.api.graduation.model.dto.*; import ca.bc.gov.educ.api.graduation.util.EducGraduationApiConstants; import ca.bc.gov.educ.api.graduation.util.GradValidation; import org.junit.After; @@ -98,6 +95,19 @@ public void testGetSchoolDetailsNoToken() { assertEquals(res.getMinCode(),mincode); } + @Test + public void testGetDistrictDetailsNoToken() { + String mincode = "213"; + DistrictTrax schtrax = new DistrictTrax(); + schtrax.setDistrictNumber(mincode); + schtrax.setAddress1("1231"); + mockTokenResponseObject(); + when(this.restService.get(any(String.class), any(), any())).thenReturn(schtrax); + DistrictTrax res = schoolService.getTraxDistrictDetails(mincode); + assertNotNull(res); + assertEquals(res.getDistrictNumber(),mincode); + } + private String mockTokenResponseObject() { final ResponseObj tokenObject = new ResponseObj(); String mockToken = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJtbUhsTG4tUFlpdTl3MlVhRnh5Yk5nekQ3d2ZIb3ZBRFhHSzNROTk0cHZrIn0.eyJleHAiOjE2NjMxODg1MzMsImlhdCI6MTY2MzE4ODIzMywianRpIjoiZjA2ZWJmZDUtMzRlMi00NjY5LTg0MDktOThkNTc3OGZiYmM3IiwiaXNzIjoiaHR0cHM6Ly9zb2FtLWRldi5hcHBzLnNpbHZlci5kZXZvcHMuZ292LmJjLmNhL2F1dGgvcmVhbG1zL21hc3RlciIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiI4ZGFjNmM3Yy0xYjU5LTQ5ZDEtOTMwNC0wZGRkMTdlZGE0YWQiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJncmFkLWFkbWluLWNsaWVudCIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiaHR0cHM6Ly9kZXYuZ3JhZC5nb3YuYmMuY2EiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6IldSSVRFX1NUVURFTlQgR1JBRF9CVVNJTkVTU19SIENSRUFURV9TVFVERU5UX1hNTF9UUkFOU0NSSVBUX1JFUE9SVCBDUkVBVEVfR1JBRF9BU1NFU1NNRU5UX1JFUVVJUkVNRU5UX0RBVEEgUkVBRF9TVFVERU5UIFJFQURfU0NIT09MIGVtYWlsIHByb2ZpbGUiLCJjbGllbnRJZCI6ImdyYWQtYWRtaW4tY2xpZW50IiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJjbGllbnRIb3N0IjoiMTQyLjMxLjQwLjE1NiIsInByZWZlcnJlZF91c2VybmFtZSI6InNlcnZpY2UtYWNjb3VudC1ncmFkLWFkbWluLWNsaWVudCIsImNsaWVudEFkZHJlc3MiOiIxNDIuMzEuNDAuMTU2In0.AqSxYzfanjhxCEuxLVHcJWA528AglXezS0-6EBohLsAJ4W1prdcrcS7p6yv1mSBs9GEkCu7SZhjl97xWaNXf7Emd4O0ieawgfXhDdgCtWtpLc0X2NjRTcZmv9kCpr__LmX4Zl3temUShNLVsSI95iBD7GKQmx_qTMpf3fiXdmmBvpZIibEly9RBbrio5DirqdYKuj0CO3x7xruBdBQnutr_GK7_vkmpw-X4RAyxsCwxSDequot1cCgMcJvPb6SxOL0BHx01OjM84FPwf2DwDrLvhXXhh4KucykUJ7QfiA5unmlLQ0wfG-bBJDwpjlXazF8jOQNEcasABVTftW6s8NA"; diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index f5b1abbd..3277d80e 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -132,6 +132,8 @@ endpoint: grad-trax-api: school-by-min-code: url: https://educ-grad-trax-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/trax/school/%s + district-by-min-code: + url: https://educ-grad-trax-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/trax/district/%s #Splunk LogHelper splunk: From 418510b0b46763d68d6061216ac730d597f8389e Mon Sep 17 00:00:00 2001 From: githubmamatha <106563495+githubmamatha@users.noreply.github.com> Date: Wed, 24 Apr 2024 09:36:18 -0700 Subject: [PATCH 7/7] Update pom.xml --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index de732c9d..28b90f83 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,7 +6,7 @@ ca.bc.gov.educ educ-grad-graduation-api - 1.8.54 + 1.8.55 educ-grad-graduation-api Ministry of Education GRAD GRADUATION API