Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grad release 1.18.0 #520

Merged
merged 11 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.bc.gov.educ</groupId>
<artifactId>educ-grad-graduation-api</artifactId>
<version>1.8.54</version>
<version>1.8.55</version>
<name>educ-grad-graduation-api</name>
<description>Ministry of Education GRAD GRADUATION API</description>

Expand Down Expand Up @@ -213,6 +213,11 @@
<artifactId>pdfbox</artifactId>
<version>2.0.26</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220320</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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;
import org.springframework.context.annotation.PropertySource;
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 {
Expand All @@ -26,4 +25,8 @@ public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(requestInterceptor).addPathPatterns("/**");
}

@Bean
public ResponseObjCache createResponseObjCache() {
return new ResponseObjCache(60);
}
}
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
@@ -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");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public byte[] getSchoolReports(List<String> uniqueSchoolList, String type, Strin

try {
List<GraduationStudentRecord> 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());
Expand Down Expand Up @@ -266,7 +266,7 @@ public Integer createAndStoreSchoolReports(List<String> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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;
import ca.bc.gov.educ.api.graduation.model.report.*;
import ca.bc.gov.educ.api.graduation.util.*;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -148,12 +150,18 @@ 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) {
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);
}
Expand Down Expand Up @@ -233,6 +241,12 @@ private Integer createAndStoreSchoolReports(String reportType, List<ReportGradSt
Student student = processNewCredentialsSchoolMap(reportGradStudentData);
if (student != null && !school.getStudents().contains(student)) {
school.getStudents().add(student);
} else if (student != null) {
for(Student st: school.getStudents()) {
if(st.getPen().equals(student.getPen())) {
st.getGraduationStatus().setCertificates(reportGradStudentData.getCertificateTypeCode());
}
}
}
}
Map<String, School> issuedTranscriptsSchoolMap = new HashMap<>();
Expand Down Expand Up @@ -443,7 +457,8 @@ private String getReportOrgCode(String mincode) {

private School populateDistrictObjectByReportGradStudentData(Map<School, List<School>> 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()) {
Expand All @@ -454,35 +469,41 @@ 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;
}

private School populateSchoolObjectByReportGradStudentData(ReportGradStudentData reportGradStudentData) {
String mincode = StringUtils.isBlank(reportGradStudentData.getMincodeAtGrad()) ? reportGradStudentData.getMincode() : reportGradStudentData.getMincodeAtGrad();
SchoolTrax traxSchool = schoolService.getTraxSchoolDetails(mincode);
School school = new School();
school.setDistno(StringUtils.substring(reportGradStudentData.getMincode(), 0, 3));
school.setMincode(reportGradStudentData.getMincode());
school.setName(reportGradStudentData.getSchoolName());
school.setTypeBanner("Principal");
Address address = new Address();
address.setStreetLine1(reportGradStudentData.getSchoolAddress1());
address.setStreetLine2(reportGradStudentData.getSchoolAddress2());
address.setCity(reportGradStudentData.getSchoolCity());
address.setRegion(reportGradStudentData.getSchoolProvince());
address.setCountry(reportGradStudentData.getSchoolCountry());
address.setCode(reportGradStudentData.getSchoolPostal());
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;
}

private School populateSchoolObjectByReportGradStudentData(Map<String, School> 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);
Expand All @@ -493,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 Expand Up @@ -570,7 +593,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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
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;
import ca.bc.gov.educ.api.graduation.util.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
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);
}

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
Loading
Loading