From 3ac6672708d94a070d222ca002dc47bf10b30bb3 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 22 Apr 2024 13:02:42 -0600 Subject: [PATCH 1/2] 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 2/2] 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.eyJleHAiOjE2NjMxODg1MzMsImlhdCI6MTY2MzE4ODIzMywianRpIjoiZjA2ZWJmZDUtMzRlMi00NjY5LTg0MDktOThkNTc3OGZiYmM3IiwiaXNzIjoiaHR0cHM6Ly9zb2FtLWRldi5hcHBzLnNpbHZlci5kZXZvcHMuZ292LmJjLmNhL2F1dGgvcmVhbG1zL21hc3RlciIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiI4ZGFjNm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xOL0BHx01OjM84FPwf2DwDrLvhXXhh4KucykUJ7QfiA5unmlLQ0wfG-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: