-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
523 additions
and
3 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
api/src/main/java/ca/bc/gov/educ/api/trax/controller/EdwController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/SnapshotResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/SnapshotEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
27 changes: 27 additions & 0 deletions
27
api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/SnapshotID.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
api/src/main/java/ca/bc/gov/educ/api/trax/repository/SnapshotRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
api/src/main/java/ca/bc/gov/educ/api/trax/service/EdwService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
api/src/main/resources/db/migration/1.0/V1.0.23__DDL-CREATE_SYNONYM-snapshot.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE OR REPLACE EDITIONABLE SYNONYM "SNAPSHOT" FOR "SNAPSHOT"@"TRAXLINK.WORLD"; |
Oops, something went wrong.