Skip to content

Commit

Permalink
Merge pull request #323 from bcgov/grad-release
Browse files Browse the repository at this point in the history
Grad release 1.16.0
  • Loading branch information
githubmamatha authored Mar 26, 2024
2 parents bae3b03 + 1a3e6a8 commit 3dd2c0e
Show file tree
Hide file tree
Showing 29 changed files with 539 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.from.main.branch.deploy.to.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ env:
MAX_CPU: "500m"
MIN_MEM: "1Gi"
MAX_MEM: "2Gi"
MIN_REPLICAS: "3"
MIN_REPLICAS: "2"
MAX_REPLICAS: "3"

on:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ env:
MAX_CPU: "500m"
MIN_MEM: "1Gi"
MAX_MEM: "2Gi"
MIN_REPLICAS: "3"
MIN_REPLICAS: "2"
MAX_REPLICAS: "3"

on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.to.dev.jinil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ env:
MAX_CPU: "500m"
MIN_MEM: "1Gi"
MAX_MEM: "2Gi"
MIN_REPLICAS: "3"
MIN_REPLICAS: "2"
MAX_REPLICAS: "3"

on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env:
MIN_MEM: "1Gi"
MAX_MEM: "2Gi"
MIN_REPLICAS: "3"
MAX_REPLICAS: "3"
MAX_REPLICAS: "4"

on:
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env:
MIN_MEM: "1Gi"
MAX_MEM: "2Gi"
MIN_REPLICAS: "3"
MAX_REPLICAS: "3"
MAX_REPLICAS: "4"

