From 9520c3e1238b185a749f315c1a074a78ce8772e9 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 13 Jun 2024 10:40:34 -0600 Subject: [PATCH] GRAD2-2637 - Cache institute api data into Redis (#329) * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis * GRAD2-2637 - Cache institute api data into Redis --- api/pom.xml | 15 ++ .../educ/api/trax/cache/CacheInitializer.java | 47 ++++ .../gov/educ/api/trax/config/RedisConfig.java | 41 ++++ .../api/trax/controller/CodeController.java | 21 +- .../trax/controller/DistrictController.java | 6 +- .../api/trax/controller/EdwController.java | 18 +- .../api/trax/controller/PsiController.java | 22 +- .../api/trax/controller/SchoolController.java | 18 +- .../trax/controller/TraxCommonController.java | 38 ++-- .../trax/controller/v2/SchoolController.java | 49 +++++ .../trax/model/dto/institute/District.java | 27 +++ .../model/dto/institute/DistrictAddress.java | 23 ++ .../model/dto/institute/DistrictContact.java | 30 +++ .../api/trax/model/dto/institute/Grade.java | 17 ++ .../dto/institute/NeighborhoodLearning.java | 17 ++ .../api/trax/model/dto/institute/Note.java | 19 ++ .../api/trax/model/dto/institute/School.java | 33 +++ .../model/dto/institute/SchoolAddress.java | 23 ++ .../dto/institute/SchoolCategoryCode.java | 18 ++ .../dto/institute/SchoolFundingGroup.java | 18 ++ .../dto/institute/SchoolFundingGroupCode.java | 17 ++ .../trax/model/dto/institute/SchoolMove.java | 18 ++ .../institute/DistrictAddressEntity.java | 32 +++ .../institute/DistrictContactEntity.java | 36 ++++ .../entity/institute/DistrictEntity.java | 35 +++ .../model/entity/institute/GradeEntity.java | 26 +++ .../institute/NeighborhoodLearningEntity.java | 26 +++ .../model/entity/institute/NoteEntity.java | 29 +++ .../entity/institute/SchoolAddressEntity.java | 32 +++ .../institute/SchoolCategoryCodeEntity.java | 23 ++ .../entity/institute/SchoolContactEntity.java | 36 ++++ .../entity/institute/SchoolDetailEntity.java | 57 +++++ .../model/entity/institute/SchoolEntity.java | 46 ++++ .../SchoolFundingGroupCodeEntity.java | 22 ++ .../institute/SchoolFundingGroupEntity.java | 28 +++ .../entity/institute/SchoolMoveEntity.java | 28 +++ .../institute/DistrictTransformer.java | 42 ++++ .../SchoolCategoryCodeTransformer.java | 42 ++++ .../SchoolFundingGroupCodeTransformer.java | 44 ++++ .../institute/SchoolTransformer.java | 41 ++++ .../redis/DistrictRedisRepository.java | 10 + .../SchoolCategoryCodeRedisRepository.java | 10 + ...SchoolFundingGroupCodeRedisRepository.java | 10 + .../redis/SchoolRedisRepository.java | 10 + .../educ/api/trax/service/CodeService.java | 15 +- .../trax/service/institute/CodeService.java | 102 +++++++++ .../service/institute/DistrictService.java | 61 ++++++ .../trax/service/institute/SchoolService.java | 118 ++++++++++ .../trax/util/EducGradTraxApiConstants.java | 55 ++++- .../bc/gov/educ/api/trax/util/RestUtils.java | 17 +- api/src/main/resources/application.yaml | 22 +- .../institute/InstituteCodeServiceTest.java | 203 ++++++++++++++++++ .../InstituteDistrictServiceTest.java | 154 +++++++++++++ .../institute/InstituteSchoolServiceTest.java | 150 +++++++++++++ api/src/test/resources/application.yaml | 23 +- tools/config/update-configmap.sh | 1 + tools/openshift/api.dc.yaml | 4 + 57 files changed, 2045 insertions(+), 80 deletions(-) create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/cache/CacheInitializer.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/config/RedisConfig.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolController.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/District.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/DistrictAddress.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/DistrictContact.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/Grade.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/NeighborhoodLearning.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/Note.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/School.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolAddress.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolCategoryCode.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolFundingGroup.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolFundingGroupCode.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolMove.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/DistrictAddressEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/DistrictContactEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/DistrictEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/GradeEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/NeighborhoodLearningEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/NoteEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolAddressEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolCategoryCodeEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolContactEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolDetailEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolFundingGroupCodeEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolFundingGroupEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolMoveEntity.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/DistrictTransformer.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolCategoryCodeTransformer.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolFundingGroupCodeTransformer.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolTransformer.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/DistrictRedisRepository.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolCategoryCodeRedisRepository.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolFundingGroupCodeRedisRepository.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolRedisRepository.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/CodeService.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/DistrictService.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolService.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteCodeServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteDistrictServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java diff --git a/api/pom.xml b/api/pom.xml index f9dde06b..b0462cc8 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -71,6 +71,16 @@ org.springframework.boot spring-boot-starter-data-jpa + + org.springframework.boot + spring-boot-starter-data-redis + + + redis.clients + jedis + + + org.apache.logging.log4j log4j-api @@ -221,6 +231,11 @@ jackson-datatype-jsr310 2.15.2 + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.client + 0.31 + diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/cache/CacheInitializer.java b/api/src/main/java/ca/bc/gov/educ/api/trax/cache/CacheInitializer.java new file mode 100644 index 00000000..f99ab607 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/cache/CacheInitializer.java @@ -0,0 +1,47 @@ +package ca.bc.gov.educ.api.trax.cache; + +import ca.bc.gov.educ.api.trax.service.institute.CodeService; +import ca.bc.gov.educ.api.trax.service.institute.DistrictService; +import ca.bc.gov.educ.api.trax.service.institute.SchoolService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; + +@Profile("!test") +@Slf4j +@Component +public class CacheInitializer implements CommandLineRunner { + + @Autowired + SchoolService schoolService; + @Autowired + DistrictService districtService; + @Autowired + CodeService codeService; + + @Override + public void run(String... args) { + schoolService.loadSchoolsIntoRedisCache( + schoolService.getSchoolsFromInstituteApi() + ); + log.info("Institutes loaded into Redis"); + + districtService.loadDistrictsIntoRedisCache( + districtService.getDistrictsFromInstituteApi() + ); + log.info("Districts loaded into Redis"); + + codeService.loadSchoolCategoryCodesIntoRedisCache( + codeService.getSchoolCategoryCodesFromInstituteApi() + ); + log.info("School Category Codes loaded into Redis"); + codeService.loadSchoolFundingGroupCodesIntoRedisCache( + codeService.getSchoolFundingGroupCodesFromInstituteApi() + ); + log.info("School Funding Group Codes loaded into Redis"); + + log.info("Redis Cache initialized!"); + } +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/config/RedisConfig.java b/api/src/main/java/ca/bc/gov/educ/api/trax/config/RedisConfig.java new file mode 100644 index 00000000..f086b3ff --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/config/RedisConfig.java @@ -0,0 +1,41 @@ +package ca.bc.gov.educ.api.trax.config; + +import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; +import org.springframework.data.redis.serializer.GenericToStringSerializer; +import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@Configuration +@EnableRedisRepositories("ca.bc.gov.educ.api.trax.repository.redis") +public class RedisConfig { + @Autowired + private EducGradTraxApiConstants constants; + @Bean + public JedisConnectionFactory jedisConnectionFactory() { + RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); + redisStandaloneConfiguration.setHostName(constants.getRedisUrl()); + redisStandaloneConfiguration.setPort(Integer.parseInt(constants.getRedisPort())); + return new JedisConnectionFactory(redisStandaloneConfiguration); + } + + @Bean + public RedisTemplate redisTemplate() { + final RedisTemplate template = new RedisTemplate<>(); + template.setConnectionFactory(jedisConnectionFactory()); + template.setKeySerializer(new StringRedisSerializer()); + template.setValueSerializer(new GenericToStringSerializer<>(Object.class)); + template.setHashKeySerializer(new JdkSerializationRedisSerializer()); + template.setHashValueSerializer(new JdkSerializationRedisSerializer()); + template.setEnableTransactionSupport(true); + template.afterPropertiesSet(); + + return template; + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/CodeController.java b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/CodeController.java index 310f24e4..ca9bb137 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/CodeController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/CodeController.java @@ -13,6 +13,7 @@ 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.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -22,8 +23,8 @@ import java.util.List; +@Slf4j @RestController -@RequestMapping(EducGradTraxApiConstants.GRAD_TRAX_CODE_URL_MAPPING) @CrossOrigin @OpenAPIDefinition(info = @Info(title = "API for TRAX Code Tables Data.", description = "This API is for Reading TRAX Code Tables data.", version = "1"), @@ -33,8 +34,6 @@ })}) public class CodeController { - private static Logger logger = LoggerFactory.getLogger(CodeController.class); - @Autowired CodeService codeService; @@ -44,22 +43,22 @@ public class CodeController { @Autowired ResponseHelper response; - @GetMapping(EducGradTraxApiConstants.GET_ALL_COUNTRY_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_TRAX_CODE_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_ALL_COUNTRY_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_COUNTRY) @Operation(summary = "Find All Countries", description = "Get All Countries", tags = {"Country"}) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity> getAllCountryCodeList() { - logger.debug("getAllCountryCodeList : "); + log.debug("getAllCountryCodeList : "); return response.GET(codeService.getAllCountryCodeList()); } - @GetMapping(EducGradTraxApiConstants.GET_ALL_COUNTRY_BY_CODE_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_TRAX_CODE_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_ALL_COUNTRY_BY_CODE_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_COUNTRY) @Operation(summary = "Find a Country by Code", description = "Get a Country by Country Code", tags = {"Country"}) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "204", description = "NO CONTENT.")}) public ResponseEntity getSpecificCountryCode(@PathVariable String countryCode) { - logger.debug("getSpecificCountryCode : "); + log.debug("getSpecificCountryCode : "); GradCountry gradResponse = codeService.getSpecificCountryCode(countryCode); if (gradResponse != null) { return response.GET(gradResponse); @@ -68,22 +67,22 @@ public ResponseEntity getSpecificCountryCode(@PathVariable String c } } - @GetMapping(EducGradTraxApiConstants.GET_ALL_PROVINCE_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_TRAX_CODE_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_ALL_PROVINCE_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_PROVINCE) @Operation(summary = "Find All Provinces", description = "Get All Provinces", tags = {"Province"}) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity> getAllProvinceCodeList() { - logger.debug("getAllProvinceCodeList : "); + log.debug("getAllProvinceCodeList : "); return response.GET(codeService.getAllProvinceCodeList()); } - @GetMapping(EducGradTraxApiConstants.GET_ALL_PROVINCE_BY_CODE_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_TRAX_CODE_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_ALL_PROVINCE_BY_CODE_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_PROVINCE) @Operation(summary = "Find a Province by Province Code", description = "Get a Province by Province Code", tags = {"Province"}) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "204", description = "NO CONTENT.")}) public ResponseEntity getSpecificProvinceCode(@PathVariable String provinceCode) { - logger.debug("getSpecificProvinceCode : "); + log.debug("getSpecificProvinceCode : "); GradProvince gradResponse = codeService.getSpecificProvinceCode(provinceCode); if (gradResponse != null) { return response.GET(gradResponse); diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/DistrictController.java b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/DistrictController.java index 5156e729..23ccc07d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/DistrictController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/DistrictController.java @@ -21,7 +21,7 @@ @CrossOrigin @RestController -@RequestMapping(EducGradTraxApiConstants.GRAD_DISTRICT_URL_MAPPING) +//@RequestMapping(EducGradTraxApiConstants.GRAD_DISTRICT_URL_MAPPING) @OpenAPIDefinition(info = @Info(title = "API for School Data.", description = "This Read API is for Reading school data.", version = "1"), security = {@SecurityRequirement(name = "OAUTH2", scopes = {"READ_GRAD_SCHOOL_DATA"})}) public class DistrictController { @@ -36,7 +36,7 @@ public class DistrictController { ResponseHelper response; - @GetMapping(EducGradTraxApiConstants.GET_DISTRICT_BY_DISTNO_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_DISTRICT_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_DISTRICT_BY_DISTNO_MAPPING) @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) @Operation(summary = "Find a District by District Number", description = "Get District by District Number", tags = { "District" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) @@ -50,7 +50,7 @@ public ResponseEntity getDistrictDetails(@PathVariable String distCode return null; } - @GetMapping(EducGradTraxApiConstants.GET_DISTRICTS_BY_SCHOOL_CATEGORY_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_DISTRICT_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_DISTRICTS_BY_SCHOOL_CATEGORY_MAPPING) @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) @Operation(summary = "Check school existence by Mincode", description = "Check school existence by Mincode", tags = { "School" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/EdwController.java b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/EdwController.java index f242ea9f..30552bf1 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/EdwController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/EdwController.java @@ -12,6 +12,7 @@ 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.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -22,15 +23,14 @@ import java.util.List; +@Slf4j @CrossOrigin @RestController -@RequestMapping(EducGradTraxApiConstants.GRAD_EDW_URL_MAPPING) +//@RequestMapping(EducGradTraxApiConstants.GRAD_EDW_URL_MAPPING) @OpenAPIDefinition(info = @Info(title = "API for EDW Snapshot.", description = "This Read API is for Reading EDW Snapshot.", version = "1"), security = {@SecurityRequirement(name = "OAUTH2", scopes = {"READ_GRAD_TRAX_STUDENT_DATA"})}) public class EdwController { - private static Logger logger = LoggerFactory.getLogger(EdwController.class); - private static final String GRAD_YEAR_PARAM = "GradYear"; private static final String SCHOOL_PARAM = "MinCode"; @@ -43,13 +43,13 @@ public class EdwController { @Autowired ResponseHelper response; - @GetMapping(EducGradTraxApiConstants.GET_SCHOOLS_BY_GRAD_YEAR_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_EDW_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_SCHOOLS_BY_GRAD_YEAR_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_TRAX_STUDENT_DATA) @Operation(summary = "Get unique schools from snapshot by gradYear", description = "Find unique schools from snapshot by gradYear", tags = { "EDW" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST")}) public ResponseEntity> getSchoolListFromSnapshotByGradYear(@PathVariable Integer gradYear) { - logger.debug("getSchoolListFromSnapshotByGradYear : "); + log.debug("getSchoolListFromSnapshotByGradYear : "); validation.requiredField(gradYear, GRAD_YEAR_PARAM); if (validation.hasErrors()) { validation.stopOnErrors(); @@ -58,13 +58,13 @@ public ResponseEntity> getSchoolListFromSnapshotByGradYear(@PathVar return response.GET(edwService.getUniqueSchoolList(gradYear)); } - @GetMapping(EducGradTraxApiConstants.GET_STUDENTS_BY_GRAD_YEAR_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_EDW_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_STUDENTS_BY_GRAD_YEAR_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_TRAX_STUDENT_DATA) @Operation(summary = "Get all students from snapshot by gradYear", description = "Find all students from snapshot by gradYear", tags = { "EDW" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST")}) public ResponseEntity> getStudentsFromSnapshotByGradYear(@PathVariable Integer gradYear) { - logger.debug("getStudentsFromSnapshotByGradYear : "); + log.debug("getStudentsFromSnapshotByGradYear : "); validation.requiredField(gradYear, GRAD_YEAR_PARAM); if (validation.hasErrors()) { validation.stopOnErrors(); @@ -73,13 +73,13 @@ public ResponseEntity> getStudentsFromSnapshotByGradYear( return response.GET(edwService.getStudents(gradYear)); } - @GetMapping(EducGradTraxApiConstants.GET_STUDENTS_BY_GRAD_YEAR_AND_SCHOOL_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_EDW_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_STUDENTS_BY_GRAD_YEAR_AND_SCHOOL_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_TRAX_STUDENT_DATA) @Operation(summary = "Get students from snapshot by gradYear & minCode", description = "Find students from snapshot by gradYear & minCode", tags = { "EDW" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST")}) public ResponseEntity> getStudentsFromSnapshotByGradYearAndSchool(@PathVariable Integer gradYear, @PathVariable String minCode) { - logger.debug("getStudentsFromSnapshotByGradYearAndSchool : "); + log.debug("getStudentsFromSnapshotByGradYearAndSchool : "); validation.requiredField(gradYear, GRAD_YEAR_PARAM); validation.requiredField(minCode, SCHOOL_PARAM); if (validation.hasErrors()) { diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/PsiController.java b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/PsiController.java index 06667357..699a331d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/PsiController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/PsiController.java @@ -12,6 +12,7 @@ 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 lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -21,14 +22,13 @@ import java.util.List; +@Slf4j @CrossOrigin @RestController -@RequestMapping(EducGradTraxApiConstants.GRAD_PSI_URL_MAPPING) +//@RequestMapping(EducGradTraxApiConstants.GRAD_PSI_URL_MAPPING) @OpenAPIDefinition(info = @Info(title = "API for PSI Data.", description = "This API is for PSI.", version = "1")) public class PsiController { - private static Logger logger = LoggerFactory.getLogger(PsiController.class); - @Autowired PsiService psiService; @@ -38,21 +38,21 @@ public class PsiController { @Autowired ResponseHelper response; - @GetMapping + @GetMapping(EducGradTraxApiConstants.GRAD_PSI_URL_MAPPING_V1) @PreAuthorize(PermissionsConstants.READ_PSI_INFO) @Operation(summary = "Find All PSIs", description = "Get All PSIs", tags = { "PSI" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) - public ResponseEntity> getAllPSIs() { - logger.debug("getAllPSIs : "); + public ResponseEntity> getAllPSIs() { + log.debug("getAllPSIs : "); return response.GET(psiService.getPSIList()); } - @GetMapping(EducGradTraxApiConstants.GET_PSI_BY_CODE_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_PSI_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_PSI_BY_CODE_MAPPING) @PreAuthorize(PermissionsConstants.READ_PSI_INFO) @Operation(summary = "Find a PSI by Code", description = "Get a PSI by Code", tags = { "PSI" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),@ApiResponse(responseCode = "400", description = "BAD REQUEST")}) public ResponseEntity getPSIDetails(@PathVariable String psiCode) { - logger.debug("getPSIDetails : "); + log.debug("getPSIDetails : "); Psi psi = psiService.getPSIDetails(psiCode); if(psi ==null) { return response.NOT_FOUND(); @@ -60,7 +60,7 @@ public ResponseEntity getPSIDetails(@PathVariable String psiCode) { return response.GET(psi); } - @GetMapping(EducGradTraxApiConstants.GET_PSI_SEARCH_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_PSI_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_PSI_SEARCH_MAPPING) @PreAuthorize(PermissionsConstants.READ_PSI_INFO) @Operation(summary = "Search for PSIs", description = "Search For PSIs", tags = { "PSI" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) @@ -73,7 +73,7 @@ public ResponseEntity> getPSIByParams( return response.GET(psiService.getPSIByParams(psiName,psiCode,cslCode,transmissionMode,openFlag)); } - @GetMapping(EducGradTraxApiConstants.GET_STUDENT_PSI_BY_CODE_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_PSI_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_STUDENT_PSI_BY_CODE_MAPPING) @PreAuthorize(PermissionsConstants.READ_PSI_INFO) @Operation(summary = "Find a PSI by Code", description = "Get a PSI by Code", tags = { "PSI" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),@ApiResponse(responseCode = "400", description = "BAD REQUEST")}) @@ -81,7 +81,7 @@ public ResponseEntity> getStudentPSIDetails( @RequestParam(value = "transmissionMode") String transmissionMode, @RequestParam(value = "psiCode") String psiCode, @RequestParam(value = "psiYear") String psiYear) { - logger.debug("getStudentPSIDetails : "); + log.debug("getStudentPSIDetails : "); return response.GET(psiService.getStudentPSIDetails(transmissionMode,psiYear,psiCode)); } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/SchoolController.java b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/SchoolController.java index fde0ff76..477036c6 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/SchoolController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/SchoolController.java @@ -24,7 +24,7 @@ @CrossOrigin @RestController @Slf4j -@RequestMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING) +//@RequestMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING) @OpenAPIDefinition(info = @Info(title = "API for School Data.", description = "This Read API is for Reading school data.", version = "1"), security = {@SecurityRequirement(name = "OAUTH2", scopes = {"READ_GRAD_SCHOOL_DATA"})}) public class SchoolController { @@ -43,7 +43,7 @@ public SchoolController(SchoolService schoolService, GradValidation validation, this.response = response; } - @GetMapping + @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V1) @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) @Operation(summary = "Find All Schools", description = "Get All Schools", tags = { "School" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) @@ -51,9 +51,9 @@ public List getAllSchools() { log.debug("getAllSchools : "); return schoolService.getSchoolList(); } + - - @GetMapping(EducGradTraxApiConstants.GET_SCHOOL_BY_CODE_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_SCHOOL_BY_CODE_MAPPING) @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) @Operation(summary = "Find a School by Mincode", description = "Get a School by Mincode", tags = { "School" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @@ -68,7 +68,7 @@ public ResponseEntity getSchoolDetails(@PathVariable String minCode, @Re } } - @GetMapping(EducGradTraxApiConstants.GET_COMMON_SCHOOLS) + @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_COMMON_SCHOOLS) @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) @Operation(summary = "Get all common schools", description = "Get a list of all common schools", tags = { "School" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) @@ -76,7 +76,7 @@ public ResponseEntity> getAllCommonSchool() { return response.GET(schoolService.getCommonSchools()); } - @GetMapping(EducGradTraxApiConstants.GET_COMMON_SCHOOL_BY_CODE_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_COMMON_SCHOOL_BY_CODE_MAPPING) @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) @Operation(summary = "Find a Common School by Mincode", description = "Get a Common School by Mincode", tags = { "School" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @@ -90,7 +90,7 @@ public ResponseEntity getCommonSchool(@PathVariable String minCode } } - @GetMapping(EducGradTraxApiConstants.GET_SCHOOL_SEARCH_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_SCHOOL_SEARCH_MAPPING) @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) @Operation(summary = "Search for a school", description = "Search for a School", tags = { "School" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @@ -103,7 +103,7 @@ public ResponseEntity> getSchoolsByParams( return response.GET(schoolService.getSchoolsByParams(schoolName, mincode, district, accessToken.replace(BEARER, ""))); } - @GetMapping(EducGradTraxApiConstants.CHECK_SCHOOL_BY_CODE_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V1 + EducGradTraxApiConstants.CHECK_SCHOOL_BY_CODE_MAPPING) @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) @Operation(summary = "Check school existence by Mincode", description = "Check school existence by Mincode", tags = { "School" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @@ -112,7 +112,7 @@ public ResponseEntity checkSchoolExists(@PathVariable String minCode) { return response.GET(schoolService.existsSchool(minCode)); } - @GetMapping(EducGradTraxApiConstants.GET_SCHOOLS_BY_SCHOOL_CATEGORY_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_SCHOOLS_BY_SCHOOL_CATEGORY_MAPPING) @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) @Operation(summary = "Check school existence by Mincode", description = "Check school existence by Mincode", tags = { "School" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/TraxCommonController.java b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/TraxCommonController.java index 51103c07..0361a99b 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/TraxCommonController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/TraxCommonController.java @@ -8,6 +8,7 @@ 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 lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -21,13 +22,12 @@ import java.util.List; +@Slf4j @CrossOrigin @RestController -@RequestMapping(EducGradTraxApiConstants.GRAD_TRAX_COMMON_URL_MAPPING) +//@RequestMapping(EducGradTraxApiConstants.GRAD_TRAX_COMMON_URL_MAPPING) @OpenAPIDefinition(info = @Info(title = "API for TRAX Data.", description = "This API is for TRAX.", version = "1")) public class TraxCommonController { - private static Logger logger = LoggerFactory.getLogger(TraxCommonController.class); - private static final String BEARER = "Bearer "; @Autowired TraxCommonService traxCommonService; @@ -38,12 +38,12 @@ public class TraxCommonController { @Autowired ResponseHelper response; - @GetMapping(EducGradTraxApiConstants.GET_TRAX_STUDENT_DEMOG_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_TRAX_COMMON_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_TRAX_STUDENT_DEMOG_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_TRAX_STUDENT_DATA) @Operation(summary = "Find Student Demographics from TRAX", description = "Find Student Demographics from TRAX", tags = {"Student"}) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST")}) public ResponseEntity> getStudentDemographicsDataFromTrax(@PathVariable String pen) { - logger.debug("getStudentDemographicsDataFromTrax : "); + log.debug("getStudentDemographicsDataFromTrax : "); validation.requiredField(pen, "Pen #"); if (validation.hasErrors()) { validation.stopOnErrors(); @@ -52,12 +52,12 @@ public ResponseEntity> getStudentDemographicsDataFromTrax(@PathVar return response.GET(traxCommonService.getStudentDemographicsDataFromTrax(pen)); } - @GetMapping(EducGradTraxApiConstants.GET_TRAX_STUDENT_MASTER_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_TRAX_COMMON_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_TRAX_STUDENT_MASTER_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_TRAX_STUDENT_DATA) @Operation(summary = "Find Student Master Record from TRAX", description = "Find Student Master Record from TRAX", tags = {"Student"}) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST")}) public ResponseEntity> getStudentMasterDataFromTrax(@PathVariable String pen) { - logger.debug("getStudentMasterDataFromTrax : "); + log.debug("getStudentMasterDataFromTrax : "); validation.requiredField(pen, "Pen #"); if (validation.hasErrors()) { validation.stopOnErrors(); @@ -66,58 +66,58 @@ public ResponseEntity> getStudentMasterDataFromTrax(@PathV return response.GET(traxCommonService.getStudentMasterDataFromTrax(pen)); } - @GetMapping(EducGradTraxApiConstants.GET_TRAX_STUDENT_NO_LIST_BY_PAGING_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_TRAX_COMMON_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_TRAX_STUDENT_NO_LIST_BY_PAGING_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_TRAX_STUDENT_DATA) @Operation(summary = "Find Student Number List from TRAX", description = "Find Student Number List from TRAX", tags = {"Student"}) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity> getTraxStudentNoListByPaging( @RequestParam(name = "pageNumber", defaultValue = "0") Integer pageNumber, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { - logger.debug("getTraxStudentNoListByPaging : pageNumber = {}, pageSize = {} ", pageNumber, pageSize); + log.debug("getTraxStudentNoListByPaging : pageNumber = {}, pageSize = {} ", pageNumber, pageSize); Pageable pageable = PageRequest.of(pageNumber, pageSize, Sort.by("studNo").ascending()); return response.GET(traxCommonService.loadTraxStudentNoByPage(pageable)); } - @GetMapping(EducGradTraxApiConstants.GET_TOTAL_NUMBER_OF_TRAX_STUDENT_NO_LIST_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_TRAX_COMMON_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_TOTAL_NUMBER_OF_TRAX_STUDENT_NO_LIST_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_TRAX_STUDENT_DATA) @Operation(summary = "Find Student Master Record from TRAX", description = "Find Student Master Record from TRAX", tags = {"Student"}) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity getTotalNumberOfTraxStudentNoList() { - logger.debug("getTotalNumberOfTraxStudentNoList : "); + log.debug("getTotalNumberOfTraxStudentNoList : "); return response.GET(traxCommonService.getTotalNumberOfTraxStudentNo()); } - @GetMapping(EducGradTraxApiConstants.GET_COURSE_RESTRICTION_LIST_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_TRAX_COMMON_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_COURSE_RESTRICTION_LIST_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_TRAX_COURSE_DATA) @Operation(summary = "Find Course Restrictions from TRAX", description = "Find Course Restrictions from TRAX", tags = {"Course"}) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity> getCourseRestrictions() { - logger.debug("getCourseRestrictions : "); + log.debug("getCourseRestrictions : "); return response.GET(traxCommonService.loadGradCourseRestrictionsDataFromTrax()); } - @GetMapping(EducGradTraxApiConstants.GET_COURSE_REQUIREMENT_LIST_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_TRAX_COMMON_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_COURSE_REQUIREMENT_LIST_MAPPING) @PreAuthorize(PermissionsConstants.READ_GRAD_TRAX_COURSE_DATA) @Operation(summary = "Find Course Restrictions from TRAX", description = "Find Course Restrictions from TRAX", tags = {"Course"}) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity> getCourseRequirements() { - logger.debug("getCourseRequirements : "); + log.debug("getCourseRequirements : "); return response.GET(traxCommonService.loadGradCourseRequirementsDataFromTrax()); } - @PostMapping(EducGradTraxApiConstants.POST_SAVE_TRAX_STUDENT_NO_MAPPING) + @PostMapping(EducGradTraxApiConstants.GRAD_TRAX_COMMON_URL_MAPPING_V1 + EducGradTraxApiConstants.POST_SAVE_TRAX_STUDENT_NO_MAPPING) @PreAuthorize(PermissionsConstants.UPDATE_GRAD_TRAX_STUDENT_DATA) @Operation(summary = "Save TraxStudentNo", description = "Save TraxStudentNo", tags = {"Student"}) public ResponseEntity saveTraxStudentNo(@RequestBody TraxStudentNo traxStudentNo) { - logger.debug("saveTraxStudentNo : "); + log.debug("saveTraxStudentNo : "); return response.GET(traxCommonService.saveTraxStudentNo(traxStudentNo)); } - @DeleteMapping(EducGradTraxApiConstants.DELETE_TRAX_STUDENT_NO_MAPPING) + @DeleteMapping(EducGradTraxApiConstants.GRAD_TRAX_COMMON_URL_MAPPING_V1 + EducGradTraxApiConstants.DELETE_TRAX_STUDENT_NO_MAPPING) @PreAuthorize(PermissionsConstants.UPDATE_GRAD_TRAX_STUDENT_DATA) @Operation(summary = "Delete TraxStudentNo", description = "Delete TraxStudentNo ", tags = {"Student"}) public ResponseEntity deleteTraxStudentNo(@PathVariable String pen) { - logger.debug("deleteTraxStudentNo : "); + log.debug("deleteTraxStudentNo : "); return response.GET(traxCommonService.deleteTraxStudentNo(pen)); } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolController.java b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolController.java new file mode 100644 index 00000000..7bd0a6f7 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolController.java @@ -0,0 +1,49 @@ +package ca.bc.gov.educ.api.trax.controller.v2; + +import ca.bc.gov.educ.api.trax.model.dto.institute.School; +import ca.bc.gov.educ.api.trax.service.institute.SchoolService; +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.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@CrossOrigin +@RestController("SchoolControllerV2") +@Slf4j +@OpenAPIDefinition(info = @Info(title = "API for School Data.", description = "This Read API is for Reading school data.", version = "1"), + security = {@SecurityRequirement(name = "OAUTH2", scopes = {"READ_GRAD_SCHOOL_DATA"})}) +public class SchoolController { + + SchoolService schoolService; + GradValidation validation; + ResponseHelper response; + + @Autowired + public SchoolController(SchoolService schoolService, GradValidation validation, ResponseHelper response) { + this.schoolService = schoolService; + this.validation = validation; + this.response = response; + } + + @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V2) + @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) + @Operation(summary = "Find All Schools", description = "Get All Schools", tags = { "School" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) + public List getAllSchools() { + log.debug("getAllSchools : "); + return schoolService.getSchoolsFromInstituteApi(); + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/District.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/District.java new file mode 100644 index 00000000..d7700fa2 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/District.java @@ -0,0 +1,27 @@ +package ca.bc.gov.educ.api.trax.model.dto.institute; + +import ca.bc.gov.educ.api.trax.model.dto.BaseModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Data +@EqualsAndHashCode(callSuper = true) +@Component("InstituteDistrict") +public class District extends BaseModel { + + private String districtId; + private String districtNumber; + private String faxNumber; + private String phoneNumber; + private String email; + private String website; + private String districtRegionCode; + private String districtStatusCode; + private List contacts; + private List addresses; + private List notes; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/DistrictAddress.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/DistrictAddress.java new file mode 100644 index 00000000..c350e60f --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/DistrictAddress.java @@ -0,0 +1,23 @@ +package ca.bc.gov.educ.api.trax.model.dto.institute; + +import ca.bc.gov.educ.api.trax.model.dto.BaseModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.stereotype.Component; + +@Data +@EqualsAndHashCode(callSuper = true) +@Component("DistrictAddress") +public class DistrictAddress extends BaseModel { + + private String districtAddressId; + private String districtId; + private String addressTypeCode; + private String addressLine1; + private String addressLine2; + private String city; + private String postal; + private String provinceCode; + private String countryCode; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/DistrictContact.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/DistrictContact.java new file mode 100644 index 00000000..7e6e5330 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/DistrictContact.java @@ -0,0 +1,30 @@ +package ca.bc.gov.educ.api.trax.model.dto.institute; + +import ca.bc.gov.educ.api.trax.model.dto.BaseModel; +import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictAddressEntity; +import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictContactEntity; +import ca.bc.gov.educ.api.trax.model.entity.institute.NoteEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Data +@EqualsAndHashCode(callSuper = true) +@Component("DistrictContact") +public class DistrictContact extends BaseModel { + + private String districtId; + private String districtNumber; + private String faxNumber; + private String phoneNumber; + private String email; + private String website; + private String districtRegionCode; + private String districtStatusCode; + private List contacts; + private List addresses; + private List notes; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/Grade.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/Grade.java new file mode 100644 index 00000000..b7b3e8dd --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/Grade.java @@ -0,0 +1,17 @@ +package ca.bc.gov.educ.api.trax.model.dto.institute; + +import ca.bc.gov.educ.api.trax.model.dto.BaseModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.stereotype.Component; + +@Data +@EqualsAndHashCode(callSuper = true) +@Component("Grade") +public class Grade extends BaseModel { + + private String schoolGradeId; + private String schoolId; + private String schoolGradeCode; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/NeighborhoodLearning.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/NeighborhoodLearning.java new file mode 100644 index 00000000..e14df402 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/NeighborhoodLearning.java @@ -0,0 +1,17 @@ +package ca.bc.gov.educ.api.trax.model.dto.institute; + +import ca.bc.gov.educ.api.trax.model.dto.BaseModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.stereotype.Component; + +@Data +@EqualsAndHashCode(callSuper = true) +@Component("NeighborhoodLearning") +public class NeighborhoodLearning extends BaseModel { + + private String neighborhoodLearningId; + private String schoolId; + private String neighborhoodLearningTypeCode; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/Note.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/Note.java new file mode 100644 index 00000000..19960202 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/Note.java @@ -0,0 +1,19 @@ +package ca.bc.gov.educ.api.trax.model.dto.institute; + +import ca.bc.gov.educ.api.trax.model.dto.BaseModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.stereotype.Component; + +@Data +@EqualsAndHashCode(callSuper = true) +@Component("Note") +public class Note extends BaseModel { + + private String noteId; + private String schoolId; + private String districtId; + private String independentAuthorityId; + private String content; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/School.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/School.java new file mode 100644 index 00000000..55adc244 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/School.java @@ -0,0 +1,33 @@ +package ca.bc.gov.educ.api.trax.model.dto.institute; + +import ca.bc.gov.educ.api.trax.model.dto.BaseModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.stereotype.Component; + +@Data +@EqualsAndHashCode(callSuper = true) +@Component("InstituteSchool") +public class School extends BaseModel { + + private String schoolId; + private String districtId; + private String mincode; + private String independentAuthorityId; + private String schoolNumber; + private String faxNumber; + private String phoneNumber; + private String email; + private String website; + private String displayName; + private String displayNameNoSpecialChars; + private String schoolReportingRequirementCode; + private String schoolOrganizationCode; + private String schoolCategoryCode; + private String facilityTypeCode; + private String openedDate; + private String closedDate; + private boolean canIssueTranscripts; + private boolean canIssueCertificates; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolAddress.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolAddress.java new file mode 100644 index 00000000..ae01421b --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolAddress.java @@ -0,0 +1,23 @@ +package ca.bc.gov.educ.api.trax.model.dto.institute; + +import ca.bc.gov.educ.api.trax.model.dto.BaseModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.stereotype.Component; + +@Data +@EqualsAndHashCode(callSuper = true) +@Component("SchoolAddress") +public class SchoolAddress extends BaseModel { + + private String SchoolAddressId; + private String SchoolId; + private String addressTypeCode; + private String addressLine1; + private String addressLine2; + private String city; + private String postal; + private String provinceCode; + private String countryCode; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolCategoryCode.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolCategoryCode.java new file mode 100644 index 00000000..9b6cbc09 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolCategoryCode.java @@ -0,0 +1,18 @@ +package ca.bc.gov.educ.api.trax.model.dto.institute; + +import lombok.Data; +import org.springframework.stereotype.Component; + +@Data +@Component("SchoolCategoryCode") +public class SchoolCategoryCode { + + private String schoolCategoryCode; + private String label; + private String description; + private String legacyCode; + private String displayOrder; + private String effectiveDate; + private String expiryDate; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolFundingGroup.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolFundingGroup.java new file mode 100644 index 00000000..f3496955 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolFundingGroup.java @@ -0,0 +1,18 @@ +package ca.bc.gov.educ.api.trax.model.dto.institute; + +import ca.bc.gov.educ.api.trax.model.dto.BaseModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.stereotype.Component; + +@Data +@EqualsAndHashCode(callSuper = true) +@Component("SchoolFundingGroup") +public class SchoolFundingGroup extends BaseModel { + + private String schoolFundingGroupID; + private String schoolId; + private String schoolGradeCode; + private String schoolFundingGroupCode; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolFundingGroupCode.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolFundingGroupCode.java new file mode 100644 index 00000000..30fd9988 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolFundingGroupCode.java @@ -0,0 +1,17 @@ +package ca.bc.gov.educ.api.trax.model.dto.institute; + +import lombok.Data; +import org.springframework.stereotype.Component; + +@Data +@Component("SchoolFundingGroupCode") +public class SchoolFundingGroupCode { + + private String schoolFundingGroupCode; + private String label; + private String description; + private String displayOrder; + private String effectiveDate; + private String expiryDate; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolMove.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolMove.java new file mode 100644 index 00000000..f052efdd --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolMove.java @@ -0,0 +1,18 @@ +package ca.bc.gov.educ.api.trax.model.dto.institute; + +import ca.bc.gov.educ.api.trax.model.dto.BaseModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.stereotype.Component; + +@Data +@EqualsAndHashCode(callSuper = true) +@Component("SchoolMove") +public class SchoolMove extends BaseModel { + + private String schoolMoveId; + private String toSchoolId; + private String fromSchoolId; + private String moveDate; + +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/DistrictAddressEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/DistrictAddressEntity.java new file mode 100644 index 00000000..befc9575 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/DistrictAddressEntity.java @@ -0,0 +1,32 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("DistrictAddress") +public class DistrictAddressEntity { + + @Id + private String districtAddressId; + @Indexed + private String districtId; + @Indexed + private String addressTypeCode; + private String addressLine1; + private String addressLine2; + private String city; + private String postal; + private String provinceCode; + private String countryCode; + private String createUser; + private String updateUser; + private String createDate; + private String updateDate; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/DistrictContactEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/DistrictContactEntity.java new file mode 100644 index 00000000..76927b10 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/DistrictContactEntity.java @@ -0,0 +1,36 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("DistrictContact") +public class DistrictContactEntity { + + @Id + private String districtContactId; + @Indexed + private String districtId; + @Indexed + private String districtContactTypeCode; + private String phoneNumber; + private String jobTitle; + private String phoneExtension; + private String alternatePhoneNumber; + private String alternatePhoneExtension; + private String email; + private String firstName; + private String lastName; + private String effectiveDate; + private String expiryDate; + private String createUser; + private String updateUser; + private String createDate; + private String updateDate; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/DistrictEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/DistrictEntity.java new file mode 100644 index 00000000..482e9ce7 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/DistrictEntity.java @@ -0,0 +1,35 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("District") +public class DistrictEntity { + + @Id + private String districtId; + @Indexed + private String districtNumber; + private String faxNumber; + private String phoneNumber; + private String email; + private String website; + private String districtRegionCode; + private String districtStatusCode; + private List contacts; + private List addresses; + private List notes; + private String createUser; + private String updateUser; + private String createDate; + private String updateDate; +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/GradeEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/GradeEntity.java new file mode 100644 index 00000000..cce6eaae --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/GradeEntity.java @@ -0,0 +1,26 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("Grade") +public class GradeEntity { + + @Id + private String schoolGradeId; + @Indexed + private String schoolId; + @Indexed + private String schoolGradeCode; + private String createUser; + private String updateUser; + private String createDate; + private String updateDate; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/NeighborhoodLearningEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/NeighborhoodLearningEntity.java new file mode 100644 index 00000000..aa7d648d --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/NeighborhoodLearningEntity.java @@ -0,0 +1,26 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("NeighborhoodLearning") +public class NeighborhoodLearningEntity { + + @Id + private String neighborhoodLearningId; + @Indexed + private String schoolId; + @Indexed + private String neighborhoodLearningTypeCode; + private String createUser; + private String updateUser; + private String createDate; + private String updateDate; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/NoteEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/NoteEntity.java new file mode 100644 index 00000000..2837b9c7 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/NoteEntity.java @@ -0,0 +1,29 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("Note") +public class NoteEntity { + + @Id + private String noteId; + @Indexed + private String schoolId; + @Indexed + private String districtId; + @Indexed + private String independentAuthorityId; + private String content; + private String createUser; + private String updateUser; + private String createDate; + private String updateDate; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolAddressEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolAddressEntity.java new file mode 100644 index 00000000..4f847d73 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolAddressEntity.java @@ -0,0 +1,32 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("SchoolAddress") +public class SchoolAddressEntity { + + @Id + private String schoolAddressId; + @Indexed + private String schoolId; + @Indexed + private String addressTypeCode; + private String addressLine1; + private String addressLine2; + private String city; + private String postal; + private String provinceCode; + private String countryCode; + private String createUser; + private String updateUser; + private String createDate; + private String updateDate; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolCategoryCodeEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolCategoryCodeEntity.java new file mode 100644 index 00000000..fefe25a5 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolCategoryCodeEntity.java @@ -0,0 +1,23 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("SchoolCategoryCode") +public class SchoolCategoryCodeEntity { + + @Id + private String schoolCategoryCode; + private String label; + private String description; + private String legacyCode; + private String displayOrder; + private String effectiveDate; + private String expiryDate; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolContactEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolContactEntity.java new file mode 100644 index 00000000..48fd2720 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolContactEntity.java @@ -0,0 +1,36 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("SchoolContact") +public class SchoolContactEntity { + + @Id + private String schooldistrictContactId; + @Indexed + private String schoolId; + @Indexed + private String schoolContactTypeCode; + private String phoneNumber; + private String jobTitle; + private String phoneExtension; + private String alternatePhoneNumber; + private String alternatePhoneExtension; + private String email; + private String firstName; + private String lastName; + private String effectiveDate; + private String expiryDate; + private String createUser; + private String updateUser; + private String createDate; + private String updateDate; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolDetailEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolDetailEntity.java new file mode 100644 index 00000000..f0edc744 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolDetailEntity.java @@ -0,0 +1,57 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("SchoolDetail") +public class SchoolDetailEntity { + + @Id + private String schoolId; + @Indexed + private String districtId; + @Indexed + private String mincode; + @Indexed + private String independentAuthorityId; + @Indexed + private String schoolNumber; + private String faxNumber; + private String phoneNumber; + private String email; + private String website; + @Indexed + private String displayName; + private String displayNameNoSpecialChars; + private String schoolReportingRequirementCode; + private String schoolOrganizationCode; + @Indexed + private String schoolCategoryCode; + private String facilityTypeCode; + private String openedDate; + private String closedDate; + @Indexed + private boolean canIssueTranscripts; + @Indexed + private boolean canIssueCertificates; + private String createUser; + private String updateUser; + private String createDate; + private String updateDate; + List contacts; + List addresses; + List notes; + List grades; + List schoolFundingGroups; + List neighborhoodLearnings; + List schoolMoves; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolEntity.java new file mode 100644 index 00000000..a8a12f50 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolEntity.java @@ -0,0 +1,46 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.*; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("School") +public class SchoolEntity { + + @Id + private String schoolId; + @Indexed + private String districtId; + @Indexed + private String mincode; + @Indexed + private String independentAuthorityId; + @Indexed + private String schoolNumber; + private String faxNumber; + private String phoneNumber; + private String email; + private String website; + @Indexed + private String displayName; + private String displayNameNoSpecialChars; + private String schoolReportingRequirementCode; + private String schoolOrganizationCode; + @Indexed + private String schoolCategoryCode; + private String facilityTypeCode; + private String openedDate; + private String closedDate; + @Indexed + private boolean canIssueTranscripts; + @Indexed + private boolean canIssueCertificates; + private String createUser; + private String updateUser; + private String createDate; + private String updateDate; +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolFundingGroupCodeEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolFundingGroupCodeEntity.java new file mode 100644 index 00000000..5fcdd616 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolFundingGroupCodeEntity.java @@ -0,0 +1,22 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("SchoolFundingGroupCode") +public class SchoolFundingGroupCodeEntity { + + @Id + private String schoolFundingGroupCode; + private String label; + private String description; + private String displayOrder; + private String effectiveDate; + private String expiryDate; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolFundingGroupEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolFundingGroupEntity.java new file mode 100644 index 00000000..86334a60 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolFundingGroupEntity.java @@ -0,0 +1,28 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("SchoolFundingGroup") +public class SchoolFundingGroupEntity { + + @Id + private String schoolFundingGroupID; + @Indexed + private String schoolId; + @Indexed + private String schoolGradeCode; + @Indexed + private String schoolFundingGroupCode; + private String createUser; + private String updateUser; + private String createDate; + private String updateDate; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolMoveEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolMoveEntity.java new file mode 100644 index 00000000..1186dc9b --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolMoveEntity.java @@ -0,0 +1,28 @@ +package ca.bc.gov.educ.api.trax.model.entity.institute; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@RedisHash("Note") +public class SchoolMoveEntity { + + @Id + private String schoolMoveId; + @Indexed + private String toSchoolId; + @Indexed + private String fromSchoolId; + @Indexed + private String moveDate; + private String createUser; + private String updateUser; + private String createDate; + private String updateDate; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/DistrictTransformer.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/DistrictTransformer.java new file mode 100644 index 00000000..83e5d44c --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/DistrictTransformer.java @@ -0,0 +1,42 @@ +package ca.bc.gov.educ.api.trax.model.transformer.institute; + +import ca.bc.gov.educ.api.trax.model.dto.institute.District; +import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictEntity; +import org.modelmapper.ModelMapper; +import org.modelmapper.TypeToken; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component("InstituteDistrictTransformer") +public class DistrictTransformer { + + @Autowired + ModelMapper modelMapper; + + public District transformToDTO (DistrictEntity districtEntity) { + return modelMapper.map(districtEntity, District.class); + } + + public District transformToDTO (Optional districtEntity ) { + if (districtEntity.isPresent()) { + DistrictEntity de = districtEntity.get(); + return modelMapper.map(de, District.class); + } + return null; + } + + public List transformToDTO (Iterable districtEntities ) { + return modelMapper.map(districtEntities, new TypeToken>(){}.getType()); + } + + public DistrictEntity transformToEntity(District district) { + return modelMapper.map(district, DistrictEntity.class); + } + + public List transformToEntity (Iterable districts ) { + return modelMapper.map(districts, new TypeToken>(){}.getType()); + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolCategoryCodeTransformer.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolCategoryCodeTransformer.java new file mode 100644 index 00000000..85a3a206 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolCategoryCodeTransformer.java @@ -0,0 +1,42 @@ +package ca.bc.gov.educ.api.trax.model.transformer.institute; + +import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolCategoryCode; +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolCategoryCodeEntity; +import org.modelmapper.ModelMapper; +import org.modelmapper.TypeToken; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component("SchoolCategoryCodeTransformer") +public class SchoolCategoryCodeTransformer { + + @Autowired + ModelMapper modelMapper; + + public SchoolCategoryCode transformToDTO (SchoolCategoryCodeEntity schoolCategoryCodeEntity) { + return modelMapper.map(schoolCategoryCodeEntity, SchoolCategoryCode.class); + } + + public SchoolCategoryCode transformToDTO (Optional schoolCategoryCodeEntity ) { + if (schoolCategoryCodeEntity.isPresent()) { + SchoolCategoryCodeEntity scce = schoolCategoryCodeEntity.get(); + return modelMapper.map(scce, SchoolCategoryCode.class); + } + return null; + } + + public List transformToDTO (Iterable schoolCategoryCodeEntities ) { + return modelMapper.map(schoolCategoryCodeEntities, new TypeToken>(){}.getType()); + } + + public SchoolCategoryCodeEntity transformToEntity(SchoolCategoryCode schoolCategoryCode) { + return modelMapper.map(schoolCategoryCode, SchoolCategoryCodeEntity.class); + } + + public List transformToEntity (Iterable schoolCategoryCodes ) { + return modelMapper.map(schoolCategoryCodes, new TypeToken>(){}.getType()); + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolFundingGroupCodeTransformer.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolFundingGroupCodeTransformer.java new file mode 100644 index 00000000..899b3423 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolFundingGroupCodeTransformer.java @@ -0,0 +1,44 @@ +package ca.bc.gov.educ.api.trax.model.transformer.institute; + +import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolCategoryCode; +import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolFundingGroupCode; +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolCategoryCodeEntity; +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolFundingGroupCodeEntity; +import org.modelmapper.ModelMapper; +import org.modelmapper.TypeToken; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component("SchoolFundingGroupCodeTransformer") +public class SchoolFundingGroupCodeTransformer { + + @Autowired + ModelMapper modelMapper; + + public SchoolFundingGroupCode transformToDTO (SchoolFundingGroupCodeEntity schoolFundingGroupCodeEntity) { + return modelMapper.map(schoolFundingGroupCodeEntity, SchoolFundingGroupCode.class); + } + + public SchoolFundingGroupCode transformToDTO (Optional schoolFundingGroupCodeEntity ) { + if (schoolFundingGroupCodeEntity.isPresent()) { + SchoolFundingGroupCodeEntity sfgce = schoolFundingGroupCodeEntity.get(); + return modelMapper.map(sfgce, SchoolFundingGroupCode.class); + } + return null; + } + + public List transformToDTO (Iterable schoolFundingGroupCodeEntities ) { + return modelMapper.map(schoolFundingGroupCodeEntities, new TypeToken>(){}.getType()); + } + + public SchoolFundingGroupCodeEntity transformToEntity(SchoolFundingGroupCode schoolFundingGroupCode) { + return modelMapper.map(schoolFundingGroupCode, SchoolFundingGroupCodeEntity.class); + } + + public List transformToEntity (Iterable schoolFundingGroupCodes ) { + return modelMapper.map(schoolFundingGroupCodes, new TypeToken>(){}.getType()); + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolTransformer.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolTransformer.java new file mode 100644 index 00000000..8978222b --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolTransformer.java @@ -0,0 +1,41 @@ +package ca.bc.gov.educ.api.trax.model.transformer.institute; + +import ca.bc.gov.educ.api.trax.model.dto.institute.School; +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolEntity; +import org.modelmapper.ModelMapper; +import org.modelmapper.TypeToken; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Optional; + +@Component("InstituteSchoolTransformer") +public class SchoolTransformer { + + @Autowired + ModelMapper modelMapper; + + public School transformToDTO (SchoolEntity schoolEntity) { + return modelMapper.map(schoolEntity, School.class); + } + + public School transformToDTO (Optional schoolEntity ) { + if (schoolEntity.isPresent()) { + SchoolEntity ie = schoolEntity.get(); + return modelMapper.map(ie, School.class); + } + return null; + } + + public List transformToDTO (Iterable schoolEntities ) { + return modelMapper.map(schoolEntities, new TypeToken>(){}.getType()); + } + + public SchoolEntity transformToEntity(School school) { + return modelMapper.map(school, SchoolEntity.class); + } + + public List transformToEntity (Iterable schools ) { + return modelMapper.map(schools, new TypeToken>(){}.getType()); + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/DistrictRedisRepository.java b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/DistrictRedisRepository.java new file mode 100644 index 00000000..b0a9d1e4 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/DistrictRedisRepository.java @@ -0,0 +1,10 @@ +package ca.bc.gov.educ.api.trax.repository.redis; + +import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictEntity; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface DistrictRedisRepository extends CrudRepository { + String HASH_KEY = "District"; +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolCategoryCodeRedisRepository.java b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolCategoryCodeRedisRepository.java new file mode 100644 index 00000000..5f281e3d --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolCategoryCodeRedisRepository.java @@ -0,0 +1,10 @@ +package ca.bc.gov.educ.api.trax.repository.redis; + +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolCategoryCodeEntity; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SchoolCategoryCodeRedisRepository extends CrudRepository { + String HASH_KEY = "SchoolCategoryCode"; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolFundingGroupCodeRedisRepository.java b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolFundingGroupCodeRedisRepository.java new file mode 100644 index 00000000..6aa6c911 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolFundingGroupCodeRedisRepository.java @@ -0,0 +1,10 @@ +package ca.bc.gov.educ.api.trax.repository.redis; + +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolFundingGroupCodeEntity; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SchoolFundingGroupCodeRedisRepository extends CrudRepository { + String HASH_KEY = "SchoolFundingGroupCode"; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolRedisRepository.java b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolRedisRepository.java new file mode 100644 index 00000000..4df623d3 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolRedisRepository.java @@ -0,0 +1,10 @@ +package ca.bc.gov.educ.api.trax.repository.redis; + +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolEntity; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SchoolRedisRepository extends CrudRepository { + String HASH_KEY = "School"; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/CodeService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/CodeService.java index e492228e..f945230c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/CodeService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/CodeService.java @@ -8,6 +8,7 @@ import ca.bc.gov.educ.api.trax.model.transformer.GradProvinceTransformer; import ca.bc.gov.educ.api.trax.repository.GradCountryRepository; import ca.bc.gov.educ.api.trax.repository.GradProvinceRepository; +import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; import ca.bc.gov.educ.api.trax.util.GradValidation; import jakarta.transaction.Transactional; import org.apache.commons.lang3.StringUtils; @@ -16,10 +17,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; - import java.util.List; import java.util.Optional; +import ca.bc.gov.educ.api.trax.util.RestUtils; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Service public class CodeService { @@ -37,9 +40,15 @@ public class CodeService { @Autowired GradValidation validation; - + + @Autowired + private EducGradTraxApiConstants constants; + + @Autowired + private WebClient webClient; + @Autowired - WebClient webClient; + private RestUtils restUtils; private static Logger logger = LoggerFactory.getLogger(CodeService.class); private static final String EXCEPTION_MSG = "Exception: %s"; diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/CodeService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/CodeService.java new file mode 100644 index 00000000..37b2be65 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/CodeService.java @@ -0,0 +1,102 @@ +package ca.bc.gov.educ.api.trax.service.institute; + +import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolCategoryCode; +import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolFundingGroupCode; +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolCategoryCodeEntity; +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolFundingGroupCodeEntity; +import ca.bc.gov.educ.api.trax.model.transformer.institute.SchoolCategoryCodeTransformer; +import ca.bc.gov.educ.api.trax.model.transformer.institute.SchoolFundingGroupCodeTransformer; +import ca.bc.gov.educ.api.trax.repository.redis.SchoolCategoryCodeRedisRepository; +import ca.bc.gov.educ.api.trax.repository.redis.SchoolFundingGroupCodeRedisRepository; +import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; +import ca.bc.gov.educ.api.trax.util.RestUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientResponseException; + +import java.util.List; + +@Slf4j +@Service("InstituteCodeService") +public class CodeService { + + @Autowired + private EducGradTraxApiConstants constants; + @Autowired + private WebClient webClient; + @Autowired + SchoolCategoryCodeRedisRepository schoolCategoryCodeRedisRepository; + @Autowired + SchoolFundingGroupCodeRedisRepository schoolFundingGroupCodeRedisRepository; + @Autowired + SchoolCategoryCodeTransformer schoolCategoryCodeTransformer; + @Autowired + SchoolFundingGroupCodeTransformer schoolFundingGroupCodeTransformer; + @Autowired + private RestUtils restUtils; + + public List getSchoolCategoryCodesFromInstituteApi() { + try { + log.debug("****Before Calling Institute API"); + List schoolCategoryCodes = + webClient.get() + .uri(constants.getAllSchoolCategoryCodesFromInstituteApiUrl()) + .headers(h -> { + h.setBearerAuth(restUtils.getTokenResponseObject( + constants.getInstituteClientId(), + constants.getInstituteClientSecret() + ).getAccess_token()); + }) + .retrieve() + .bodyToMono(new ParameterizedTypeReference>() { + }).block(); + assert schoolCategoryCodes != null; + log.debug("# of School Category Codes: " + schoolCategoryCodes.size()); + return schoolCategoryCodeTransformer.transformToDTO(schoolCategoryCodes); + } catch (WebClientResponseException e) { + log.warn(String.format("Error getting School Category Codes: %s", e.getMessage())); + } catch (Exception e) { + log.error(String.format("Error while calling school-api: %s", e.getMessage())); + } + return null; + } + + public void loadSchoolCategoryCodesIntoRedisCache(List schoolCategoryCodes) { + schoolCategoryCodeRedisRepository + .saveAll(schoolCategoryCodeTransformer.transformToEntity(schoolCategoryCodes)); + } + + public List getSchoolFundingGroupCodesFromInstituteApi() { + try { + log.debug("****Before Calling Institute API"); + List schoolFundingGroupCodes; + schoolFundingGroupCodes = webClient.get() + .uri(constants.getAllSchoolFundingGroupCodesFromInstituteApiUrl()) + .headers(h -> { + h.setBearerAuth(restUtils.getTokenResponseObject( + constants.getInstituteClientId(), + constants.getInstituteClientSecret() + ).getAccess_token()); + }) + .retrieve() + .bodyToMono(new ParameterizedTypeReference>() { + }).block(); + //assert schoolFundingGroupCodes != null; + //log.debug("# of School Funding Group Codes: " + schoolFundingGroupCodes.size()); + return schoolFundingGroupCodeTransformer.transformToDTO(schoolFundingGroupCodes); + } catch (WebClientResponseException e) { + log.warn(String.format("Error getting School Funding Group Codes: %s", e.getMessage())); + } catch (Exception e) { + log.error(String.format("Error while calling school-api: %s", e.getMessage())); + } + return null; + } + + public void loadSchoolFundingGroupCodesIntoRedisCache(List schoolFundingGroupCodes) { + schoolFundingGroupCodeRedisRepository + .saveAll(schoolFundingGroupCodeTransformer.transformToEntity(schoolFundingGroupCodes)); + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/DistrictService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/DistrictService.java new file mode 100644 index 00000000..ca5b118c --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/DistrictService.java @@ -0,0 +1,61 @@ +package ca.bc.gov.educ.api.trax.service.institute; + +import ca.bc.gov.educ.api.trax.model.dto.institute.District; +import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictEntity; +import ca.bc.gov.educ.api.trax.model.transformer.institute.DistrictTransformer; +import ca.bc.gov.educ.api.trax.repository.redis.DistrictRedisRepository; +import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; +import ca.bc.gov.educ.api.trax.util.RestUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientResponseException; +import java.util.List; + +@Slf4j +@Service("InstituteDistrictService") +public class DistrictService { + + @Autowired + private EducGradTraxApiConstants constants; + @Autowired + private RestUtils restUtils; + @Autowired + private WebClient webClient; + @Autowired + DistrictRedisRepository districtRedisRepository; + @Autowired + DistrictTransformer districtTransformer; + + public List getDistrictsFromInstituteApi() { + try { + log.debug("****Before Calling Institute API"); + List districts = + webClient.get() + .uri(constants.getAllDistrictsFromInstituteApiUrl()) + .headers(h -> h.setBearerAuth(restUtils.getTokenResponseObject( + constants.getInstituteClientId(), + constants.getInstituteClientSecret() + ).getAccess_token())) + .retrieve() + .bodyToMono(new ParameterizedTypeReference>() { + }).block(); + //assert districts != null; + //log.debug("# of Districts: " + districts.size()); + return districtTransformer.transformToDTO(districts); + } catch (WebClientResponseException e) { + log.warn(String.format("Error getting Common School List: %s", e.getMessage())); + } catch (Exception e) { + log.error(String.format("Error while calling school-api: %s", e.getMessage())); + } + return null; + } + + public void loadDistrictsIntoRedisCache(List districts) { + districtRedisRepository + .saveAll(districtTransformer.transformToEntity(districts)); + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolService.java new file mode 100644 index 00000000..b1f12857 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolService.java @@ -0,0 +1,118 @@ +package ca.bc.gov.educ.api.trax.service.institute; + +import ca.bc.gov.educ.api.trax.model.dto.institute.School; +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolEntity; +import ca.bc.gov.educ.api.trax.model.transformer.institute.SchoolTransformer; +import ca.bc.gov.educ.api.trax.repository.redis.SchoolRedisRepository; +import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; +import ca.bc.gov.educ.api.trax.util.RestUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientResponseException; + +import java.util.List; + +@Slf4j +@Service("InstituteSchoolService") +public class SchoolService { + + @Autowired + private EducGradTraxApiConstants constants; + + @Autowired + private WebClient webClient; + + @Autowired + SchoolRedisRepository schoolRedisRepository; + + @Autowired + SchoolTransformer schoolTransformer; + + @Autowired + private RestUtils restUtils; + + public List getSchoolsFromInstituteApi() { + try { + log.debug("****Before Calling Institute API"); + List schools; + schools = webClient.get() + .uri(constants.getAllSchoolsFromInstituteApiUrl()) + .headers(h -> { + h.setBearerAuth(restUtils.getTokenResponseObject( + constants.getInstituteClientId(), + constants.getInstituteClientSecret() + ).getAccess_token()); + }) + .retrieve() + .bodyToMono(new ParameterizedTypeReference>(){}).block(); + //assert schools != null; + //log.debug("# of Schools: " + schools.size()); + return schoolTransformer.transformToDTO(schools); + } catch (WebClientResponseException e) { + log.warn(String.format("Error getting Common School List: %s", e.getMessage())); + } catch (Exception e) { + log.error(String.format("Error while calling school-api: %s", e.getMessage())); + } + return null; + } + + public void loadSchoolsIntoRedisCache(List schools) { + schoolRedisRepository + .saveAll(schoolTransformer.transformToEntity(schools)); + } + + /*public SchoolDetail getCommonSchoolDetailById(String schoolId, String accessToken) { + try { + return webClient.get().uri( + String.format(constants.getSchoolDetailsByIdFromInstituteApiUrl(), schoolId)) + .headers(h -> { + h.setBearerAuth(accessToken); + }) + .retrieve().bodyToMono(SchoolDetail.class).block(); + } catch (WebClientResponseException e) { + logger.warn("Error getting Common School Details"); + } catch (Exception e) { + logger.error(String.format("Error while calling school-api: %s", e.getMessage())); + } + return null; + }*/ + + /*public List getAllSchoolDetails() { + + String accessToken = getAccessToken(); + List schools = getCommonSchools(accessToken); + List schoolDetails = new ArrayList(); + Address address = new Address(); + int counter = 1; + + for (School s : schools) { + SchoolDetail sd = new SchoolDetail(); + + if (counter%100 == 0) + accessToken = getAccessToken(); + sd = getCommonSchoolDetailById(s.getSchoolId(), accessToken); + + address = null; + if (sd.getAddresses() == null || sd.getAddresses().isEmpty()) { + logger.debug("," + sd.getMincode() + "," + "," + "," + "," + "," + "," + "," + ","); + } else { + address = sd.getAddresses().get(0); + logger.debug("," + sd.getMincode() + "," + + sd.getAddresses().get(0).getAddressLine1() + "," + + sd.getAddresses().get(0).getAddressLine2() + "," + + sd.getAddresses().get(0).getCity() + "," + + sd.getAddresses().get(0).getProvinceCode() + "," + + sd.getAddresses().get(0).getCountryCode() + "," + + sd.getAddresses().get(0).getPostal() + "," + + sd.getAddresses().get(0).getAddressTypeCode() + "," + ); + } + schoolDetails.add(sd); + counter++; + } + return schoolDetails; + }*/ +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java index c0198cb3..6546dff2 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java @@ -23,21 +23,29 @@ public class EducGradTraxApiConstants { public static final String CORRELATION_ID = "correlationID"; //API end-point Mapping constants - public static final String API_ROOT_MAPPING = ""; - public static final String API_VERSION = "v1"; + public static final String API_VERSION_V1 = "/api/v1"; + public static final String API_VERSION_V2 = "/api/v2"; // API Root Mapping - public static final String GRAD_TRAX_API_ROOT_MAPPING = "/api/" + API_VERSION+"/trax"; + public static final String GRAD_TRAX_API_ROOT_MAPPING_V1 = API_VERSION_V1+"/trax"; + public static final String GRAD_TRAX_API_ROOT_MAPPING_V2 = API_VERSION_V2+"/trax"; // Controller Mappings public static final String GET_COMMON_SCHOOLS = "/common"; - public static final String GRAD_TRAX_CODE_URL_MAPPING = GRAD_TRAX_API_ROOT_MAPPING + "/code"; - public static final String GRAD_SCHOOL_URL_MAPPING = GRAD_TRAX_API_ROOT_MAPPING + "/school"; - public static final String GRAD_DISTRICT_URL_MAPPING = GRAD_TRAX_API_ROOT_MAPPING + "/district"; - public static final String GRAD_PSI_URL_MAPPING = GRAD_TRAX_API_ROOT_MAPPING + "/psi"; - public static final String GRAD_TRAX_COMMON_URL_MAPPING = GRAD_TRAX_API_ROOT_MAPPING + GET_COMMON_SCHOOLS; - public static final String GRAD_TSW_URL_MAPPING = GRAD_TRAX_API_ROOT_MAPPING + "/tsw"; - public static final String GRAD_EDW_URL_MAPPING = GRAD_TRAX_API_ROOT_MAPPING + "/edw"; + public static final String GRAD_TRAX_CODE_URL_MAPPING_V1 = GRAD_TRAX_API_ROOT_MAPPING_V1 + "/code"; + public static final String GRAD_TRAX_CODE_URL_MAPPING_V2 = GRAD_TRAX_API_ROOT_MAPPING_V2 + "/code"; + public static final String GRAD_SCHOOL_URL_MAPPING_V1 = GRAD_TRAX_API_ROOT_MAPPING_V1 + "/school"; + public static final String GRAD_SCHOOL_URL_MAPPING_V2 = GRAD_TRAX_API_ROOT_MAPPING_V2 + "/school"; + public static final String GRAD_DISTRICT_URL_MAPPING_V1 = GRAD_TRAX_API_ROOT_MAPPING_V1 + "/district"; + public static final String GRAD_DISTRICT_URL_MAPPING_V2 = GRAD_TRAX_API_ROOT_MAPPING_V2 + "/district"; + public static final String GRAD_PSI_URL_MAPPING_V1 = GRAD_TRAX_API_ROOT_MAPPING_V1 + "/psi"; + public static final String GRAD_PSI_URL_MAPPING_V2 = GRAD_TRAX_API_ROOT_MAPPING_V2 + "/psi"; + public static final String GRAD_TRAX_COMMON_URL_MAPPING_V1 = GRAD_TRAX_API_ROOT_MAPPING_V1 + GET_COMMON_SCHOOLS; + public static final String GRAD_TRAX_COMMON_URL_MAPPING_V2 = GRAD_TRAX_API_ROOT_MAPPING_V2 + GET_COMMON_SCHOOLS; + public static final String GRAD_TSW_URL_MAPPING_V1 = GRAD_TRAX_API_ROOT_MAPPING_V1 + "/tsw"; + public static final String GRAD_TSW_URL_MAPPING_V2 = GRAD_TRAX_API_ROOT_MAPPING_V2 + "/tsw"; + public static final String GRAD_EDW_URL_MAPPING_V1 = GRAD_TRAX_API_ROOT_MAPPING_V1 + "/edw"; + public static final String GRAD_EDW_URL_MAPPING_V2 = GRAD_TRAX_API_ROOT_MAPPING_V2 + "/edw"; // Service Methods Mappings @@ -100,6 +108,12 @@ public class EducGradTraxApiConstants { @Value("${endpoint.keycloak.getToken}") private String tokenUrl; + @Value("${authorization.institute-api.client-id}") + private String instituteClientId; + + @Value("${authorization.institute-api.client-secret}") + private String instituteClientSecret; + //NAT /** * The Server. @@ -117,6 +131,12 @@ public class EducGradTraxApiConstants { @Value("${nats.connectionName}") private String connectionName; + @Value("${redis.url}") + private String redisUrl; + + @Value("${redis.port}") + private String redisPort; + // Incremental Trax Update @Value("${trax.update.enabled}") private boolean traxUpdateEnabled; @@ -131,6 +151,21 @@ public class EducGradTraxApiConstants { @Value("${endpoint.educ-school-api.get-all-schools.url}") private String allSchoolSchoolApiUrl; + @Value("${endpoint.institute-api.get-all-schools.url}") + private String allSchoolsFromInstituteApiUrl; + + @Value("${endpoint.institute-api.get-school-details-by-id.url}") + private String schoolDetailsByIdFromInstituteApiUrl; + + @Value("${endpoint.institute-api.get-all-districts.url}") + private String allDistrictsFromInstituteApiUrl; + + @Value("${endpoint.institute-api.get-all-school-category-codes.url}") + private String allSchoolCategoryCodesFromInstituteApiUrl; + + @Value("${endpoint.institute-api.get-all-school-funding-group-codes.url}") + private String allSchoolFundingGroupCodesFromInstituteApiUrl; + // Scheduler: ongoing updates from TRAX to GRAD @Value("${cron.scheduled.process.events.trax-to-grad.run}") private String traxToGradCronRun; diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/util/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/api/trax/util/RestUtils.java index dc73ba38..f46cce3c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/util/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/util/RestUtils.java @@ -41,8 +41,23 @@ public ResponseObj getTokenResponseObject() { .bodyToMono(ResponseObj.class).block(); } + @Retry(name = "rt-getToken-institute", fallbackMethod = "rtGetTokenFallback") + public ResponseObj getTokenResponseObject(String clientId, String clientSecret) { + log.info("Fetching the Institute api access token from KeyCloak."); + HttpHeaders httpHeadersKC = EducGradTraxApiUtils.getHeaders( + clientId, clientSecret); + MultiValueMap map= new LinkedMultiValueMap<>(); + map.add("grant_type", "client_credentials"); + return this.webClient.post().uri(constants.getTokenUrl()) + .headers(h -> h.addAll(httpHeadersKC)) + .contentType(MediaType.APPLICATION_FORM_URLENCODED) + .body(BodyInserters.fromFormData(map)) + .retrieve() + .bodyToMono(ResponseObj.class).block(); + } + public ResponseObj rtGetTokenFallBack(HttpServerErrorException exception){ - log.error("{} NOT REACHABLE after many attempts: {}", constants.getTokenUrl(), exception); + log.error("{} NOT REACHABLE after many attempts: {}", constants.getTokenUrl(), exception.getMessage()); return null; } } diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index 62567dd3..dd29d4d3 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -1,5 +1,6 @@ -#DB Properties spring: + #main: + # allow-bean-definition-overriding: true jmx: enabled: false datasource: @@ -114,6 +115,9 @@ resilience4j.retry: authorization: user: ${GRAD_CLIENT_NAME} password: ${GRAD_CLIENT_SECRET} + institute-api: + client-id: ${EDX_GRAD_CLIENT_NAME} + client-secret: ${EDX_GRAD_CLIENT_SECRET} #NATS nats: @@ -121,6 +125,11 @@ nats: maxReconnect: ${NATS_MAX_RECONNECT} connectionName: GRAD-TRAX-API +#Redis +redis: + url: ${REDIS_URL} + port: ${REDIS_PORT} + #Scheduler cron: scheduled: @@ -165,6 +174,17 @@ endpoint: url: ${EDUC_SCHOOL_API}api/v1/schools/%s get-all-schools: url: ${EDUC_SCHOOL_API}api/v1/schools + institute-api: + get-all-schools: + url: ${INSTITUTE_API_URL_ROOT}api/v1/institute/school + get-school-details-by-id: + url: ${INSTITUTE_API_URL_ROOT}api/v1/institute/school/%s + get-all-districts: + url: ${INSTITUTE_API_URL_ROOT}api/v1/institute/district + get-all-school-category-codes: + url: ${INSTITUTE_API_URL_ROOT}api/v1/institute/category-codes + get-all-school-funding-group-codes: + url: ${INSTITUTE_API_URL_ROOT}api/v1/institute/funding-group-codes # other properties props: diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteCodeServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteCodeServiceTest.java new file mode 100644 index 00000000..9ad65608 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteCodeServiceTest.java @@ -0,0 +1,203 @@ +package ca.bc.gov.educ.api.trax.service.institute; + +import ca.bc.gov.educ.api.trax.messaging.NatsConnection; +import ca.bc.gov.educ.api.trax.messaging.jetstream.Publisher; +import ca.bc.gov.educ.api.trax.messaging.jetstream.Subscriber; +import ca.bc.gov.educ.api.trax.model.dto.ResponseObj; +import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolCategoryCode; +import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolFundingGroupCode; +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolCategoryCodeEntity; +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolFundingGroupCodeEntity; +import ca.bc.gov.educ.api.trax.repository.GradCountryRepository; +import ca.bc.gov.educ.api.trax.repository.GradProvinceRepository; +import ca.bc.gov.educ.api.trax.repository.redis.SchoolFundingGroupCodeRedisRepository; +import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; +import ca.bc.gov.educ.api.trax.util.RestUtils; +import org.junit.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Bean; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpHeaders; +import org.springframework.security.oauth2.client.registration.ClientRegistration; +import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; + +@RunWith(SpringRunner.class) +@SpringBootTest +@ActiveProfiles("test") +@ExtendWith(MockitoExtension.class) +@SuppressWarnings({"unchecked","rawtypes"}) +public class InstituteCodeServiceTest { + + @Autowired + private EducGradTraxApiConstants constants; + @Autowired + private CodeService codeService; + @MockBean + private SchoolFundingGroupCodeRedisRepository schoolFundingGroupCodeRedisRepository; + @MockBean + private GradCountryRepository gradCountryRepository; + + @MockBean + private GradProvinceRepository gradProvinceRepository; + + @MockBean + @Qualifier("default") + WebClient webClientMock; + @Mock + private WebClient.RequestHeadersSpec requestHeadersSpecMock; + @Mock + private WebClient.RequestHeadersUriSpec requestHeadersUriSpecMock; + @Mock + private WebClient.ResponseSpec responseSpecMock; + @Mock + private HttpHeaders httpHeadersMock; + @Mock + private ResponseObj responseObjectMock; + @Mock + private Mono> schoolCategoryCodeEntitiesMock; + @Mock + private Mono> schoolFundingGroupCodeEntitiesMock; + @MockBean + private RestUtils restUtilsMock; + + // NATS + @MockBean + private NatsConnection natsConnection; + + @MockBean + private Publisher publisher; + + @MockBean + private Subscriber subscriber; + + @TestConfiguration + static class TestConfigInstitute { + @Bean + public ClientRegistrationRepository clientRegistrationRepository() { + return new ClientRegistrationRepository() { + @Override + public ClientRegistration findByRegistrationId(String registrationId) { + return null; + } + }; + } + } + + @Test + public void whenGetSchoolCategoryCodesFromInstituteApi_returnsListOfSchoolCategoryCodeEntity() { + List schoolCategoryCodes = new ArrayList<>(); + SchoolCategoryCodeEntity scce = new SchoolCategoryCodeEntity(); + + scce.setSchoolCategoryCode("11"); + scce.setDescription("Description"); + scce.setLegacyCode("LegacyCode"); + scce.setLabel("Label"); + scce.setEffectiveDate("01-01-2024"); + scce.setExpiryDate("01-01-2024"); + scce.setDisplayOrder("10"); + schoolCategoryCodes.add(scce); + + ResponseObj tokenObj = new ResponseObj(); + tokenObj.setAccess_token("123"); + + when(webClientMock.get()) + .thenReturn(requestHeadersUriSpecMock); + when(requestHeadersUriSpecMock.uri(anyString())) + .thenReturn(requestHeadersSpecMock); + when(this.restUtilsMock.getTokenResponseObject(anyString(), anyString())) + .thenReturn(tokenObj); + when(this.responseObjectMock.getAccess_token()) + .thenReturn("accessToken"); + when(requestHeadersSpecMock.retrieve()) + .thenReturn(responseSpecMock); + when(this.responseSpecMock.bodyToMono(new ParameterizedTypeReference>(){})) + .thenReturn(schoolCategoryCodeEntitiesMock); + when(this.schoolCategoryCodeEntitiesMock.block()) + .thenReturn(schoolCategoryCodes); + + List result = codeService.getSchoolCategoryCodesFromInstituteApi(); + //assertThat(result).hasSize(1); + } + + @Test + public void whenGetSchoolFundingGroupCodesFromInstituteApi_returnsListOfSchoolFundingGroupCodeEntity() { + List schoolFundingGroupCodes = new ArrayList<>(); + SchoolFundingGroupCodeEntity sfgc = new SchoolFundingGroupCodeEntity(); + + sfgc.setSchoolFundingGroupCode("CODE"); + sfgc.setDescription("Description"); + sfgc.setLabel("Label"); + sfgc.setEffectiveDate("01-01-2024"); + sfgc.setExpiryDate("01-01-2024"); + sfgc.setDisplayOrder("10"); + schoolFundingGroupCodes.add(sfgc); + + ResponseObj tokenObj = new ResponseObj(); + tokenObj.setAccess_token("123"); + + ParameterizedTypeReference> schoolFundingGroupCodeEntityType = + new ParameterizedTypeReference>() {}; + + when(webClientMock.get()) + .thenReturn(this.requestHeadersUriSpecMock); + when(requestHeadersUriSpecMock.uri(anyString())) + .thenReturn(this.requestHeadersSpecMock); + when(this.restUtilsMock.getTokenResponseObject(anyString(), anyString())) + .thenReturn(tokenObj); + when(this.responseObjectMock.getAccess_token()) + .thenReturn("accessToken"); + when(this.requestHeadersSpecMock.headers(any(Consumer.class))) + .thenReturn(this.requestHeadersSpecMock); + when(requestHeadersSpecMock.retrieve()) + .thenReturn(this.responseSpecMock); + when(this.responseSpecMock.bodyToMono(schoolFundingGroupCodeEntityType)) + .thenReturn(Mono.just(schoolFundingGroupCodes)); + when(this.schoolFundingGroupCodeEntitiesMock.block()) + .thenReturn(schoolFundingGroupCodes); + + List result = codeService.getSchoolFundingGroupCodesFromInstituteApi(); + //assertThat(result).hasSize(1); + } + + @Test + public void whenLoadSchoolCategoryCodesIntoRedisCache_DoesNotThrow() { + List schoolFundingGroupCodeEntities = Arrays.asList(new SchoolFundingGroupCodeEntity()); + List schoolFundingGroupCodes = Arrays.asList(new SchoolFundingGroupCode()); + when(this.schoolFundingGroupCodeRedisRepository.saveAll(schoolFundingGroupCodeEntities)) + .thenReturn(schoolFundingGroupCodeEntities); + assertDoesNotThrow(() -> codeService.loadSchoolFundingGroupCodesIntoRedisCache(schoolFundingGroupCodes)); + } + + @Test + public void whenLoadSchoolFundingGroupCodesIntoRedisCache_DoesNotThrow() { + List schoolFundingGroupCodeEntities = Arrays.asList(new SchoolFundingGroupCodeEntity()); + List schoolFundingGroupCodes = Arrays.asList(new SchoolFundingGroupCode()); + when(this.schoolFundingGroupCodeRedisRepository.saveAll(schoolFundingGroupCodeEntities)) + .thenReturn(schoolFundingGroupCodeEntities); + assertDoesNotThrow(() -> codeService.loadSchoolFundingGroupCodesIntoRedisCache(schoolFundingGroupCodes)); + } +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteDistrictServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteDistrictServiceTest.java new file mode 100644 index 00000000..28395d61 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteDistrictServiceTest.java @@ -0,0 +1,154 @@ +package ca.bc.gov.educ.api.trax.service.institute; + +import ca.bc.gov.educ.api.trax.messaging.NatsConnection; +import ca.bc.gov.educ.api.trax.messaging.jetstream.Publisher; +import ca.bc.gov.educ.api.trax.messaging.jetstream.Subscriber; +import ca.bc.gov.educ.api.trax.model.dto.ResponseObj; +import ca.bc.gov.educ.api.trax.model.dto.institute.District; +import ca.bc.gov.educ.api.trax.model.dto.institute.DistrictContact; +import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictContactEntity; +import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictEntity; +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolCategoryCodeEntity; +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolFundingGroupCodeEntity; +import ca.bc.gov.educ.api.trax.model.transformer.institute.DistrictTransformer; +import ca.bc.gov.educ.api.trax.repository.GradCountryRepository; +import ca.bc.gov.educ.api.trax.repository.GradProvinceRepository; +import ca.bc.gov.educ.api.trax.repository.redis.DistrictRedisRepository; +import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; +import ca.bc.gov.educ.api.trax.util.RestUtils; +import org.junit.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Bean; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpHeaders; +import org.springframework.security.oauth2.client.registration.ClientRegistration; +import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + + +@RunWith(SpringRunner.class) +@SpringBootTest +@ActiveProfiles("test") +@ExtendWith(MockitoExtension.class) +@SuppressWarnings({"unchecked","rawtypes"}) +public class InstituteDistrictServiceTest { + + @Autowired + private EducGradTraxApiConstants constants; + @Autowired + private DistrictService districtService; + @MockBean + private DistrictRedisRepository districtRedisRepository; + + @MockBean + @Qualifier("default") + WebClient webClientMock; + @Mock + private WebClient.RequestHeadersSpec requestHeadersSpecMock; + @Mock + private WebClient.RequestHeadersUriSpec requestHeadersUriSpecMock; + @Mock + private WebClient.ResponseSpec responseSpecMock; + @Mock + private HttpHeaders httpHeadersMock; + @Mock + private ResponseObj responseObjectMock; + @Mock + private Mono> districtEntitiesMock; + @Mock + private List districtsMock; + @MockBean + private RestUtils restUtilsMock; + @MockBean + private DistrictTransformer districtTransformerMock; + + // NATS + @MockBean + private NatsConnection natsConnection; + + @MockBean + private Publisher publisher; + + @MockBean + private Subscriber subscriber; + + @TestConfiguration + static class TestConfigInstitute { + @Bean + public ClientRegistrationRepository clientRegistrationRepository() { + return new ClientRegistrationRepository() { + @Override + public ClientRegistration findByRegistrationId(String registrationId) { + return null; + } + }; + } + } + + @Test + public void whenGetDistrictsFromInstituteApi_returnsListOfDistricts() { + List districts = new ArrayList<>(); + DistrictEntity district = new DistrictEntity(); + + district.setDistrictId("ID"); + district.setDistrictNumber("1234"); + district.setDistrictStatusCode("SC"); + district.setDistrictRegionCode("RC"); + district.setContacts(Arrays.asList(new DistrictContactEntity(), new DistrictContactEntity())); + + districts.add(district); + + ResponseObj tokenObj = new ResponseObj(); + tokenObj.setAccess_token("123"); + + when(webClientMock.get()) + .thenReturn(requestHeadersUriSpecMock); + when(requestHeadersUriSpecMock.uri(anyString())) + .thenReturn(requestHeadersSpecMock); + when(this.restUtilsMock.getTokenResponseObject(anyString(), anyString())) + .thenReturn(tokenObj); + when(this.responseObjectMock.getAccess_token()) + .thenReturn("AccessToken"); + when(this.requestHeadersSpecMock.retrieve()) + .thenReturn(responseSpecMock); + when(this.responseSpecMock.bodyToMono(new ParameterizedTypeReference>(){})) + .thenReturn(districtEntitiesMock); + when(this.districtEntitiesMock.block()).thenReturn(districts); + + when(this.districtTransformerMock.transformToDTO(districts)) + .thenReturn(districtsMock); + + List result = districtService.getDistrictsFromInstituteApi(); + } + + @Test + public void whenLoadDistrictsIntoRedisCache_DoesNotThrow() { + List districtEntities = Arrays.asList(new DistrictEntity()); + List districts = Arrays.asList(new District()); + when(this.districtRedisRepository.saveAll(districtEntities)) + .thenReturn(districtEntities); + assertDoesNotThrow(() -> districtService.loadDistrictsIntoRedisCache(districts)); + } +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java new file mode 100644 index 00000000..138305c5 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java @@ -0,0 +1,150 @@ +package ca.bc.gov.educ.api.trax.service.institute; + +import ca.bc.gov.educ.api.trax.messaging.NatsConnection; +import ca.bc.gov.educ.api.trax.messaging.jetstream.Publisher; +import ca.bc.gov.educ.api.trax.messaging.jetstream.Subscriber; +import ca.bc.gov.educ.api.trax.model.dto.ResponseObj; +import ca.bc.gov.educ.api.trax.model.dto.institute.District; +import ca.bc.gov.educ.api.trax.model.dto.institute.School; +import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictContactEntity; +import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictEntity; +import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolEntity; +import ca.bc.gov.educ.api.trax.model.transformer.institute.DistrictTransformer; +import ca.bc.gov.educ.api.trax.model.transformer.institute.SchoolTransformer; +import ca.bc.gov.educ.api.trax.repository.GradCountryRepository; +import ca.bc.gov.educ.api.trax.repository.GradProvinceRepository; +import ca.bc.gov.educ.api.trax.repository.redis.SchoolRedisRepository; +import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; +import ca.bc.gov.educ.api.trax.util.RestUtils; +import org.junit.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Bean; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpHeaders; +import org.springframework.security.oauth2.client.registration.ClientRegistration; +import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + + +@RunWith(SpringRunner.class) +@SpringBootTest +@ActiveProfiles("test") +@ExtendWith(MockitoExtension.class) +@SuppressWarnings({"unchecked","rawtypes"}) +public class InstituteSchoolServiceTest { + + @Autowired + private EducGradTraxApiConstants constants; + @Autowired + private SchoolService schoolService; + @MockBean + private SchoolRedisRepository schoolRedisRepository; + @MockBean + @Qualifier("default") + WebClient webClientMock; + @Mock + private WebClient.RequestHeadersSpec requestHeadersSpecMock; + @Mock + private WebClient.RequestHeadersUriSpec requestHeadersUriSpecMock; + @Mock + private WebClient.ResponseSpec responseSpecMock; + @Mock + private HttpHeaders httpHeadersMock; + @Mock + private ResponseObj responseObjectMock; + @Mock + private Mono> schoolEntitiesMock; + @Mock + private List schoolsMock; + @MockBean + private RestUtils restUtilsMock; + @MockBean + private SchoolTransformer schoolTransformerMock; + + // NATS + @MockBean + private NatsConnection natsConnection; + + @MockBean + private Publisher publisher; + + @MockBean + private Subscriber subscriber; + + @TestConfiguration + static class TestConfigInstitute { + @Bean + public ClientRegistrationRepository clientRegistrationRepository() { + return new ClientRegistrationRepository() { + @Override + public ClientRegistration findByRegistrationId(String registrationId) { + return null; + } + }; + } + } + + @Test + public void whenGetSchoolsFromInstituteApi_returnsListOfSchools() { + List schools = new ArrayList<>(); + SchoolEntity school = new SchoolEntity(); + + school.setSchoolId("ID"); + school.setDistrictId("DistID"); + school.setSchoolNumber("12345"); + school.setSchoolCategoryCode("SCC"); + school.setEmail("abc@xyz.ca"); + + schools.add(school); + + ResponseObj tokenObj = new ResponseObj(); + tokenObj.setAccess_token("123"); + + when(webClientMock.get()) + .thenReturn(requestHeadersUriSpecMock); + when(requestHeadersUriSpecMock.uri(anyString())) + .thenReturn(requestHeadersSpecMock); + when(this.restUtilsMock.getTokenResponseObject(anyString(), anyString())) + .thenReturn(tokenObj); + when(this.responseObjectMock.getAccess_token()) + .thenReturn("AccessToken"); + when(this.requestHeadersSpecMock.retrieve()) + .thenReturn(responseSpecMock); + when(this.responseSpecMock.bodyToMono(new ParameterizedTypeReference>(){})) + .thenReturn(schoolEntitiesMock); + when(this.schoolEntitiesMock.block()).thenReturn(schools); + + when(this.schoolTransformerMock.transformToDTO(schools)) + .thenReturn(schoolsMock); + + List result = schoolService.getSchoolsFromInstituteApi(); + } + + @Test + public void whenLoadSchoolsIntoRedisCache_DoesNotThrow() { + List schoolEntities = Arrays.asList(new SchoolEntity()); + List schools = Arrays.asList(new School()); + when(this.schoolRedisRepository.saveAll(schoolEntities)) + .thenReturn(schoolEntities); + assertDoesNotThrow(() -> schoolService.loadSchoolsIntoRedisCache(schools)); + } +} diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index e0b0f8df..16e0b2bc 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -1,7 +1,5 @@ #DB Properties spring: - main: - allow-bean-definition-overriding: true jmx: enabled: false datasource: @@ -64,6 +62,9 @@ logging: authorization: user: batch-api password: abc + institute-api: + client-id: edx-grad-client-name + client-secret: xyz #NATS nats: @@ -71,6 +72,11 @@ nats: maxReconnect: 60 connectionName: GRAD-TRAX-API +#Redis +redis: + url: '127.0.0.1' + port: '6379' + #Scheduler cron: scheduled: @@ -109,12 +115,23 @@ splunk: #Endpoint properties endpoint: keycloak: - getToken: https://soam-tools.apps.silver.devops.gov.bc.ca/auth/realms/master/protocol/openid-connect/token + getToken: https://soam-dev.apps.silver.devops.gov.bc.ca/auth/realms/master/protocol/openid-connect/token educ-school-api: get-school-by-mincode: url: https://school-api-75e61b-dev.apps.silver.devops.gov.bc.ca/api/v1/schools/%s get-all-schools: url: https://school-api-75e61b-dev.apps.silver.devops.gov.bc.ca/api/v1/schools + institute-api: + get-all-schools: + url: https://school-api-75e61b-dev.apps.silver.devops.gov.bc.ca/api/v1/institute/school + get-school-details-by-id: + url: https://school-api-75e61b-dev.apps.silver.devops.gov.bc.ca/api/v1/institute/school/%s + get-all-districts: + url: https://school-api-75e61b-dev.apps.silver.devops.gov.bc.ca/api/v1/institute/district + get-all-school-category-codes: + url: https://school-api-75e61b-dev.apps.silver.devops.gov.bc.ca/api/v1/institute/category-codes + get-all-school-funding-group-codes: + url: https://school-api-75e61b-dev.apps.silver.devops.gov.bc.ca/api/v1/institute/funding-group-codes # other properties props: diff --git a/tools/config/update-configmap.sh b/tools/config/update-configmap.sh index 57312136..89aafec3 100644 --- a/tools/config/update-configmap.sh +++ b/tools/config/update-configmap.sh @@ -68,6 +68,7 @@ oc create -n "$GRAD_NAMESPACE"-"$envValue" configmap "$APP_NAME"-config-map \ --from-literal=ENABLE_FLYWAY="true" \ --from-literal=ENABLE_TRAX_UPDATE="true" \ --from-literal=KEYCLOAK_TOKEN_URL="https://soam-$envValue.apps.silver.devops.gov.bc.ca/" \ + --from-literal=INSTITUTE_API_URL_ROOT="https://institute-api-$COMMON_NAMESPACE.apps.silver.devops.gov.bc.ca/" \ --from-literal=MAX_RETRY_ATTEMPTS="3" \ --from-literal=SCHOOL_CACHE_EXPIRY_IN_MINS="240" \ --dry-run=client -o yaml | oc apply -f - diff --git a/tools/openshift/api.dc.yaml b/tools/openshift/api.dc.yaml index b0e4e269..55ba0f86 100644 --- a/tools/openshift/api.dc.yaml +++ b/tools/openshift/api.dc.yaml @@ -70,6 +70,10 @@ objects: name: grad-client-secret - secretRef: name: trax-client-secret + - secretRef: + name: edx-grad-client-secret + - secretRef: + name: redis-cache-secret resources: requests: cpu: "${MIN_CPU}"