Skip to content

Commit

Permalink
GRAD2-3018 - Adds tables, data, and get endpoint for student grade codes
Browse files Browse the repository at this point in the history
  • Loading branch information
mightycox committed Oct 29, 2024
1 parent e287e4d commit 0484f87
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 35 deletions.
7 changes: 6 additions & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,16 @@
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down Expand Up @@ -201,6 +202,18 @@ public ResponseEntity<HistoryActivity> getSpecificHistoryActivityCode(@PathVaria
return response.GET(commonService.getSpecificHistoryActivityCode(activityCode));
}

@GetMapping(EducGradStudentApiConstants.GET_ALL_STUDENT_GRADE_CODES)
@PreAuthorize(PermissionsConstants.READ_STUDENT_GRADE_CODES)
@Transactional(readOnly = true)
@Operation(summary = "Find all active Student Grade Codes",
description = "Find all active Student Grade Codes", tags = {"Student Grade Code"})
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "204", description = "NO CONTENT.")})
public ResponseEntity<List<StudentGradeCode>> getAllStudentGradeCodes() {
logger.debug("getAllStudentGradeCodes : ");
return response.GET(commonService.getAllStudentGradeCodes());
}

@GetMapping(EducGradStudentApiConstants.GET_ALL_STUDENT_REPORT_DATA_BY_MINCODE)
@PreAuthorize(PermissionsConstants.READ_GRAD_STUDENT_STATUS)
@Operation(summary = "Find a Student Graduation Data by Mininstry Code",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ca.bc.gov.educ.api.gradstudent.model.dto;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Data
@EqualsAndHashCode(callSuper = false)
@Component
@SuppressWarnings("squid:S1700")
public class StudentGradeCode extends BaseModel {
private String studentGradeCode;
private String label;
private int displayOrder;
private String description;
private LocalDateTime effectiveDate;
private LocalDateTime expiryDate;
private String expected;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ca.bc.gov.educ.api.gradstudent.model.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import lombok.*;

import java.time.LocalDateTime;

@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "STUDENT_GRADE_CODE")
public class StudentGradeCodeEntity extends BaseEntity {

@Id
@Column(name = "STUDENT_GRADE_CODE", unique = true, updatable = false)
private String studentGradeCode;

@NotNull(message = "label cannot be null")
@Column(name = "LABEL")
private String label;

@NotNull(message = "displayOrder cannot be null")
@Column(name = "DISPLAY_ORDER")
private Integer displayOrder;

@NotNull(message = "description cannot be null")
@Column(name = "DESCRIPTION")
private String description;

@NotNull(message = "effectiveDate cannot be null")
@Column(name = "EFFECTIVE_DATE")
private LocalDateTime effectiveDate;

@Column(name = "EXPIRY_DATE")
private LocalDateTime expiryDate;

@NotNull(message = "expected cannot be null")
@Column(name = "EXPECTED")
private String expected;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ca.bc.gov.educ.api.gradstudent.model.transformer;

import ca.bc.gov.educ.api.gradstudent.model.dto.StudentGradeCode;
import ca.bc.gov.educ.api.gradstudent.model.entity.StudentGradeCodeEntity;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class StudentGradeCodeTransformer {

@Autowired
ModelMapper modelMapper;

public StudentGradeCode transformToDTO (StudentGradeCodeEntity entity) {
return modelMapper.map(entity, StudentGradeCode.class);
}

public StudentGradeCodeEntity transformToEntity(StudentGradeCode studentGradeCode) {
return modelMapper.map(studentGradeCode, StudentGradeCodeEntity.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ca.bc.gov.educ.api.gradstudent.repository;

import ca.bc.gov.educ.api.gradstudent.model.entity.StudentGradeCodeEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface StudentGradeCodeRepository extends JpaRepository<StudentGradeCodeEntity, String> {
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
package ca.bc.gov.educ.api.gradstudent.service;

import ca.bc.gov.educ.api.gradstudent.model.dto.*;
import ca.bc.gov.educ.api.gradstudent.model.entity.HistoryActivityCodeEntity;
import ca.bc.gov.educ.api.gradstudent.model.entity.StudentCareerProgramEntity;
import ca.bc.gov.educ.api.gradstudent.model.entity.StudentRecordNoteEntity;
import ca.bc.gov.educ.api.gradstudent.model.entity.StudentStatusEntity;
import ca.bc.gov.educ.api.gradstudent.model.transformer.GradStudentCareerProgramTransformer;
import ca.bc.gov.educ.api.gradstudent.model.transformer.HistoryActivityTransformer;
import ca.bc.gov.educ.api.gradstudent.model.transformer.StudentNoteTransformer;
import ca.bc.gov.educ.api.gradstudent.model.transformer.StudentStatusTransformer;
import ca.bc.gov.educ.api.gradstudent.repository.HistoryActivityRepository;
import ca.bc.gov.educ.api.gradstudent.repository.StudentCareerProgramRepository;
import ca.bc.gov.educ.api.gradstudent.repository.StudentNoteRepository;
import ca.bc.gov.educ.api.gradstudent.repository.StudentStatusRepository;
import ca.bc.gov.educ.api.gradstudent.model.entity.*;
import ca.bc.gov.educ.api.gradstudent.model.transformer.*;
import ca.bc.gov.educ.api.gradstudent.repository.*;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants;
import ca.bc.gov.educ.api.gradstudent.util.GradValidation;
import ca.bc.gov.educ.api.gradstudent.util.ThreadLocalStateUtil;
Expand Down Expand Up @@ -51,6 +42,8 @@ public class CommonService {
final GradValidation validation;
final HistoryActivityRepository historyActivityRepository;
final HistoryActivityTransformer historyActivityTransformer;
final StudentGradeCodeRepository studentGradeCodeRepository;
final StudentGradeCodeTransformer studentGradeCodeTransformer;

@Autowired
public CommonService(EducGradStudentApiConstants constants,
Expand All @@ -65,7 +58,9 @@ public CommonService(EducGradStudentApiConstants constants,
HistoryActivityRepository historyActivityRepository,
HistoryActivityTransformer historyActivityTransformer,
WebClient webClient,
GradValidation validation) {
GradValidation validation,
StudentGradeCodeRepository studentGradeCodeRepository,
StudentGradeCodeTransformer studentGradeCodeTransformer) {
this.constants = constants;
this.gradStudentCareerProgramRepository = gradStudentCareerProgramRepository;
this.gradStudentCareerProgramTransformer = gradStudentCareerProgramTransformer;
Expand All @@ -79,6 +74,8 @@ public CommonService(EducGradStudentApiConstants constants,
this.historyActivityTransformer = historyActivityTransformer;
this.webClient = webClient;
this.validation = validation;
this.studentGradeCodeRepository = studentGradeCodeRepository;
this.studentGradeCodeTransformer = studentGradeCodeTransformer;
}

@Transactional
Expand Down Expand Up @@ -235,4 +232,8 @@ public HistoryActivity getSpecificHistoryActivityCode(String activityCode) {
public List<UUID> getDeceasedStudentIDs(List<UUID> studentIDs) {
return gradStudentService.getStudentIDsByStatusCode(studentIDs, "DEC");
}

public List<StudentGradeCode> getAllStudentGradeCodes() {
return studentGradeCodeRepository.findAll().stream().map(studentGradeCodeTransformer::transformToDTO).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class EducGradStudentApiConstants {
public static final String GRADUATION_RECORD_HISTORY_BY_BATCH_ID_DISTRIBUTION_RUN = "/distribution/batchid/{batchID}";
public static final String UPDATE_GRAD_STUDENT_FLAG_BY_BATCH_JOB_TYPE_AND_MULTIPLE_STUDENTIDS = "/multistudentids/batchflag/jobtype/{batchJobType}";
public static final String GRAD_STUDENT_NON_GRAD_REASON_BY_PEN = "/pen/{pen}/nongrad-reason";
public static final String GET_ALL_STUDENT_GRADE_CODES = "/student-grade-codes";

public static final String GRAD_STUDENT_OPTIONAL_PROGRAM_BY_PEN = "/optionalprogram/studentid/{studentID}";
public static final String GRAD_STUDENT_OPTIONAL_PROGRAM_BY_PEN_PROGRAM_OPTIONAL_PROGRAM = "/optionalprogram/{studentID}/{optionalProgramID}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ private PermissionsConstants() {}
public static final String UPDATE_STUDENT_STATUS = PREFIX + "SCOPE_UPDATE_GRAD_STUDENT_STATUS_CODE_DATA"+ SUFFIX;
public static final String STUDENT_ALGORITHM_DATA = PREFIX + "SCOPE_READ_GRAD_GRADUATION_STATUS" + SUFFIX + " and "
+ PREFIX + "SCOPE_READ_GRAD_STUDENT_DATA" + SUFFIX;
public static final String READ_STUDENT_GRADE_CODES = PREFIX + "SCOPE_READ_STUDENT_GRADE_CODES" + SUFFIX;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- API_GRAD_STUDENT.STUDENT_GRADE_CODE definition

CREATE TABLE "STUDENT_GRADE_CODE"
( "STUDENT_GRADE_CODE" VARCHAR2(2) NOT NULL,
"LABEL" VARCHAR2(30) NOT NULL,
"DESCRIPTION" VARCHAR2(125) NOT NULL,
"DISPLAY_ORDER" NUMBER NOT NULL,
"EFFECTIVE_DATE" DATE NOT NULL,
"EXPIRY_DATE" DATE,
"EXPECTED" VARCHAR2(1) NOT NULL,
"CREATE_DATE" DATE DEFAULT SYSTIMESTAMP NOT NULL,
"CREATE_USER" VARCHAR2(32) DEFAULT USER NOT NULL,
"UPDATE_DATE" DATE DEFAULT SYSTIMESTAMP NOT NULL,
"UPDATE_USER" VARCHAR2(32) DEFAULT USER NOT NULL,
CONSTRAINT "STUDENT_GRADE_CODE_PK" PRIMARY KEY ("STUDENT_GRADE_CODE")
USING INDEX TABLESPACE "API_GRAD_IDX"
) SEGMENT CREATION IMMEDIATE
NOCOMPRESS LOGGING
TABLESPACE "API_GRAD_DATA" NO INMEMORY ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('01','Grade 1','First grade',110,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'N');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('02','Grade 2','Second grade',120,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'N');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('03','Grade 3','Third grade',130,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'N');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('04','Grade 4','Fourth grade',140,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'N');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('05','Grade 5','Fifth grade',150,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'N');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('06','Grade 6','Sixth grade',160,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'N');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('07','Grade 7','Seventh grade',170,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'N');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('08','Grade 8','Eighth grade',10,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'Y');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('09','Grade 9','Ninth grade',20,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'Y');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('10','Grade 10','Tenth grade',30,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'Y');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('11','Grade 11','Eleventh grade',40,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'Y');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('12','Grade 12','Twelfth grade',50,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'Y');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('AD','Adult Grad','Student on the Adult Graduation Program who is expected to graduate this year (subgrade)',60,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'Y');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('AN','Adult Non Grad','Student on the Adult Graduation Program who is not expected to graduate this year (subgrade)',70,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'Y');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('GA','Graduated Adult','An adult student who has graduated in BC or another jurisdiction (subgrade)',90,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'Y');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('GR','Graduated','Used by MyEdBC schools only when a student withdraws or the school believes they have finished their program',100,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'N');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('KF','Kindergarten Full-time','After 2012, the only valid grade code for kindergarten (subgrade)',180,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'N');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('SU','Secondary Upgraded','Secondary upgraded (subgrade)',190,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'Y');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('EU','Elementary Upgraded','Elementary ungraded (subgrade)',200,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'N');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('HS','Home School','Students whose parents provide their educational program and who are registered with the school (subgrade)',80,TIMESTAMP'2024-10-01 00:00:00.0',NULL, 'Y');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('KH','Kindergarten Half','Kindergarten half-time, applicable only until 2012 (subgrade)',210,TIMESTAMP'2024-10-01 00:00:00.0',TIMESTAMP'2012-06-30 00:00:00.0', 'N');

INSERT INTO STUDENT_GRADE_CODE (STUDENT_GRADE_CODE,LABEL,DESCRIPTION,DISPLAY_ORDER,EFFECTIVE_DATE,EXPIRY_DATE, EXPECTED)
VALUES ('OT','Other','A historic grade code applied by TRAX when an unexpected grade code was submitted for a student',220,TIMESTAMP'2024-10-01 00:00:00.0',TIMESTAMP'2024-10-01 00:00:00.0', 'Y');
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ca.bc.gov.educ.api.gradstudent.controller;

import ca.bc.gov.educ.api.gradstudent.EducGradStudentApiApplication;
import ca.bc.gov.educ.api.gradstudent.model.entity.StudentGradeCodeEntity;
import ca.bc.gov.educ.api.gradstudent.repository.StudentGradeCodeRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest(classes = {EducGradStudentApiApplication.class})
@ActiveProfiles("test")
@AutoConfigureMockMvc
public abstract class BaseIntegrationTest {

@Autowired
StudentGradeCodeRepository studentGradeCodeRepository;

@BeforeEach
public void before() {
studentGradeCodeRepository.saveAll(studentGradeCodeData());
}

@AfterEach
public void resetState() {
studentGradeCodeRepository.deleteAll();
}

public List<StudentGradeCodeEntity> studentGradeCodeData() {
List<StudentGradeCodeEntity> entities = new ArrayList<>();
entities.add(StudentGradeCodeEntity.builder().studentGradeCode("07").description("Grade 7").label("Grade 7").effectiveDate(LocalDateTime.now()).expected("N").displayOrder(1).build());

entities.add(StudentGradeCodeEntity.builder().studentGradeCode("08").description("Grade 8").label("Grade 8").effectiveDate(LocalDateTime.now()).expected("Y").displayOrder(2).build());

entities.add(StudentGradeCodeEntity.builder().studentGradeCode("09").description("Grade 9").label("Grade 9").effectiveDate(LocalDateTime.now()).expected("Y").displayOrder(3).build());

entities.add(StudentGradeCodeEntity.builder().studentGradeCode("10").description("Grade 10").label("Grade 10").effectiveDate(LocalDateTime.now()).expected("Y").displayOrder(4).build());

return entities;
}
}
Loading

0 comments on commit 0484f87

Please sign in to comment.