Skip to content

Commit

Permalink
Merge branch 'grad-release'
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry0589 committed Oct 26, 2023
2 parents 964c5c2 + d66aede commit f402db1
Show file tree
Hide file tree
Showing 10 changed files with 523 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package ca.bc.gov.educ.api.trax.controller;

import ca.bc.gov.educ.api.trax.model.dto.SnapshotResponse;
import ca.bc.gov.educ.api.trax.service.EdwService;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@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";

@Autowired
EdwService edwService;

@Autowired
GradValidation validation;

@Autowired
ResponseHelper response;

@GetMapping(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 : ");
validation.requiredField(gradYear, GRAD_YEAR_PARAM);
if (validation.hasErrors()) {
validation.stopOnErrors();
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
return response.GET(edwService.getUniqueSchoolList(gradYear));
}

@GetMapping(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 : ");
validation.requiredField(gradYear, GRAD_YEAR_PARAM);
if (validation.hasErrors()) {
validation.stopOnErrors();
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
return response.GET(edwService.getStudents(gradYear));
}

@GetMapping(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 : ");
validation.requiredField(gradYear, GRAD_YEAR_PARAM);
validation.requiredField(minCode, SCHOOL_PARAM);
if (validation.hasErrors()) {
validation.stopOnErrors();
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
return response.GET(edwService.getStudents(gradYear, minCode));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ca.bc.gov.educ.api.trax.model.dto;

import lombok.*;

import java.math.BigDecimal;

@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
public class SnapshotResponse {
private String pen;
private String graduatedDate; // yyyyMM
private BigDecimal gpa;
private String honourFlag;
private String schoolOfRecord;
private String studentGrade;

public SnapshotResponse(String pen, String graduatedDate, BigDecimal gpa, String honourFlag, String schoolOfRecord, String studentGrade) {
this.pen = pen;
this.graduatedDate = graduatedDate;
this.gpa = gpa;
this.honourFlag = honourFlag;
this.schoolOfRecord = schoolOfRecord;
this.studentGrade = studentGrade;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ca.bc.gov.educ.api.trax.model.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

/**
* The type TRAX Student entity.
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "SNAPSHOT")
@IdClass(SnapshotID.class)
public class SnapshotEntity {
@Id
@Column(name = "GRAD_YEAR", nullable = false, updatable = false)
private Integer gradYear;

@Id
@Column(name = "STUD_NO", nullable = false, updatable = false)
private String pen;

@Column(name = "STUD_GRADE")
private String studGrade;

@Column(name = "GRADUATED")
private String graduatedDate;

@Column(name = "MINCODE")
private String schoolOfRecord;

@Column(name = "STUD_GPA")
private BigDecimal gpa;

@Column(name = "HONOUR_FLAG")
private String honourFlag;

@Column(name = "STUD_SEX")
private String studSex;

@Column(name = "PRGM_CODE")
private String prgmCode;

@Column(name = "PRGM_CODE2")
private String prgmCode2;

@Column(name = "PRGM_CODE3")
private String prgmCode3;

@Column(name = "PRGM_CODE4")
private String prgmCode4;

@Column(name = "PRGM_CODE5")
private String prgmCode5;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ca.bc.gov.educ.api.trax.model.entity;

import java.io.Serializable;
import java.util.Objects;

public class SnapshotID implements Serializable {
private Integer gradYear;
private String pen;

public SnapshotID(int gradYear, String pen) {
this.gradYear = gradYear;
this.pen = pen;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SnapshotID that = (SnapshotID) o;
return Objects.equals(gradYear, that.gradYear) && Objects.equals(pen, that.pen);
}

@Override
public int hashCode() {
return Objects.hash(gradYear, pen);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ca.bc.gov.educ.api.trax.repository;

import ca.bc.gov.educ.api.trax.model.dto.SnapshotResponse;
import ca.bc.gov.educ.api.trax.model.entity.SnapshotEntity;
import ca.bc.gov.educ.api.trax.model.entity.SnapshotID;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SnapshotRepository extends JpaRepository<SnapshotEntity, SnapshotID> {

@Query(value="select distinct trim(s.mincode) as schoolOfRecord\n" +
"from snapshot s\n" +
"where s.grad_year = :gradYear", nativeQuery=true)
List<String> getSchools(@Param("gradYear") Integer gradYear);

@Query(value="select new ca.bc.gov.educ.api.trax.model.dto.SnapshotResponse(trim(s.pen), trim(s.graduatedDate), s.gpa, trim(s.honourFlag), trim(s.schoolOfRecord), trim(s.studGrade))\n" +
"from SnapshotEntity s\n" +
"where s.gradYear = :gradYear")
List<SnapshotResponse> getStudentsByGradYear(@Param("gradYear") Integer gradYear);

@Query(value="select new ca.bc.gov.educ.api.trax.model.dto.SnapshotResponse(trim(s.pen), trim(s.graduatedDate), s.gpa, trim(s.honourFlag), trim(s.schoolOfRecord), trim(s.studGrade))\n" +
"from SnapshotEntity s\n" +
"where s.gradYear = :gradYear\n" +
"and s.schoolOfRecord = :schoolOfRecord")
List<SnapshotResponse> getStudentsByGradYearAndSchoolOfRecord(@Param("gradYear") Integer gradYear, @Param("schoolOfRecord") String schoolOfRecord);

// Paginated support by gradYear
Page<SnapshotEntity> findByGradYear(Integer gradYear, Pageable pageable);

Integer countAllByGradYear(Integer gradYear);

// Paginated support by gradYear & schoolOfRecord
Page<SnapshotEntity> findByGradYearAndSchoolOfRecord(Integer gradYear, String schoolOfRecord, Pageable pageable);

Integer countAllByGradYearAndSchoolOfRecord(Integer gradYear, String schoolOfRecord);

}
30 changes: 30 additions & 0 deletions api/src/main/java/ca/bc/gov/educ/api/trax/service/EdwService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ca.bc.gov.educ.api.trax.service;

import ca.bc.gov.educ.api.trax.model.dto.SnapshotResponse;
import ca.bc.gov.educ.api.trax.repository.SnapshotRepository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EdwService {
final SnapshotRepository snapshotRepository;

public EdwService(
SnapshotRepository snapshotRepository
) {
this.snapshotRepository = snapshotRepository;
}

public List<String> getUniqueSchoolList(Integer gradYear) {
return snapshotRepository.getSchools(gradYear);
}

public List<SnapshotResponse> getStudents(Integer gradYear) {
return snapshotRepository.getStudentsByGradYear(gradYear);
}

public List<SnapshotResponse> getStudents(Integer gradYear, String schoolOfRecord) {
return snapshotRepository.getStudentsByGradYearAndSchoolOfRecord(gradYear, schoolOfRecord);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ public class EducGradTraxApiConstants {
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 + "/common";
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";


// Service Methods Mappings
public static final String GET_ALL_COUNTRY_MAPPING = "/country";
public static final String GET_ALL_COUNTRY_BY_CODE_MAPPING = "/country/{countryCode}";

public static final String GET_ALL_PROVINCE_MAPPING = "/province";
public static final String GET_ALL_PROVINCE_BY_CODE_MAPPING = "/province/{provinceCode}";

Expand All @@ -58,6 +60,10 @@ public class EducGradTraxApiConstants {
public static final String GET_TRANSCRIPT_DEMOG_BY_PEN_MAPPING = "/tran-demog/{pen}";
public static final String GET_TRANSCRIPT_COURSE_BY_PEN_MAPPING = "/tran-courses/{pen}";

public static final String GET_SCHOOLS_BY_GRAD_YEAR_MAPPING = "/get-schools/snapshot/{gradYear}";
public static final String GET_STUDENTS_BY_GRAD_YEAR_MAPPING = "/get-students/snapshot/{gradYear}";
public static final String GET_STUDENTS_BY_GRAD_YEAR_AND_SCHOOL_MAPPING = "/get-students/snapshot/{gradYear}/{minCode}";

public static final String GET_TRAX_STUDENT_GRADUATED_BY_PEN_MAPPING = "/student/graduated/{pen}";
public static final String GET_TRAX_STUDENT_MASTER_MAPPING = "/student-master/{pen}";
public static final String GET_TRAX_STUDENT_DEMOG_MAPPING = "/student-demog/{pen}";
Expand All @@ -66,7 +72,7 @@ public class EducGradTraxApiConstants {
public static final String GET_COURSE_RESTRICTION_LIST_MAPPING = "/course-restrictions";
public static final String GET_COURSE_REQUIREMENT_LIST_MAPPING = "/course-requirements";
public static final String POST_SAVE_TRAX_STUDENT_NO_MAPPING = "/trax-student-no";

//Default Attribute value constants
public static final String DEFAULT_CREATED_BY = "API_GRAD_TRAX";
protected static final Date DEFAULT_CREATED_TIMESTAMP = new Date();
Expand All @@ -75,7 +81,7 @@ public class EducGradTraxApiConstants {

//Default Date format constants
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";

public static final String TRAX_DATE_FORMAT = "yyyyMMdd";
public static final String TRAX_TSW_DATE_FORMAT = "yyyyMM";
public static final Date ADULT_18_RULE_VALID_DATE = EducGradTraxApiUtils.parseDate("2012-07-01");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE OR REPLACE EDITIONABLE SYNONYM "SNAPSHOT" FOR "SNAPSHOT"@"TRAXLINK.WORLD";
Loading

0 comments on commit f402db1

Please sign in to comment.