Skip to content

Commit

Permalink
Merge branch 'grad-release' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kamal-mohammed authored Jun 14, 2024
2 parents d4b83bf + 9520c3e commit b11ae13
Show file tree
Hide file tree
Showing 55 changed files with 2,040 additions and 80 deletions.
15 changes: 15 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>


<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
Expand Down Expand Up @@ -221,6 +231,11 @@
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.client</artifactId>
<version>0.31</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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!");
}
}
41 changes: 41 additions & 0 deletions api/src/main/java/ca/bc/gov/educ/api/trax/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -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<String, Object> redisTemplate() {
final RedisTemplate<String, Object> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"),
Expand All @@ -33,8 +34,6 @@
})})
public class CodeController {

private static Logger logger = LoggerFactory.getLogger(CodeController.class);

@Autowired
CodeService codeService;

Expand All @@ -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<List<GradCountry>> 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<GradCountry> getSpecificCountryCode(@PathVariable String countryCode) {
logger.debug("getSpecificCountryCode : ");
log.debug("getSpecificCountryCode : ");
GradCountry gradResponse = codeService.getSpecificCountryCode(countryCode);
if (gradResponse != null) {
return response.GET(gradResponse);
Expand All @@ -68,22 +67,22 @@ public ResponseEntity<GradCountry> 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<List<GradProvince>> 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<GradProvince> getSpecificProvinceCode(@PathVariable String provinceCode) {
logger.debug("getSpecificProvinceCode : ");
log.debug("getSpecificProvinceCode : ");
GradProvince gradResponse = codeService.getSpecificProvinceCode(provinceCode);
if (gradResponse != null) {
return response.GET(gradResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")})
Expand All @@ -50,7 +50,7 @@ public ResponseEntity<District> 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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand All @@ -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<List<String>> getSchoolListFromSnapshotByGradYear(@PathVariable Integer gradYear) {
logger.debug("getSchoolListFromSnapshotByGradYear : ");
log.debug("getSchoolListFromSnapshotByGradYear : ");
validation.requiredField(gradYear, GRAD_YEAR_PARAM);
if (validation.hasErrors()) {
validation.stopOnErrors();
Expand All @@ -58,13 +58,13 @@ public ResponseEntity<List<String>> 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<List<SnapshotResponse>> getStudentsFromSnapshotByGradYear(@PathVariable Integer gradYear) {
logger.debug("getStudentsFromSnapshotByGradYear : ");
log.debug("getStudentsFromSnapshotByGradYear : ");
validation.requiredField(gradYear, GRAD_YEAR_PARAM);
if (validation.hasErrors()) {
validation.stopOnErrors();
Expand All @@ -73,13 +73,13 @@ public ResponseEntity<List<SnapshotResponse>> 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<List<SnapshotResponse>> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -38,29 +38,29 @@ 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<List<Psi>> getAllPSIs() {
logger.debug("getAllPSIs : ");
public ResponseEntity<List<Psi>> 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<Psi> getPSIDetails(@PathVariable String psiCode) {
logger.debug("getPSIDetails : ");
log.debug("getPSIDetails : ");
Psi psi = psiService.getPSIDetails(psiCode);
if(psi ==null) {
return response.NOT_FOUND();
}
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")})
Expand All @@ -73,15 +73,15 @@ public ResponseEntity<List<Psi>> 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")})
public ResponseEntity<List<StudentPsi>> 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));
}
}
Loading

0 comments on commit b11ae13

Please sign in to comment.