on:
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.bc.gov.educ</groupId>
<artifactId>educ-grad-data-conversion-api</artifactId>
<version>1.8.54</version>
<version>1.8.55</version>
<name>educ-grad-data-conversion-api</name>
<description>Ministry of Education GRAD DATA CONVERSION API</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
@EnableWebSecurity
public class WebSecurityConfiguration {

public WebSecurityConfiguration() {
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
}

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Date;

@RestController
@RequestMapping(EducGradDataConversionApiConstants.GRAD_BATCH_API_ROOT_MAPPING)
@RequestMapping(EducGradDataConversionApiConstants.GRAD_DATA_CONVERSION_API_ROOT_MAPPING)
@CrossOrigin
@OpenAPIDefinition(info = @Info(title = "API for Data Conversion & Ongoing Updates.",
description = "This API is for Reading TRAX data and Persisting GRAD data.", version = "1"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package ca.bc.gov.educ.api.dataconversion.controller;

import ca.bc.gov.educ.api.dataconversion.model.Student;
import ca.bc.gov.educ.api.dataconversion.service.student.StudentService;
import ca.bc.gov.educ.api.dataconversion.util.EducGradDataConversionApiConstants;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(EducGradDataConversionApiConstants.GRAD_DATA_CONVERSION_API_ROOT_MAPPING)
@CrossOrigin
@OpenAPIDefinition(info = @Info(title = "API for Adhoc Student Operations",
description = "This API is for running adhoc student operations invoking the endpoints manually.", version = "1"))
public class StudentController {

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

@Autowired
StudentService studentService;

@GetMapping(EducGradDataConversionApiConstants.GRAD_STUDENT_BY_PEN_STUDENT_API)
@PreAuthorize("hasAuthority('SCOPE_READ_GRAD_STUDENT_DATA')")
@Operation(summary = "Search For Student by PEN", description = "Search for Student Demographics by PEN", tags = { "Students" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public Student getGradStudentByPenFromStudentAPI(@PathVariable String pen, @RequestHeader(name="Authorization") String accessToken) {
logger.debug("Get Student by PEN [Controller]");
return studentService.getStudentByPen(pen, accessToken.replaceAll("Bearer ", ""));
}

@DeleteMapping(EducGradDataConversionApiConstants.GRAD_STUDENT_BY_PEN_STUDENT_API)
@PreAuthorize("hasAuthority('SCOPE_DELETE_GRAD_STUDENT_DATA')")
@Operation(summary = "Delete a Student by PEN", description = "Delete a Student and all related data by PEN", tags = { "Students" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public void cascadeDeleteStudent(@PathVariable String pen, @RequestHeader(name="Authorization") String accessToken) {
logger.debug("Cascade Delete a Student [Controller]");
studentService.cascadeDeleteStudent(pen, accessToken.replaceAll("Bearer ", ""));
}

@DeleteMapping(EducGradDataConversionApiConstants.GRAD_STUDENTS_BY_PENLIST_STUDENT_API)
@PreAuthorize("hasAuthority('SCOPE_DELETE_GRAD_STUDENT_DATA')")
@Operation(summary = "Delete multiple Students by PEN", description = "Delete a list of Students and all related data by PEN", tags = { "Students" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public void cascadeDeleteStudents(@RequestBody List<String> penList, @RequestHeader(name="Authorization") String accessToken) {
logger.debug("Cascade Delete a Student [Controller]");
penList.forEach(pen -> {
studentService.cascadeDeleteStudent(pen, accessToken.replaceAll("Bearer ", ""));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package ca.bc.gov.educ.api.dataconversion.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.sql.Date;

@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class GradSearchStudent {

private String studentID;
private String pen;
private String legalFirstName;
private String legalMiddleNames;
private String legalLastName;
private String dob;
private String sexCode;
private String genderCode;
private String studentCitizenship;
private String usualFirstName;
private String usualMiddleNames;
private String usualLastName;
private String email;
private String emailVerified;
private String deceasedDate;
private String postalCode;
private String mincode;
private String localID;
private String gradeCode;
private String gradeYear;
private String demogCode;
private String statusCode;
private String memo;
private String trueStudentID;
private String program;
private String schoolOfRecord;
private String schoolOfRecordName;
private String schoolOfRecordindependentAffiliation;
private String studentGrade;
private String studentStatus;
private String transcriptEligibility;
private String certificateEligibility;
@JsonFormat(pattern="yyyy-MM-dd")
private Date adultStartDate;

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class Student {

String studentID;
String pen;
String legalFirstName;
String legalMiddleNames;
String legalLastName;
String dob;
String sexCode;
String genderCode;
String usualFirstName;
String usualMiddleNames;
String usualLastName;
String email;
String emailVerified;
String deceasedDate;
String postalCode;
String mincode;
String localID;
String gradeCode;
String gradeYear;
String demogCode;
String statusCode;
String memo;
String trueStudentID;
String historyActivityCode;
String studentID;
String pen;
String legalFirstName;
String legalMiddleNames;
String legalLastName;
String dob;
String sexCode;
String genderCode;
String usualFirstName;
String usualMiddleNames;
String usualLastName;
String email;
String emailVerified;
String deceasedDate;
String postalCode;
String mincode;
String localID;
String gradeCode;
String gradeYear;
String demogCode;
String statusCode;
String memo;
String trueStudentID;
String historyActivityCode;

public String createUser;
public String updateUser;
public String createDate;
public String updateDate;
public String createUser;
public String updateUser;
public String createDate;
public String updateDate;

String truePen;
String truePen;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ca.bc.gov.educ.api.dataconversion.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.UUID;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class StudentNote extends BaseModel {

private UUID id;
private String note;
private String studentID;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package ca.bc.gov.educ.api.dataconversion.service.student;

import ca.bc.gov.educ.api.dataconversion.model.*;
import ca.bc.gov.educ.api.dataconversion.util.RestUtils;
import io.github.resilience4j.retry.annotation.Retry;
import jakarta.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.UUID;

@Service
@Slf4j
public class StudentService {
private static final Logger logger = LoggerFactory.getLogger(StudentService.class);

private final RestUtils restUtils;
final WebClient webClient;

@Autowired
public StudentService(RestUtils restUtils, WebClient webClient) {
this.restUtils = restUtils;
this.webClient = webClient;
}

@Transactional
@Retry(name = "searchbypen")
public Student getStudentByPen(String pen, String accessToken) {
logger.debug("Get Student by PEN [Service]");

Student student;
List<Student> gradStudentList;

try {
gradStudentList = restUtils.getStudentsByPen(pen, accessToken);
student = gradStudentList.stream().filter(s -> s.getPen().compareTo(pen) == 0).findAny().orElse(null);
} catch (Exception e) {
log.error("Failed to retrieve PEN [{}] : {} ", pen, e.getLocalizedMessage());
return null;
}

if (student == null) {
log.error("PEN NOT FOUND [{}]", pen);
return null;
}
return student;
}

@Transactional
public String cascadeDeleteStudent(String pen, String accessToken) {
logger.debug("Cascade Delete a Student [Service]");

//GET Student by PEN
Student student = getStudentByPen(pen, accessToken);
logger.debug("After GET student");
String studentID;

if (student != null) {
studentID = student.getStudentID();
logger.debug("Student ID: [{}]", studentID);

/*
Delete All student related data ({STUDENT_API}/api/v1/student/conv/studentid/{studentID})
This will delete student data from the following tables:
STUDENT_RECORD_NOTE, STUDENT_CAREER_PROGRAMS, STUDENT_OPTIONAL_PROGRAM_HISTORY,
STUDENT_OPTIONAL_PROGRAM, GRADUATION_STUDENT_RECORD_HISTORY, GRADUATION_STUDENT_RECORD
*/
try {
restUtils.removeAllStudentRelatedData(UUID.fromString(studentID), accessToken);
} catch (Exception e) {
logger.info("Exception thrown when trying to delete student related data from grad student API.");
}

/*
Delete all Student certificates, transcripts and reports from API_GRAD_REPORT schema
Tables: STUDENT_CERTIFICATE, STUDENT_TRANSCRIPT and STUDENT_REPORT
*/
try {
restUtils.removeAllStudentAchievements(UUID.fromString(studentID), accessToken);
} catch (Exception e) {
logger.info("Exception thrown when trying to delete student achievements.");
}

/*
Update TRAX_STUDENT_NO status to NULL
*/
try {
restUtils.updateTraxStudentNo(new TraxStudentNo(pen, null, null), accessToken);
} catch (Exception e) {
logger.info("Exception thrown when trying to update TraxStudentNo.");
}
}
return pen;
}
}
Loading

0 comments on commit 3dd2c0e

Please sign in to comment.