Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRAD2-2465 - Delete a student and related data #323

Merged
merged 43 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
eb14dae
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 4, 2024
ad93be7
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 4, 2024
40a8e24
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 4, 2024
ed71dea
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 4, 2024
d30a37b
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 4, 2024
ffba551
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 4, 2024
cd94e1d
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 4, 2024
9a83a71
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 4, 2024
dac41a3
Update pom.xml
githubmamatha Mar 4, 2024
5297318
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
78965ed
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
5afaa6a
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
298ccfe
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
577d801
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
c161f81
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
59b9e5b
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
a0dafa7
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
6932caf
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
2dcef52
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
8629571
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
bf907e6
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
2f02f37
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
cff1c7a
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 7, 2024
aeecf46
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 8, 2024
724ffd1
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 8, 2024
4e86b1d
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 8, 2024
8600965
Update POM
kamal-mohammed Mar 8, 2024
6749516
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 14, 2024
c4ab028
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 15, 2024
883adbc
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 15, 2024
f84f6ed
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 15, 2024
4b09679
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 15, 2024
7caeeb9
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 18, 2024
895e189
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 18, 2024
e69aa06
Merge pull request #319 from bcgov/GRAD2-2465-km
arybakov-cgi Mar 18, 2024
dbfe575
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 18, 2024
2612c79
Merge pull request #320 from bcgov/GRAD2-2465-km
kamal-mohammed Mar 18, 2024
d92ba35
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 18, 2024
3c51b17
Merge pull request #322 from bcgov/GRAD2-2465-km
kamal-mohammed Mar 18, 2024
72b8a46
GRAD2-2465 - Delete a student and related data
kamal-mohammed Mar 18, 2024
4ad8cbd
Merge pull request #324 from bcgov/GRAD2-2465-km
kamal-mohammed Mar 18, 2024
b1df144
Fixing HPA alerts from OCIO (#325)
cditcher Mar 20, 2024
1a3e6a8
Update pom.xml
githubmamatha Mar 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading