-
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.
GRAD2-2465 - Delete a student and related data
GRAD2-2465 - Delete a student and related data
- Loading branch information
Showing
23 changed files
with
520 additions
and
37 deletions.
There are no files selected for viewing
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
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
59 changes: 59 additions & 0 deletions
59
api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.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,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 ", "")); | ||
}); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/GradSearchStudent.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,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; | ||
|
||
} |
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
17 changes: 17 additions & 0 deletions
17
api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/StudentNote.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,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; | ||
} |
90 changes: 90 additions & 0 deletions
90
api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.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,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; | ||
} | ||
} |
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
Oops, something went wrong.