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

GRAD2-2949: initial commit for the new endpoints to get school clob data from institute RedisCache. #357

Merged
merged 7 commits into from
Nov 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public List<School> getAllSchools() {
@Operation(summary = "Find a School by Mincode", description = "Get a School by Mincode", tags = { "School" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "204", description = "NO CONTENT")})
public ResponseEntity<School> getSchoolDetails(@PathVariable String minCode, @RequestHeader(name="Authorization") String accessToken) {
public ResponseEntity<School> getSchoolDetails(@PathVariable String minCode) {
log.debug("getSchoolDetails : ");
School schoolResponse = schoolService.getSchoolDetails(minCode, accessToken.replace(BEARER, ""));
School schoolResponse = schoolService.getSchoolDetails(minCode);
if(schoolResponse != null) {
return response.GET(schoolResponse);
}else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package ca.bc.gov.educ.api.trax.controller.v2;

import ca.bc.gov.educ.api.trax.model.dto.School;
import ca.bc.gov.educ.api.trax.service.institute.CommonService;
import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants;
import ca.bc.gov.educ.api.trax.util.GradValidation;
import ca.bc.gov.educ.api.trax.util.PermissionsConstants;
import ca.bc.gov.educ.api.trax.util.ResponseHelper;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@Slf4j
@OpenAPIDefinition(info = @Info(title = "API for School Clob for Graduation Algorithm Data.", description = "This Common API is for retrieving School Clob for Graduation Algorithm Data from Redis Cache.", version = "2"),
security = {@SecurityRequirement(name = "OAUTH2", scopes = {"READ_GRAD_SCHOOL_DATA"})})
public class CommonController {
CommonService commonService;
GradValidation validation;
ResponseHelper response;

@Autowired
public CommonController(CommonService commonService, GradValidation validation, ResponseHelper response) {
this.commonService = commonService;
this.validation = validation;
this.response = response;
}

@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_CLOB_URL_MAPPING_V2)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Find All Schools Clob data for GRAD Algorithm Data from cache", description = "Get All Schools Clob data for GRAD Algorithm Data from cache", tags = { "Algorithm Data" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<List<School>> getAllSchoolsForClobData() {
log.debug("getAllSchoolsClob : ");
return response.GET(commonService.getSchoolsForClobDataFromRedisCache());
}

@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_CLOB_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_SCHOOL_BY_CODE_MAPPING)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Find a School Clob data by MinCode for GRAD Algorithm Data from cache", description = "Get a School Clob data by MinCode for GRAD Algorithm Data from cache", tags = { "Algorithm Data" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "400", description = "BAD REQUEST"),
@ApiResponse(responseCode = "422", description = "UNPROCESSABLE CONTENT"),
@ApiResponse(responseCode = "204", description = "NO CONTENT")})
public ResponseEntity<School> getSchoolForClobDataByMinCode(@PathVariable String minCode) {
log.debug("getSchoolClobData by minCode: {}", minCode);
validation.requiredField(minCode, "minCode");
if (validation.hasErrors()) {
validation.stopOnErrors();
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}

School schoolResponse = commonService.getSchoolForClobDataByMinCodeFromRedisCache(minCode);
if (schoolResponse != null) {
return response.GET(schoolResponse);
} else {
return response.NOT_FOUND();
}
}

@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOLS_BY_DISTRICT_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_DISTRICT_BY_DISTNO_MAPPING)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Find Schools Clob data by District Number for GRAD Algorithm Data from cache", description = "Get Schools Clob data by District Number for GRAD Algorithm Data from cache", tags = { "Algorithm Data" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<List<School>> getSchoolsForClobDataByDistrictNumber(@PathVariable String distNo) {
log.debug("getSchoolsClob by districtNumber: {}", distNo);
return response.GET(commonService.getSchoolsByDistrictNumberFromRedisCache(distNo));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public List<School> getAllSchools() {
@ApiResponse(responseCode = "204", description = "NO CONTENT")})
public ResponseEntity<School> getSchoolByMincode(@PathVariable String minCode) {
log.debug("getSchoolByMincode V2 : ");
School schoolResponse = schoolService.getSchoolByMincodeFromRedisCache(minCode);
School schoolResponse = schoolService.getSchoolByMinCodeFromRedisCache(minCode);
if(schoolResponse != null) {
return response.GET(schoolResponse);
}else {
Expand Down
83 changes: 10 additions & 73 deletions api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/School.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,20 @@
public class School implements Comparable<School> {

private String minCode;
private String schoolId;
private String schoolName;
private String districtName;
private String transcriptEligibility;
private String certificateEligibility;
private String independentDesignation;
private String mailerType;
private String address1;
private String address2;
private String city;
private String provCode;
private String provinceName;
private String countryCode;
private String countryName;
private String provCode;
private String countryCode;
private String postal;
private String independentAffiliation;
private String openFlag;
private String signatureDistrict;
private String newMinCode;
private String schoolOrg;
private String appendTrans;
private String ministryContact;
private String principalName;
private String schoolPhone;
private String schoolFax;
private String schoolEmail;

private String schoolCategory;
private String openFlag;
private String schoolCategoryCode;
private String schoolCategoryCodeInstitute;

public String getSchoolName() {
return schoolName != null ? schoolName.trim(): "";
Expand All @@ -57,54 +44,10 @@ public String getAddress2() {
public String getCity() {
return city != null ? city.trim(): "";
}

public String getProvinceName() {
return provinceName != null ? provinceName.trim(): "";
}

public String getCountryName() {
return countryName != null ? countryName.trim(): "";
}

public String getPostal() {
return postal != null ? postal.trim(): "";
}

public String getIndependentDesignation() {
return independentDesignation != null ? independentDesignation.trim(): "";
}

public String getIndependentAffiliation() {
return independentAffiliation != null ? independentAffiliation.trim(): "";
}

public String getOpenFlag() {
return openFlag != null ? openFlag.trim(): "";
}

public String getReportingFlag() {
return getOpenFlag();
}

public String getSignatureDistrict() {
return signatureDistrict != null ? signatureDistrict.trim(): "";
}

public String getSchoolEmail() {
return schoolEmail != null ? schoolEmail.trim(): "";
}

public String getPrincipalName() {
return principalName != null ? principalName.trim(): "";
}

public String getAppendTrans() {
return appendTrans != null ? appendTrans.trim(): "";
}

public String getMinistryContact() {
return ministryContact != null ? ministryContact.trim(): "";
}

public String getMinCode() {
return minCode != null ? minCode.trim(): "";
Expand All @@ -126,16 +69,10 @@ public int hashCode() {

@Override
public String toString() {
return "School [minCode=" + minCode + ", schoolName=" + schoolName + ", districtName=" + districtName
+ ", transcriptEligibility=" + transcriptEligibility + ", certificateEligibility="
+ certificateEligibility + ", independentDesignation=" + independentDesignation + ", mailerType="
+ mailerType + ", address1=" + address1 + ", address2=" + address2 + ", city=" + city + ", provCode="
+ provCode + ", provinceName=" + provinceName + ", countryCode=" + countryCode + ", countryName="
+ countryName + ", postal=" + postal + ", independentAffiliation=" + independentAffiliation
+ ", openFlag=" + openFlag + ", signatureDistrict=" + signatureDistrict + ", newMinCode=" + newMinCode
+ ", schoolOrg=" + schoolOrg + ", appendTrans=" + appendTrans + ", ministryContact=" + ministryContact
+ ", principalName=" + principalName + ", schoolPhone=" + schoolPhone + ", schoolFax=" + schoolFax
+ ", schoolEmail=" + schoolEmail + "]";
return "School [minCode=" + minCode + ", schoolId=" + schoolId + ", schoolCategoryCode=" + schoolCategoryCode + ", schoolCategoryCodeInstitute=" + schoolCategoryCodeInstitute
+ ", schoolName=" + schoolName + ", districtName=" + districtName + ", transcriptEligibility=" + transcriptEligibility + ", certificateEligibility=" + certificateEligibility
+ ", address1=" + address1 + ", address2=" + address2 + ", city=" + city + ", provCode=" + provCode + ", countryCode=" + countryCode + ", postal=" + postal + ", openFlag=" + openFlag
+ "]";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class SchoolTransformer {
ModelMapper modelMapper;

public School transformToDTO (SchoolEntity schoolEntity) {
if (schoolEntity == null) return null;
return modelMapper.map(schoolEntity, School.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public interface SchoolDetailRedisRepository extends CrudRepository<SchoolDetail

List<SchoolDetailEntity> findBySchoolCategoryCode(String schoolCategoryCode);

List<SchoolDetailEntity> findByDistrictId(String districtId);

SchoolDetailEntity findByMincode(String mincode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,39 @@
import ca.bc.gov.educ.api.trax.repository.SchoolRepository;
import ca.bc.gov.educ.api.trax.repository.TraxSchoolSearchCriteria;
import ca.bc.gov.educ.api.trax.repository.TraxSchoolSearchSpecification;
import ca.bc.gov.educ.api.trax.service.institute.CommonService;
import ca.bc.gov.educ.api.trax.util.CommonSchoolCache;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

@Service
@Slf4j
public class SchoolService {

private SchoolRepository schoolRepository;
private SchoolTransformer schoolTransformer;
private DistrictRepository districtRepository;
private DistrictTransformer districtTransformer;
private CodeService codeService;
private CommonService commonService;
private CommonSchoolCache commonSchoolCache;

@Autowired
public SchoolService(SchoolRepository schoolRepository, SchoolTransformer schoolTransformer, DistrictRepository districtRepository, DistrictTransformer districtTransformer, CodeService codeService, CommonSchoolCache commonSchoolCache) {
public SchoolService(SchoolRepository schoolRepository, SchoolTransformer schoolTransformer, DistrictRepository districtRepository, DistrictTransformer districtTransformer,
CommonSchoolCache commonSchoolCache, CommonService commonService) {
this.schoolRepository = schoolRepository;
this.schoolTransformer = schoolTransformer;
this.districtRepository = districtRepository;
this.districtTransformer = districtTransformer;
this.codeService = codeService;
this.commonService = commonService;
this.commonSchoolCache = commonSchoolCache;
}

Expand All @@ -54,24 +57,16 @@ public List<School> getSchoolList() {
if (dist != null) {
sL.setDistrictName(dist.getDistrictName());
}
if(StringUtils.isNotBlank(sL.getCountryCode())) {
GradCountry country = codeService.getSpecificCountryCode(sL.getCountryCode());
if(country != null) {
sL.setCountryName(country.getCountryName());
}
}
if(StringUtils.isNotBlank(sL.getProvCode())) {
GradProvince province = codeService.getSpecificProvinceCode(sL.getProvCode());
if(province != null) {
sL.setProvinceName(province.getProvName());
}
sL.setSchoolId(commonService.getSchoolIdStrFromRedisCache(sL.getMinCode())); // Dev
if (sL.getSchoolId() == null) {
log.debug("Mincode [{}] failed to get School from RedisCache!", sL.getMinCode());
}
});
return schoolList;
}

@Transactional(readOnly = true)
public School getSchoolDetails(String minCode, String accessToken) {
public School getSchoolDetails(String minCode) {
Optional<SchoolEntity> entOptional = schoolRepository.findById(minCode);
if(entOptional.isPresent()) {
School school = schoolTransformer.transformToDTO(entOptional.get());
Expand Down Expand Up @@ -152,8 +147,9 @@ public List<CommonSchool> getCommonSchools() {
private School adaptSchool(CommonSchool commonSchool) {
School school = new School();
school.setMinCode(commonSchool.getDistNo()+commonSchool.getSchlNo());
school.setSchoolId(commonService.getSchoolIdStrFromRedisCache(school.getMinCode()));
school.setSchoolName(commonSchool.getSchoolName());
school.setSchoolCategory(commonSchool.getSchoolCategoryCode());
school.setSchoolCategoryCode(commonSchool.getSchoolCategoryCode());
return school;
}

Expand All @@ -170,20 +166,9 @@ private void adaptSchool(School school, CommonSchool commonSchool) {
return;
}
if(school != null) {
school.setSchoolCategory(commonSchool.getSchoolCategoryCode());

if(StringUtils.isNotBlank(school.getCountryCode())) {
GradCountry country = codeService.getSpecificCountryCode(school.getCountryCode());
if(country != null) {
school.setCountryName(country.getCountryName());
}
}
if(StringUtils.isNotBlank(school.getProvCode())) {
GradProvince province = codeService.getSpecificProvinceCode(school.getProvCode());
if(province != null) {
school.setProvinceName(province.getProvName());
}
}
school.setSchoolCategoryCode(commonSchool.getSchoolCategoryCode());
school.setSchoolId(commonService.getSchoolIdStrFromRedisCache(school.getMinCode()));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ca.bc.gov.educ.api.trax.repository.GradCourseRepository;
import ca.bc.gov.educ.api.trax.repository.TraxStudentNoRepository;
import ca.bc.gov.educ.api.trax.repository.TraxStudentRepository;
import ca.bc.gov.educ.api.trax.service.institute.CommonService;
import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants;
import ca.bc.gov.educ.api.trax.util.EducGradTraxApiUtils;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -25,6 +26,8 @@
@Service
@Slf4j
public class TraxCommonService {

private final CommonService commonSerivce;
private final TraxStudentRepository traxStudentRepository;
private final TraxStudentNoRepository traxStudentNoRepository;
private final GradCourseRepository gradCourseRepository;
Expand All @@ -35,12 +38,14 @@ public class TraxCommonService {
private final EducGradTraxApiConstants constants;

@Autowired
public TraxCommonService(TraxStudentRepository traxStudentRepository,
public TraxCommonService(CommonService commonService,
TraxStudentRepository traxStudentRepository,
TraxStudentNoRepository traxStudentNoRepository,
GradCourseRepository gradCourseRepository,
TraxStudentNoTransformer traxStudentNoTransformer,
GradCourseTransformer gradCourseTransformer,
EducGradTraxApiConstants constants) {
this.commonSerivce = commonService;
this.traxStudentRepository = traxStudentRepository;
this.traxStudentNoRepository = traxStudentNoRepository;
this.gradCourseRepository = gradCourseRepository;
Expand Down
Loading
Loading