Skip to content

Commit

Permalink
Merge pull request #518 from bcgov/develop/alex-GRAD2-2377
Browse files Browse the repository at this point in the history
Develop/alex grad2 2377
  • Loading branch information
infstar authored Apr 22, 2024
2 parents 743d4e1 + 8c7d09d commit b50b244
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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 + "]";
}


}

Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -149,7 +150,7 @@ private Integer createAndStoreReports(List<ReportGradStudentData> reportGradStud
public Integer createAndStoreSchoolDistrictYearEndReports(String accessToken, String slrt, String drt, String srt, List<String> schools) {
logger.debug("***** Get Students for School Year End Reports Starts *****");
List<ReportGradStudentData> 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) {
Expand Down Expand Up @@ -468,10 +469,11 @@ private School populateDistrictObjectByReportGradStudentData(Map<School, List<Sc
}
}
if (addNewDistrict) {
DistrictTrax districtTrax = schoolService.getTraxDistrictDetails(distcode);
district = new School();
district.setDistno(distcode);
district.setMincode(distcode);
district.setName(reportGradStudentData.getDistrictName());
district.setName(districtTrax != null ? districtTrax.getDistrictName() : reportGradStudentData.getDistrictName());
districtSchoolsMap.put(district, new ArrayList<>());
}
return district;
Expand All @@ -481,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;
}

Expand All @@ -509,18 +514,20 @@ private School populateSchoolObjectByReportGradStudentData(Map<String, School> s

private void processDistrictSchoolMap(List<School> 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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProgramRequirementCode> programRequirementCodes = new ArrayList<>();

ProgramRequirementCode programRequirementCode = new ProgramRequirementCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public class SchooReportsServiceTest {
@MockBean
RESTService restService;

@MockBean
SchoolService schoolService;

@MockBean
private TokenUtils tokenUtils;

Expand Down Expand Up @@ -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();

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions api/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b50b244

Please sign in to comment.