From eb14dae641eef638c5fb81a4614bf770dad4c6c9 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Mon, 4 Mar 2024 09:31:23 -0700 Subject: [PATCH 01/30] GRAD2-2465 - Delete a student and related data --- .../config/WebSecurityConfiguration.java | 4 - .../controller/StudentController.java | 46 +++++++++++ .../model/GradSearchStudent.java | 52 ++++++++++++ .../api/dataconversion/model/Student.java | 58 +++++++------- .../api/dataconversion/model/StudentNote.java | 19 +++++ .../service/student/StudentService.java | 80 +++++++++++++++++++ .../EducGradDataConversionApiConstants.java | 11 ++- .../api/dataconversion/util/RestUtils.java | 14 ++++ 8 files changed, 249 insertions(+), 35 deletions(-) create mode 100644 api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/GradSearchStudent.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/StudentNote.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/config/WebSecurityConfiguration.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/config/WebSecurityConfiguration.java index e89cd61d..283e9824 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/config/WebSecurityConfiguration.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/config/WebSecurityConfiguration.java @@ -16,10 +16,6 @@ @EnableWebSecurity public class WebSecurityConfiguration { - public WebSecurityConfiguration() { - SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL); - } - @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java new file mode 100644 index 00000000..0cbc1fee --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java @@ -0,0 +1,46 @@ +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.*; + +@RestController +@RequestMapping(EducGradDataConversionApiConstants.GRAD_STUDENT_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_CASCADE_DELETE_STUDENT_BY_PEN) + @PreAuthorize("hasAuthority('SCOPE_READ_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 ", "")); + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/GradSearchStudent.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/GradSearchStudent.java new file mode 100644 index 00000000..0c855c9c --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/GradSearchStudent.java @@ -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; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/Student.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/Student.java index 547c7e66..db8405bd 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/Student.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/Student.java @@ -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; } diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/StudentNote.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/StudentNote.java new file mode 100644 index 00000000..95643b98 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/StudentNote.java @@ -0,0 +1,19 @@ +package ca.bc.gov.educ.api.dataconversion.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.UUID; + +@Data +@SuperBuilder +@AllArgsConstructor +@NoArgsConstructor +public class StudentNote extends BaseModel { + + private UUID id; + private String note; + private String studentID; +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java new file mode 100644 index 00000000..ef37a96b --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java @@ -0,0 +1,80 @@ +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; + private final EducGradDataConversionApiConstants constants; + final WebClient webClient; + + @Autowired + public StudentService(RestUtils restUtils, EducGradDataConversionApiConstants constants, WebClient webClient) { + this.restUtils = restUtils; + this.constants = constants; + this.webClient = webClient; + } + + @Transactional + @Retry(name = "searchbypen") + public Student getStudentByPen(String pen, String accessToken) { + logger.debug("Get Student by PEN [Service]"); + + Student student; + List 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 void 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); + } + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java index 28e9c623..b947fef3 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java @@ -16,11 +16,14 @@ public class EducGradDataConversionApiConstants { 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_STUDENT_ROOT_MAPPING = "/api/" + API_VERSION + "/student"; // 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 = "/pen/{pen}"; + public static final String GRAD_CASCADE_DELETE_STUDENT_BY_PEN = "/pen/{pen}"; // Util public static final String PEN_UPDATES_PARALLEL_BATCH_JOB = "/penUpdates/parallel"; @@ -33,8 +36,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; @@ -101,6 +102,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; diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/RestUtils.java index c3e5f840..7da5ff66 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/RestUtils.java @@ -76,6 +76,20 @@ public List getStudentsByPen(String pen, String accessToken) { .retrieve().bodyToMono(responseType).block(); } + public List getStudentNotesByStudentId(String studentID, String accessToken) { + + log.debug("GET student Notes: {}", String.format(constants.getGradStudentNotesByStudentID(), studentID)); + final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { + }; + return this.webClient.get() + .uri(String.format(constants.getGradStudentNotesByStudentID(), studentID)) + .headers(h -> { + h.setBearerAuth(accessToken); + h.set(EducGradDataConversionApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); + }) + .retrieve().bodyToMono(responseType).block(); + } + public OptionalProgram getOptionalProgram(String programCode, String specialProgramCode, String accessToken) { return this.webClient.get() .uri(constants.getGradOptionalProgramUrl(), uri -> uri.path("/{programCode}/{specialProgramCode}").build(programCode, specialProgramCode)) From ad93be70254ad8144fc163cd2c71c596c9b97fab Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Mon, 4 Mar 2024 09:37:38 -0700 Subject: [PATCH 02/30] GRAD2-2465 - Delete a student and related data --- api/src/main/resources/application.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index 2d03219e..2a433145 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -210,6 +210,8 @@ endpoint: remove-student-career-program: ${GRAD_STUDENT_API}api/v1/student/conv/studentcareerprogram/%s/%s read-student-career-programs: ${GRAD_STUDENT_API}api/v1/student/studentcareerprogram/studentid/%s save-grad-student-record-for-ongoing-updates: ${GRAD_STUDENT_API}api/v1/student/conv/ongoingupdate/gradstatus + get-student-by-pen: ${GRAD_STUDENT_API}api/v1/student/pen/%s + get-student-notes-by-studentID: ${GRAD_STUDENT_API}api/v1/student/studentnotes/studentid/%s grad-assessment-api: assessment-requirement: url: ${GRAD_ASSESSMENT_API}api/v1/assessment/requirement From 40a8e242efa8ebb05fc78cff604adfb655819631 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Mon, 4 Mar 2024 09:38:42 -0700 Subject: [PATCH 03/30] GRAD2-2465 - Delete a student and related data --- .../ca/bc/gov/educ/api/dataconversion/model/StudentNote.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/StudentNote.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/StudentNote.java index 95643b98..c814be1b 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/StudentNote.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/StudentNote.java @@ -3,12 +3,10 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; import java.util.UUID; @Data -@SuperBuilder @AllArgsConstructor @NoArgsConstructor public class StudentNote extends BaseModel { From ed71dea2791a5e432a573d8620507651b2c4b3a2 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Mon, 4 Mar 2024 10:52:20 -0700 Subject: [PATCH 04/30] GRAD2-2465 - Delete a student and related data --- api/src/test/resources/application.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index fee5931c..e901af27 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -137,6 +137,8 @@ endpoint: remove-student-career-program: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/conv/studentcareerprogram/%s/%s read-student-career-programs: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/studentcareerprogram/studentid/%s save-grad-student-record-for-ongoing-updates: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/conv/ongoingupdate/gradstatus + get-student-by-pen: ${GRAD_STUDENT_API}api/v1/student/pen/%s + get-student-notes-by-studentID: ${GRAD_STUDENT_API}api/v1/student/studentnotes/studentid/%s grad-assessment-api: assessment-requirement: url: https://educ-grad-assessment-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/assessment/requirement From d30a37b52f4f5f4cab74e0d0c81a776d7af6e93e Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Mon, 4 Mar 2024 11:05:36 -0700 Subject: [PATCH 05/30] GRAD2-2465 - Delete a student and related data --- api/src/test/resources/application.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index e901af27..0bc2ea50 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -137,8 +137,8 @@ endpoint: remove-student-career-program: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/conv/studentcareerprogram/%s/%s read-student-career-programs: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/studentcareerprogram/studentid/%s save-grad-student-record-for-ongoing-updates: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/conv/ongoingupdate/gradstatus - get-student-by-pen: ${GRAD_STUDENT_API}api/v1/student/pen/%s - get-student-notes-by-studentID: ${GRAD_STUDENT_API}api/v1/student/studentnotes/studentid/%s + get-student-by-pen: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/pen/%s + get-student-notes-by-studentID: https://educ-grad-student-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/student/studentnotes/studentid/%s grad-assessment-api: assessment-requirement: url: https://educ-grad-assessment-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/assessment/requirement From ffba551e8d281e969c7bde340359318f81df3152 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Mon, 4 Mar 2024 11:50:27 -0700 Subject: [PATCH 06/30] GRAD2-2465 - Delete a student and related data --- .../api/dataconversion/config/WebSecurityConfiguration.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/config/WebSecurityConfiguration.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/config/WebSecurityConfiguration.java index 283e9824..e89cd61d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/config/WebSecurityConfiguration.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/config/WebSecurityConfiguration.java @@ -16,6 +16,10 @@ @EnableWebSecurity public class WebSecurityConfiguration { + public WebSecurityConfiguration() { + SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL); + } + @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http From cd94e1d8c23fe5b3aa13b116c730145c655d5cb5 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Mon, 4 Mar 2024 12:01:48 -0700 Subject: [PATCH 07/30] GRAD2-2465 - Delete a student and related data --- .../api/dataconversion/config/WebSecurityConfiguration.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/config/WebSecurityConfiguration.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/config/WebSecurityConfiguration.java index e89cd61d..283e9824 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/config/WebSecurityConfiguration.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/config/WebSecurityConfiguration.java @@ -16,10 +16,6 @@ @EnableWebSecurity public class WebSecurityConfiguration { - public WebSecurityConfiguration() { - SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL); - } - @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http From 9a83a719e586ecb2497f908174b6cf86af1ae52b Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Mon, 4 Mar 2024 13:39:30 -0700 Subject: [PATCH 08/30] GRAD2-2465 - Delete a student and related data --- .../dataconversion/controller/JobLauncherController.java | 2 +- .../api/dataconversion/controller/StudentController.java | 2 +- .../util/EducGradDataConversionApiConstants.java | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/JobLauncherController.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/JobLauncherController.java index b12c8120..eb825922 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/JobLauncherController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/JobLauncherController.java @@ -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")) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java index 0cbc1fee..4385dbfe 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java @@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.*; @RestController -@RequestMapping(EducGradDataConversionApiConstants.GRAD_STUDENT_ROOT_MAPPING) +@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")) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java index b947fef3..f1704a40 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java @@ -15,15 +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_STUDENT_ROOT_MAPPING = "/api/" + API_VERSION + "/student"; + 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 = "/pen/{pen}"; - public static final String GRAD_CASCADE_DELETE_STUDENT_BY_PEN = "/pen/{pen}"; + public static final String GRAD_STUDENT_BY_PEN_STUDENT_API = "/student/pen/{pen}"; + public static final String GRAD_CASCADE_DELETE_STUDENT_BY_PEN = "/student/pen/{pen}"; // Util public static final String PEN_UPDATES_PARALLEL_BATCH_JOB = "/penUpdates/parallel"; From 52973185812b151cc9d2565693dc3b750878aefe Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Wed, 6 Mar 2024 22:35:04 -0700 Subject: [PATCH 09/30] GRAD2-2465 - Delete a student and related data --- .../dataconversion/service/NewStudentEventServiceTest.java | 4 ++++ .../service/StudentAssessmentUpdateEventServiceTest.java | 4 ++++ .../service/StudentCourseUpdateEventServiceTest.java | 4 ++++ .../service/StudentDemographicsUpdateEventServiceTest.java | 4 ++++ .../service/StudentFrenchImmersionEventServiceTest.java | 4 ++++ .../service/StudentGraduationUpdateEventServiceTest.java | 4 ++++ .../service/StudentStatusUpdateEventServiceTest.java | 4 ++++ .../service/StudentXProgramEventServiceTest.java | 4 ++++ 8 files changed, 32 insertions(+) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/NewStudentEventServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/NewStudentEventServiceTest.java index 55d0e4a5..08363b3f 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/NewStudentEventServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/NewStudentEventServiceTest.java @@ -18,6 +18,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; import java.util.Arrays; import java.util.Optional; @@ -45,6 +46,9 @@ public class NewStudentEventServiceTest { @MockBean RestUtils restUtils; + @MockBean + WebClient webClient; + // NATS @MockBean private NatsConnection natsConnection; diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentAssessmentUpdateEventServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentAssessmentUpdateEventServiceTest.java index 9b8c48d3..58fe1e1c 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentAssessmentUpdateEventServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentAssessmentUpdateEventServiceTest.java @@ -18,6 +18,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; import java.util.Optional; import java.util.UUID; @@ -44,6 +45,9 @@ public class StudentAssessmentUpdateEventServiceTest { @MockBean RestUtils restUtils; + @MockBean + WebClient webClient; + // NATS @MockBean private NatsConnection natsConnection; diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentCourseUpdateEventServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentCourseUpdateEventServiceTest.java index d65d1258..9f9319f5 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentCourseUpdateEventServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentCourseUpdateEventServiceTest.java @@ -18,6 +18,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; import java.util.Optional; import java.util.UUID; @@ -44,6 +45,9 @@ public class StudentCourseUpdateEventServiceTest { @MockBean RestUtils restUtils; + @MockBean + WebClient webClient; + // NATS @MockBean private NatsConnection natsConnection; diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentDemographicsUpdateEventServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentDemographicsUpdateEventServiceTest.java index 8c904691..9a858067 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentDemographicsUpdateEventServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentDemographicsUpdateEventServiceTest.java @@ -18,6 +18,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; import java.util.Optional; import java.util.UUID; @@ -44,6 +45,9 @@ public class StudentDemographicsUpdateEventServiceTest { @MockBean RestUtils restUtils; + @MockBean + WebClient webClient; + // NATS @MockBean private NatsConnection natsConnection; diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentFrenchImmersionEventServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentFrenchImmersionEventServiceTest.java index 699a86d8..db7962ac 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentFrenchImmersionEventServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentFrenchImmersionEventServiceTest.java @@ -18,6 +18,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; import java.util.Optional; import java.util.UUID; @@ -44,6 +45,9 @@ public class StudentFrenchImmersionEventServiceTest { @MockBean RestUtils restUtils; + @MockBean + WebClient webClient; + // NATS @MockBean private NatsConnection natsConnection; diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentGraduationUpdateEventServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentGraduationUpdateEventServiceTest.java index b99513c2..20a38f27 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentGraduationUpdateEventServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentGraduationUpdateEventServiceTest.java @@ -18,6 +18,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; import java.util.Optional; import java.util.UUID; @@ -44,6 +45,9 @@ public class StudentGraduationUpdateEventServiceTest { @MockBean RestUtils restUtils; + @MockBean + WebClient webClient; + // NATS @MockBean private NatsConnection natsConnection; diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentStatusUpdateEventServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentStatusUpdateEventServiceTest.java index d92072a1..8c944ab5 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentStatusUpdateEventServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentStatusUpdateEventServiceTest.java @@ -18,6 +18,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; import java.util.Arrays; import java.util.Optional; @@ -45,6 +46,9 @@ public class StudentStatusUpdateEventServiceTest { @MockBean RestUtils restUtils; + @MockBean + WebClient webClient; + // NATS @MockBean private NatsConnection natsConnection; diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentXProgramEventServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentXProgramEventServiceTest.java index 7a3aa9b2..ce36a69f 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentXProgramEventServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentXProgramEventServiceTest.java @@ -18,6 +18,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; import java.util.ArrayList; import java.util.Arrays; @@ -46,6 +47,9 @@ public class StudentXProgramEventServiceTest { @MockBean RestUtils restUtils; + @MockBean + WebClient webClient; + // NATS @MockBean private NatsConnection natsConnection; From 78965eda467ee4b054262ba5234fb53458fa995b Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 00:51:32 -0700 Subject: [PATCH 10/30] GRAD2-2465 - Delete a student and related data --- .../controller/StudentControllerTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java new file mode 100644 index 00000000..5dce16fd --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java @@ -0,0 +1,43 @@ +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 org.junit.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.batch.core.configuration.JobRegistry; +import org.springframework.batch.core.launch.JobLauncher; + +import java.util.List; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) +public class StudentControllerTest { + + @Mock + private StudentService studentService; + + @Test + public void testGetGradStudentByPenFromStudentAPI() { + // ID + UUID studentID = UUID.randomUUID(); + + String pen = "123456789"; + String accessToken = "Bearer accesstoken"; + + Student student = new Student(); + + Mockito.when(studentService.getStudentByPen(pen,accessToken)).thenReturn(student); + studentService.getStudentByPen(pen,accessToken.replaceAll("Bearer ", "")); + //Mockito.verify(gradStudentReportService).getGradStudentDataByMincode(reportGradStudentData.getMincode()); + + } +} From 5afaa6a5a210a3be07baf248d9b6ebac2b1edc64 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 00:52:18 -0700 Subject: [PATCH 11/30] GRAD2-2465 - Delete a student and related data --- .../api/dataconversion/controller/StudentControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java index 5dce16fd..41450c66 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java @@ -37,7 +37,7 @@ public void testGetGradStudentByPenFromStudentAPI() { Mockito.when(studentService.getStudentByPen(pen,accessToken)).thenReturn(student); studentService.getStudentByPen(pen,accessToken.replaceAll("Bearer ", "")); - //Mockito.verify(gradStudentReportService).getGradStudentDataByMincode(reportGradStudentData.getMincode()); + Mockito.verify(studentService).getStudentByPen(pen,accessToken); } } From 298ccfee9e46bbf8d2739ae371bd4f0ccfe60b4f Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 00:57:08 -0700 Subject: [PATCH 12/30] GRAD2-2465 - Delete a student and related data --- .../api/dataconversion/controller/StudentControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java index 41450c66..95130460 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java @@ -36,7 +36,7 @@ public void testGetGradStudentByPenFromStudentAPI() { Student student = new Student(); Mockito.when(studentService.getStudentByPen(pen,accessToken)).thenReturn(student); - studentService.getStudentByPen(pen,accessToken.replaceAll("Bearer ", "")); + studentService.getStudentByPen(pen,accessToken.replaceAll("Bearer ", accessToken)); Mockito.verify(studentService).getStudentByPen(pen,accessToken); } From 577d801c264cb0ec12a4c36357c868898e3640b8 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 00:57:40 -0700 Subject: [PATCH 13/30] GRAD2-2465 - Delete a student and related data --- .../api/dataconversion/controller/StudentControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java index 95130460..de83237e 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java @@ -37,7 +37,7 @@ public void testGetGradStudentByPenFromStudentAPI() { Mockito.when(studentService.getStudentByPen(pen,accessToken)).thenReturn(student); studentService.getStudentByPen(pen,accessToken.replaceAll("Bearer ", accessToken)); - Mockito.verify(studentService).getStudentByPen(pen,accessToken); + Mockito.verify(studentService).getStudentByPen(pen, "accesstoken"); } } From c161f818dd9009553d510eb31b2402e5a8ca48e1 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 01:01:20 -0700 Subject: [PATCH 14/30] GRAD2-2465 - Delete a student and related data --- .../api/dataconversion/controller/StudentControllerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java index de83237e..bb2bb9e1 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java @@ -35,9 +35,9 @@ public void testGetGradStudentByPenFromStudentAPI() { Student student = new Student(); - Mockito.when(studentService.getStudentByPen(pen,accessToken)).thenReturn(student); + Mockito.when(studentService.getStudentByPen(pen,accessToken.replaceAll("Bearer ", accessToken))).thenReturn(student); studentService.getStudentByPen(pen,accessToken.replaceAll("Bearer ", accessToken)); - Mockito.verify(studentService).getStudentByPen(pen, "accesstoken"); + Mockito.verify(studentService).getStudentByPen(pen, accessToken.replaceAll("Bearer ", accessToken)); } } From 59b9e5b34d31c1cafe5ddde190ce33dae348c80d Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 13:45:25 -0700 Subject: [PATCH 15/30] GRAD2-2465 - Delete a student and related data --- .../service/student/StudentService.java | 3 ++- .../controller/StudentControllerTest.java | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java index ef37a96b..9b0ed0dd 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java @@ -56,7 +56,7 @@ public Student getStudentByPen(String pen, String accessToken) { } @Transactional - public void cascadeDeleteStudent(String pen, String accessToken) { + public String cascadeDeleteStudent(String pen, String accessToken) { logger.debug("Cascade Delete a Student [Service]"); //GET Student by PEN @@ -76,5 +76,6 @@ Delete All student related data ({STUDENT_API}/api/v1/student/conv/studentid/{st */ restUtils.removeAllStudentRelatedData(UUID.fromString(studentID), accessToken); } + return pen; } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java index bb2bb9e1..b66051dc 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java @@ -27,8 +27,6 @@ public class StudentControllerTest { @Test public void testGetGradStudentByPenFromStudentAPI() { - // ID - UUID studentID = UUID.randomUUID(); String pen = "123456789"; String accessToken = "Bearer accesstoken"; @@ -40,4 +38,18 @@ public void testGetGradStudentByPenFromStudentAPI() { Mockito.verify(studentService).getStudentByPen(pen, accessToken.replaceAll("Bearer ", accessToken)); } + + @Test + public void testCascadeDeleteStudent() { + + String pen = "123456789"; + String accessToken = "Bearer accesstoken"; + + Student student = new Student(); + + Mockito.when(studentService.cascadeDeleteStudent(pen, accessToken.replaceAll("Bearer ", accessToken))).thenReturn(pen); + studentService.cascadeDeleteStudent(pen,accessToken.replaceAll("Bearer ", accessToken)); + Mockito.verify(studentService).cascadeDeleteStudent(pen, accessToken.replaceAll("Bearer ", accessToken)); + + } } From a0dafa759c586984119aa1c256e24e0899b43376 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 14:00:26 -0700 Subject: [PATCH 16/30] GRAD2-2465 - Delete a student and related data --- .../service/StudentServiceTest.java | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java new file mode 100644 index 00000000..e66cfcfc --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java @@ -0,0 +1,101 @@ +package ca.bc.gov.educ.api.dataconversion.service; + +import ca.bc.gov.educ.api.dataconversion.constant.EventStatus; +import ca.bc.gov.educ.api.dataconversion.constant.EventType; +import ca.bc.gov.educ.api.dataconversion.entity.Event; +import ca.bc.gov.educ.api.dataconversion.messaging.NatsConnection; +import ca.bc.gov.educ.api.dataconversion.messaging.jetstream.Subscriber; +import ca.bc.gov.educ.api.dataconversion.model.ConvGradStudent; +import ca.bc.gov.educ.api.dataconversion.model.ConversionStudentSummaryDTO; +import ca.bc.gov.educ.api.dataconversion.model.Student; +import ca.bc.gov.educ.api.dataconversion.process.StudentProcess; +import ca.bc.gov.educ.api.dataconversion.repository.EventRepository; +import ca.bc.gov.educ.api.dataconversion.service.student.NewStudentEventService; +import ca.bc.gov.educ.api.dataconversion.service.student.StudentService; +import ca.bc.gov.educ.api.dataconversion.util.EducGradDataConversionApiConstants; +import ca.bc.gov.educ.api.dataconversion.util.RestUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; + +import java.util.*; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +@RunWith(SpringRunner.class) +@SpringBootTest +@ActiveProfiles("test") +public class StudentServiceTest { + + @Autowired + StudentService studentService; + + @MockBean + RestUtils restUtils; + + @MockBean + WebClient webClient; + + @Autowired + private EducGradDataConversionApiConstants constants; + + @Test + public void testGetStudentByPen_given_PEN_returnsAPICallSuccess() { + String pen = "123456789"; + String accessToken = "Bearer accesstoken"; + + Student student = new Student(); + student.setPen(pen); + List penList = List.of(student); + + when(this.restUtils.getStudentsByPen(pen, accessToken)).thenReturn(penList); + studentService.getStudentByPen(pen, accessToken); + + assertThat(penList).isNotNull(); + } + + /*@Test + public void testProcessStudent_whenException_isThrown_returnsAPICallError() throws Exception { + // ID + String pen = "111222333"; + + // Program & School + String program = "2018-EN"; + String mincode = "222333"; + + String updateType = "NEWSTUDENT"; + + // ConvGradStudent = traxStudent with the recent updated info + ConvGradStudent traxNewStudent = ConvGradStudent.builder() + .pen(pen) + .program(program) + .studentGrade("11") + .studentStatus("A") + .schoolOfRecord(mincode) + .schoolAtGrad(mincode) + .graduationRequirementYear("2018") + .programCodes(Arrays.asList("XC","FI")).build(); + + // Event + Event event = new Event(); + event.setEventType(EventType.NEWSTUDENT.name()); + event.setEventStatus(EventStatus.DB_COMMITTED.name()); + event.setActivityCode(updateType); + event.setEventId(UUID.randomUUID()); + + when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); + when(this.studentProcess.convertStudent(any(), any(), eq(false), eq(true))).thenThrow(new RuntimeException("Test Exception is thrown!")); + newStudentEventService.processEvent(traxNewStudent, event); + + assertThat(event).isNotNull(); + assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); + }*/ +} From 6932caf1cdae817a826bdf7890ecc8c2fc9b4573 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 14:13:44 -0700 Subject: [PATCH 17/30] GRAD2-2465 - Delete a student and related data --- .../controller/StudentControllerTest.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java index b66051dc..8d8358d7 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/controller/StudentControllerTest.java @@ -5,18 +5,10 @@ import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.batch.core.configuration.JobRegistry; -import org.springframework.batch.core.launch.JobLauncher; - -import java.util.List; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; @RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class) @@ -30,13 +22,11 @@ public void testGetGradStudentByPenFromStudentAPI() { String pen = "123456789"; String accessToken = "Bearer accesstoken"; - Student student = new Student(); Mockito.when(studentService.getStudentByPen(pen,accessToken.replaceAll("Bearer ", accessToken))).thenReturn(student); studentService.getStudentByPen(pen,accessToken.replaceAll("Bearer ", accessToken)); Mockito.verify(studentService).getStudentByPen(pen, accessToken.replaceAll("Bearer ", accessToken)); - } @Test @@ -44,7 +34,6 @@ public void testCascadeDeleteStudent() { String pen = "123456789"; String accessToken = "Bearer accesstoken"; - Student student = new Student(); Mockito.when(studentService.cascadeDeleteStudent(pen, accessToken.replaceAll("Bearer ", accessToken))).thenReturn(pen); From 2dcef527a18bc909f4bc19c15d2523b8534741c4 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 14:19:12 -0700 Subject: [PATCH 18/30] GRAD2-2465 - Delete a student and related data --- .../educ/api/dataconversion/service/StudentServiceTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java index e66cfcfc..635c9906 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java @@ -44,6 +44,12 @@ public class StudentServiceTest { @MockBean WebClient webClient; + // NATS + @MockBean + private NatsConnection natsConnection; + @MockBean + private Subscriber subscriber; + @Autowired private EducGradDataConversionApiConstants constants; From 8629571f37c68a6f87fe255ec228d1240f3036d2 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 14:35:14 -0700 Subject: [PATCH 19/30] GRAD2-2465 - Delete a student and related data --- .../service/StudentServiceTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java index 635c9906..9fdf0dc2 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java @@ -68,6 +68,21 @@ public void testGetStudentByPen_given_PEN_returnsAPICallSuccess() { assertThat(penList).isNotNull(); } + @Test + public void testGetStudentByPen_given_PEN_returnsNULL() { + String pen = "123456789"; + String accessToken = "Bearer accesstoken"; + + Student student = new Student(); + student.setPen(pen); + List penList = List.of(student); + + when(this.restUtils.getStudentsByPen(pen, accessToken)).thenReturn(null); + Student s = studentService.getStudentByPen(pen, accessToken); + + assertThat(s).isNull(); + } + /*@Test public void testProcessStudent_whenException_isThrown_returnsAPICallError() throws Exception { // ID From bf907e684cec34d1d40a9a798272c516df7a0bcb Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 14:35:31 -0700 Subject: [PATCH 20/30] GRAD2-2465 - Delete a student and related data --- .../service/StudentServiceTest.java | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java index 9fdf0dc2..6fd87869 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java @@ -82,41 +82,4 @@ public void testGetStudentByPen_given_PEN_returnsNULL() { assertThat(s).isNull(); } - - /*@Test - public void testProcessStudent_whenException_isThrown_returnsAPICallError() throws Exception { - // ID - String pen = "111222333"; - - // Program & School - String program = "2018-EN"; - String mincode = "222333"; - - String updateType = "NEWSTUDENT"; - - // ConvGradStudent = traxStudent with the recent updated info - ConvGradStudent traxNewStudent = ConvGradStudent.builder() - .pen(pen) - .program(program) - .studentGrade("11") - .studentStatus("A") - .schoolOfRecord(mincode) - .schoolAtGrad(mincode) - .graduationRequirementYear("2018") - .programCodes(Arrays.asList("XC","FI")).build(); - - // Event - Event event = new Event(); - event.setEventType(EventType.NEWSTUDENT.name()); - event.setEventStatus(EventStatus.DB_COMMITTED.name()); - event.setActivityCode(updateType); - event.setEventId(UUID.randomUUID()); - - when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); - when(this.studentProcess.convertStudent(any(), any(), eq(false), eq(true))).thenThrow(new RuntimeException("Test Exception is thrown!")); - newStudentEventService.processEvent(traxNewStudent, event); - - assertThat(event).isNotNull(); - assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); - }*/ } From 2f02f375fa51933f4ee016105c70cd3d8f538174 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 16:25:33 -0700 Subject: [PATCH 21/30] GRAD2-2465 - Delete a student and related data --- .../dataconversion/service/StudentServiceTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java index 6fd87869..db7a24c4 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java @@ -26,6 +26,7 @@ import java.util.*; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -82,4 +83,17 @@ public void testGetStudentByPen_given_PEN_returnsNULL() { assertThat(s).isNull(); } + + @Test(expected = Exception.class) + public void testGetStudentByPen_given_PEN_throws_exception() { + String pen = "123456789"; + String accessToken = "Bearer accesstoken"; + + Student student = new Student(); + student.setPen(pen); + List penList = List.of(student); + + when(this.restUtils.getStudentsByPen(pen, accessToken)).thenThrow(Exception.class); + Student s = studentService.getStudentByPen(pen, accessToken); + } } From cff1c7a83bd9786f65286f5c282d856a9c1e22ee Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 16:31:59 -0700 Subject: [PATCH 22/30] GRAD2-2465 - Delete a student and related data --- .../gov/educ/api/dataconversion/service/StudentServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java index db7a24c4..5054e1a3 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java @@ -78,7 +78,7 @@ public void testGetStudentByPen_given_PEN_returnsNULL() { student.setPen(pen); List penList = List.of(student); - when(this.restUtils.getStudentsByPen(pen, accessToken)).thenReturn(null); + when(this.restUtils.getStudentsByPen(pen, accessToken)).thenReturn(new ArrayList()); Student s = studentService.getStudentByPen(pen, accessToken); assertThat(s).isNull(); From aeecf469d3805c71ca874635d46aa7204467ee18 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 17:36:53 -0700 Subject: [PATCH 23/30] GRAD2-2465 - Delete a student and related data --- .../service/StudentServiceTest.java | 20 +++++++++++--- .../dataconversion/util/RestUtilsTest.java | 27 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java index 5054e1a3..bb47f062 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentServiceTest.java @@ -16,6 +16,7 @@ import ca.bc.gov.educ.api.dataconversion.util.RestUtils; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -51,9 +52,6 @@ public class StudentServiceTest { @MockBean private Subscriber subscriber; - @Autowired - private EducGradDataConversionApiConstants constants; - @Test public void testGetStudentByPen_given_PEN_returnsAPICallSuccess() { String pen = "123456789"; @@ -96,4 +94,20 @@ public void testGetStudentByPen_given_PEN_throws_exception() { when(this.restUtils.getStudentsByPen(pen, accessToken)).thenThrow(Exception.class); Student s = studentService.getStudentByPen(pen, accessToken); } + + @Test + public void testCascadeDeleteStudentBy_given_PEN_returnsAPICallSuccess() { + String pen = "123456789"; + String studentID = "0a614e84-7e27-1815-817e-fad384090090"; + String accessToken = "Bearer accesstoken"; + + Student student = new Student(); + student.setPen(pen); + student.setStudentID(studentID); + List penList = List.of(student); + + when(this.restUtils.getStudentsByPen(pen, accessToken)).thenReturn(penList); + studentService.cascadeDeleteStudent(pen, accessToken); + Mockito.verify(restUtils).removeAllStudentRelatedData(UUID.fromString(studentID), accessToken); + } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/util/RestUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/util/RestUtilsTest.java index dbd49fbe..1a72ae8f 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/util/RestUtilsTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/util/RestUtilsTest.java @@ -368,4 +368,31 @@ public void testUpdateStudentFallbackMethod_givenException_shouldReturnNull(){ val result = this.restUtils.rtUpdateStudentGradStatusFallback(new HttpServerErrorException(HttpStatus.I_AM_A_TEAPOT)); assertThat(result).isNull(); } + + @Test + public void testGetStudentNotesByStudentId_returnsTrue_with_APICallSuccess() { + + final String studentID = "0a614e84-7e27-1815-817e-fad384090090"; + final String noteID = "0a614e84-7e27-1815-817e-fad384090090"; + String accessToken = "Bearer accesstoken"; + StudentNote note = new StudentNote(); + note.setStudentID(studentID); + note.setNote("Sample Note"); + note.setId(UUID.fromString(noteID)); + + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getGradStudentNotesByStudentID(), studentID))) + .thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + + final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { + }; + when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(Arrays.asList(note))); + + val result = this.restUtils.getStudentNotesByStudentId(studentID, accessToken); + assertThat(result).isNotNull(); + assertThat(result.size() > 0).isTrue(); + assertThat(result.get(0).getStudentID()).isEqualTo(studentID); + } } From 724ffd1ef786fdf72e4eedfa30b3ca9053459246 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 17:45:47 -0700 Subject: [PATCH 24/30] GRAD2-2465 - Delete a student and related data --- .../api/dataconversion/service/student/StudentService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java index 9b0ed0dd..b39e5558 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java @@ -22,13 +22,11 @@ public class StudentService { private static final Logger logger = LoggerFactory.getLogger(StudentService.class); private final RestUtils restUtils; - private final EducGradDataConversionApiConstants constants; final WebClient webClient; @Autowired - public StudentService(RestUtils restUtils, EducGradDataConversionApiConstants constants, WebClient webClient) { + public StudentService(RestUtils restUtils, WebClient webClient) { this.restUtils = restUtils; - this.constants = constants; this.webClient = webClient; } From 4e86b1df86165c43597bd225181fa733176f062e Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 7 Mar 2024 17:50:50 -0700 Subject: [PATCH 25/30] GRAD2-2465 - Delete a student and related data --- .../ca/bc/gov/educ/api/dataconversion/util/RestUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/util/RestUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/util/RestUtilsTest.java index 1a72ae8f..310c84ed 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/util/RestUtilsTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/util/RestUtilsTest.java @@ -392,7 +392,7 @@ public void testGetStudentNotesByStudentId_returnsTrue_with_APICallSuccess() { val result = this.restUtils.getStudentNotesByStudentId(studentID, accessToken); assertThat(result).isNotNull(); - assertThat(result.size() > 0).isTrue(); + assertThat(!result.isEmpty()).isTrue(); assertThat(result.get(0).getStudentID()).isEqualTo(studentID); } } From 6749516712ac836332c189d2e3a486e7efef84cc Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Thu, 14 Mar 2024 11:03:24 -0600 Subject: [PATCH 26/30] GRAD2-2465 - Delete a student and related data --- .../controller/StudentController.java | 19 +++++++++++++++++-- .../EducGradDataConversionApiConstants.java | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java index 4385dbfe..ef81db1f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java @@ -14,6 +14,9 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; +import java.util.List; +import java.util.UUID; + @RestController @RequestMapping(EducGradDataConversionApiConstants.GRAD_DATA_CONVERSION_API_ROOT_MAPPING) @CrossOrigin @@ -32,7 +35,7 @@ public class StudentController { @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 ", "")); + return studentService.getStudentByPen(pen, accessToken.replaceAll("Bearer ", "")); } @DeleteMapping(EducGradDataConversionApiConstants.GRAD_CASCADE_DELETE_STUDENT_BY_PEN) @@ -41,6 +44,18 @@ public Student getGradStudentByPenFromStudentAPI(@PathVariable String pen, @Requ @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 ", "")); + studentService.cascadeDeleteStudent(pen, accessToken.replaceAll("Bearer ", "")); + } + + @DeleteMapping(EducGradDataConversionApiConstants.GRAD_CASCADE_DELETE_STUDENTS_BY_PENLIST) + @PreAuthorize("hasAuthority('SCOPE_READ_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 penList, @RequestHeader(name="Authorization") String accessToken) { + logger.debug("Cascade Delete a Student [Controller]"); + penList.forEach(pen -> { + studentService.cascadeDeleteStudent(pen, accessToken.replaceAll("Bearer ", "")); + }); + } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java index f1704a40..2c75bbd3 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java @@ -23,6 +23,7 @@ public class EducGradDataConversionApiConstants { 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_CASCADE_DELETE_STUDENT_BY_PEN = "/student/pen/{pen}"; + public static final String GRAD_CASCADE_DELETE_STUDENTS_BY_PENLIST = "/student/penlist"; // Util public static final String PEN_UPDATES_PARALLEL_BATCH_JOB = "/penUpdates/parallel"; From c4ab0283a03ea9c6062d2ab6039a8771efe50bfc Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Fri, 15 Mar 2024 12:35:38 -0600 Subject: [PATCH 27/30] GRAD2-2465 - Delete a student and related data --- .../api/dataconversion/controller/StudentController.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java index ef81db1f..951cf354 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java @@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.*; import java.util.List; -import java.util.UUID; @RestController @RequestMapping(EducGradDataConversionApiConstants.GRAD_DATA_CONVERSION_API_ROOT_MAPPING) @@ -39,7 +38,7 @@ public Student getGradStudentByPenFromStudentAPI(@PathVariable String pen, @Requ } @DeleteMapping(EducGradDataConversionApiConstants.GRAD_CASCADE_DELETE_STUDENT_BY_PEN) - @PreAuthorize("hasAuthority('SCOPE_READ_GRAD_STUDENT_DATA')") + @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) { @@ -48,7 +47,7 @@ public void cascadeDeleteStudent(@PathVariable String pen, @RequestHeader(name=" } @DeleteMapping(EducGradDataConversionApiConstants.GRAD_CASCADE_DELETE_STUDENTS_BY_PENLIST) - @PreAuthorize("hasAuthority('SCOPE_READ_GRAD_STUDENT_DATA')") + @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 penList, @RequestHeader(name="Authorization") String accessToken) { From 883adbc2e542014bf6ef9dd0ac3ba55d2d88c564 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Fri, 15 Mar 2024 12:36:01 -0600 Subject: [PATCH 28/30] GRAD2-2465 - Delete a student and related data --- .../educ/api/dataconversion/controller/StudentController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java index 951cf354..9f161bd4 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java @@ -55,6 +55,5 @@ public void cascadeDeleteStudents(@RequestBody List penList, @RequestHea penList.forEach(pen -> { studentService.cascadeDeleteStudent(pen, accessToken.replaceAll("Bearer ", "")); }); - } } From f84f6edcd3be295e1983818e3bf37f95a9d572b0 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Fri, 15 Mar 2024 16:55:25 -0600 Subject: [PATCH 29/30] GRAD2-2465 - Delete a student and related data --- .../controller/StudentController.java | 4 ++-- .../service/student/StudentService.java | 11 +++++++++++ .../EducGradDataConversionApiConstants.java | 6 ++++-- .../api/dataconversion/util/RestUtils.java | 18 ++++++++++++++++++ api/src/main/resources/application.yaml | 4 ++++ tools/config/update-configmap.sh | 1 + 6 files changed, 40 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java index 9f161bd4..4a1343a4 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/controller/StudentController.java @@ -37,7 +37,7 @@ public Student getGradStudentByPenFromStudentAPI(@PathVariable String pen, @Requ return studentService.getStudentByPen(pen, accessToken.replaceAll("Bearer ", "")); } - @DeleteMapping(EducGradDataConversionApiConstants.GRAD_CASCADE_DELETE_STUDENT_BY_PEN) + @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")}) @@ -46,7 +46,7 @@ public void cascadeDeleteStudent(@PathVariable String pen, @RequestHeader(name=" studentService.cascadeDeleteStudent(pen, accessToken.replaceAll("Bearer ", "")); } - @DeleteMapping(EducGradDataConversionApiConstants.GRAD_CASCADE_DELETE_STUDENTS_BY_PENLIST) + @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")}) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java index b39e5558..20b4a4dd 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentService.java @@ -73,6 +73,17 @@ Delete All student related data ({STUDENT_API}/api/v1/student/conv/studentid/{st 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; } diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java index 2c75bbd3..76ed6d79 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/EducGradDataConversionApiConstants.java @@ -22,8 +22,7 @@ public class EducGradDataConversionApiConstants { 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_CASCADE_DELETE_STUDENT_BY_PEN = "/student/pen/{pen}"; - public static final String GRAD_CASCADE_DELETE_STUDENTS_BY_PENLIST = "/student/penlist"; + public static final String GRAD_STUDENTS_BY_PENLIST_STUDENT_API = "/student/penlist"; // Util public static final String PEN_UPDATES_PARALLEL_BATCH_JOB = "/penUpdates/parallel"; @@ -162,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; diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/RestUtils.java index 7da5ff66..7c80a996 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/util/RestUtils.java @@ -360,6 +360,16 @@ public TraxStudentNo saveTraxStudentNo(TraxStudentNo traxStudentNo, String acces .retrieve().bodyToMono(TraxStudentNo.class).block(); } + public TraxStudentNo updateTraxStudentNo(String pen, String accessToken) { + return webClient.put() + .uri(String.format(constants.getSaveTraxStudentNoUrl(), pen)) + .headers(h -> { + h.setBearerAuth(accessToken); + h.set(EducGradDataConversionApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); + }) + .retrieve().bodyToMono(TraxStudentNo.class).block(); + } + // Read GraduationStudentRecord - GET /student/studentid/{id}/algorithm @Retry(name = "rt-getStudentGradStatus", fallbackMethod = "rtGetStudentGradStatusFallback") public GraduationStudentRecord getStudentGradStatus(String studentID, String accessToken) { @@ -394,6 +404,14 @@ public GraduationStudentRecord updateStudentGradStatusByFields(OngoingUpdateRequ }).body(BodyInserters.fromValue(requestDTO)).retrieve().bodyToMono(GraduationStudentRecord.class).block(); } + public void removeAllStudentAchievements(UUID studentID, String accessToken) { + webClient.delete().uri(String.format(constants.getDeleteStudentAchievementsUrl(),studentID)) + .headers(h -> { + h.setBearerAuth(accessToken); + h.set(EducGradDataConversionApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); + }).retrieve().onStatus(p -> p.value() == 404, error -> Mono.error(new Exception("Student Achievements Not Found"))).bodyToMono(Void.class).block(); + } + // Remove All Student Related Data - DELETE /student/conv/studentid/{id} public void removeAllStudentRelatedData(UUID studentID, String accessToken) { webClient.delete().uri(String.format(constants.getSaveGraduationStudentRecord(),studentID)) diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index 2a433145..ece58aa5 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -235,6 +235,10 @@ endpoint: url: ${GRAD_TRAX_API}api/v1/trax/common/course-restrictions get-course-requirements: url: ${GRAD_TRAX_API}api/v1/trax/common/course-requirements + grad-graduation-report-api: + delete-student-achievements: + url: ${GRAD_GRADUATION_REPORT_API}/api/v1/graduationreports/studentachievement/{studentID} + #Incremental Grad Update grad: diff --git a/tools/config/update-configmap.sh b/tools/config/update-configmap.sh index ca30ca8c..baa14221 100644 --- a/tools/config/update-configmap.sh +++ b/tools/config/update-configmap.sh @@ -62,6 +62,7 @@ oc create -n "$BUSINESS_NAMESPACE"-"$envValue" configmap "$APP_NAME"-config-map --from-literal=GRAD_PROGRAM_API="http://educ-grad-program-api.$GRAD_NAMESPACE-$envValue.svc.cluster.local:8080/" \ --from-literal=GRAD_STUDENT_API="http://educ-grad-student-api.$GRAD_NAMESPACE-$envValue.svc.cluster.local:8080/" \ --from-literal=GRAD_TRAX_API="http://educ-grad-trax-api.$GRAD_NAMESPACE-$envValue.svc.cluster.local:8080/" \ + --from-literal=GRAD_GRADUATION_REPORT_API="http://educ-grad-graduation-report-api.$GRAD_NAMESPACE-$envValue.svc.cluster.local:8080/" \ --from-literal=IDLE_TIMEOUT="400000" \ --from-literal=KEYCLOAK_TOKEN_URL="https://soam-$envValue.apps.silver.devops.gov.bc.ca/" \ --from-literal=MAXIMUM_POOL_SIZE="40" \ From 4b09679471dc3819638740229c742ac5a398f945 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Fri, 15 Mar 2024 17:57:03 -0600 Subject: [PATCH 30/30] GRAD2-2465 - Delete a student and related data --- api/src/main/resources/application.yaml | 2 +- api/src/test/resources/application.yaml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index ece58aa5..21dac332 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -237,7 +237,7 @@ endpoint: url: ${GRAD_TRAX_API}api/v1/trax/common/course-requirements grad-graduation-report-api: delete-student-achievements: - url: ${GRAD_GRADUATION_REPORT_API}/api/v1/graduationreports/studentachievement/{studentID} + url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/studentachievement/{studentID} #Incremental Grad Update diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index 0bc2ea50..41c15c43 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -162,6 +162,9 @@ endpoint: url: https://educ-grad-trax-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/trax/common/course-restrictions get-course-requirements: url: https://educ-grad-trax-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/trax/common/course-requirements + grad-graduation-report-api: + delete-student-achievements: + url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/studentachievement #Incremental Grad Update grad: