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 #316

Merged
merged 30 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 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
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
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
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
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,90 @@
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.EducGradDataConversionApiConstants;
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.ArrayList;
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 = new ArrayList<>();

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
*/
restUtils.removeAllStudentRelatedData(UUID.fromString(studentID), accessToken);

/*
Delete all Student certificates, transcripts and reports from API_GRAD_REPORT schema
Tables: STUDENT_CERTIFICATE, STUDENT_TRANSCRIPT and STUDENT_REPORT
*/
restUtils.removeAllStudentAchievements(UUID.fromString(studentID), accessToken);

/*
Update TRAX_STUDENT_NO status to NULL
*/
restUtils.updateTraxStudentNo(pen, accessToken);
}
return pen;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ public class EducGradDataConversionApiConstants {
public static final String CORRELATION_ID = "correlationID";
public static final String API_ROOT_MAPPING = "";
public static final String API_VERSION = "v1";
public static final String GRAD_BATCH_API_ROOT_MAPPING = "/api/" + API_VERSION + "/data-conversion";
public static final String GRAD_DATA_CONVERSION_API_ROOT_MAPPING = "/api/" + API_VERSION + "/data-conversion";

// Data Conversion
public static final String GRAD_STUDENT_PARALLEL_DATA_CONVERSION_BATCH_JOB = "/student/parallel";
public static final String GRAD_COURSE_RESTRICTION_DATA_CONVERSION_BATCH_JOB = "/courseRestriction";
public static final String GRAD_COURSE_REQUIREMENT_DATA_CONVERSION_BATCH_JOB = "/courseRequirement";
public static final String GRAD_STUDENT_BY_PEN_STUDENT_API = "/student/pen/{pen}";
public static final String GRAD_STUDENTS_BY_PENLIST_STUDENT_API = "/student/penlist";

// Util
public static final String PEN_UPDATES_PARALLEL_BATCH_JOB = "/penUpdates/parallel";
Expand All @@ -33,8 +35,6 @@ public class EducGradDataConversionApiConstants {
public static final String DEFAULT_CREATED_BY = "DATA_CONV";
public static final String DEFAULT_UPDATED_BY = "DATA_CONV";

public static final String DEFAULT_END_DATE_FORMAT = "20991231"; // yyyyMMdd

@Value("${authorization.user}")
private String userName;

Expand Down Expand Up @@ -101,6 +101,12 @@ public class EducGradDataConversionApiConstants {
@Value("${endpoint.grad-student-api.remove-student-career-program}")
private String removeStudentCareerProgram;

@Value("${endpoint.grad-student-api.get-student-by-pen}")
private String gradStudentByPenUrl;

@Value("${endpoint.grad-student-api.get-student-notes-by-studentID}")
private String gradStudentNotesByStudentID;

@Value("${endpoint.grad-assessment-api.assessment-requirement.url}")
private String addAssessmentRequirementApiUrl;

Expand Down Expand Up @@ -155,6 +161,9 @@ public class EducGradDataConversionApiConstants {
@Value("${endpoint.grad-trax-api.student.save-trax-student-no.url}")
private String saveTraxStudentNoUrl;

@Value("${endpoint.grad-graduation-report-api.delete-student-achievements.url}")
private String deleteStudentAchievementsUrl;

// Incremental Grad Update
@Value("${grad.update.enabled}")
private boolean gradUpdateEnabled;
Expand Down
Loading
Loading