From 08a71ffb0ec21dea09df32758b2989a0ab0574d9 Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 3 Apr 2024 13:20:44 -0600 Subject: [PATCH 1/5] GRAD2-2570 Regenerate Certificate Process Modifications --- .../report/model/dto/StudentSearchRequest.java | 18 +++++++++++++----- .../GradStudentCertificatesRepository.java | 4 +++- .../api/grad/report/service/CommonService.java | 11 ++++++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/StudentSearchRequest.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/StudentSearchRequest.java index dcad7ff7..6cade99c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/StudentSearchRequest.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/StudentSearchRequest.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.grad.report.model.dto; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -7,6 +8,7 @@ import org.springframework.stereotype.Component; import java.io.Serializable; +import java.time.LocalDate; import java.util.List; import java.util.UUID; @@ -16,12 +18,18 @@ @AllArgsConstructor @Builder public class StudentSearchRequest implements Serializable { - List schoolOfRecords; - List districts; - List schoolCategoryCodes; - List pens; - List programs; + private List schoolOfRecords; + private List districts; + private List schoolCategoryCodes; + private List pens; + private List programs; private List studentIDs; + @JsonFormat(pattern = "yyyy-MM-dd") + LocalDate gradDateFrom; + @JsonFormat(pattern = "yyyy-MM-dd") + LocalDate gradDateTo; + Boolean validateInput; + } diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentCertificatesRepository.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentCertificatesRepository.java index 9a4edaeb..178a63a2 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentCertificatesRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentCertificatesRepository.java @@ -31,7 +31,9 @@ public interface GradStudentCertificatesRepository extends JpaRepository findByDocumentStatusCode(@Param("documentStatusCode") String documentStatusCode); - @Query("select new ca.bc.gov.educ.api.grad.report.model.dto.StudentCredentialDistribution(c.id,c.gradCertificateTypeCode,c.studentID,cert.paperType,c.documentStatusCode,c.distributionDate) from GradStudentCertificatesEntity c inner join GradCertificateTypesEntity cert on cert.code = c.gradCertificateTypeCode where c.studentID in (:subList) and c.documentStatusCode='COMPL'") + @Query("select new ca.bc.gov.educ.api.grad.report.model.dto.StudentCredentialDistribution(c.id,c.gradCertificateTypeCode,c.studentID,cert.paperType,c.documentStatusCode,c.distributionDate) from GradStudentCertificatesEntity c inner join GradCertificateTypesEntity cert on cert.code = c.gradCertificateTypeCode where c.studentID in (:subList)") List findRecordsForUserRequest(List subList); + @Query("select new ca.bc.gov.educ.api.grad.report.model.dto.StudentCredentialDistribution(c.id,c.gradCertificateTypeCode,c.studentID,cert.paperType,c.documentStatusCode,c.distributionDate) from GradStudentCertificatesEntity c inner join GradCertificateTypesEntity cert on cert.code = c.gradCertificateTypeCode where c.studentID in (:subList) and c.distributionDate is null") + List findRecordsForUserRequestAndNullDistributionDate(List subList); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java index 948c12a6..7782220f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java @@ -516,7 +516,7 @@ public List getStudentCredentialsForUserRequestDi partitions.add(studentIDs.subList(i, Math.min(i + partitionSize, studentIDs.size()))); } if (credentialType.equalsIgnoreCase("OC") || credentialType.equalsIgnoreCase("RC")) { - processCertificate(partitions, scdList); + processCertificate(partitions, studentSearchRequest, scdList); } else if (credentialType.equalsIgnoreCase("OT") || credentialType.equalsIgnoreCase("RT")) { processTranscript(partitions, studentSearchRequest, scdList); } @@ -524,9 +524,14 @@ public List getStudentCredentialsForUserRequestDi return scdList; } - private void processCertificate(List> partitions, List scdList) { + private void processCertificate(List> partitions, StudentSearchRequest studentSearchRequest, List scdList) { for (List subList : partitions) { - List scdSubList = gradStudentCertificatesRepository.findRecordsForUserRequest(subList); + List scdSubList; + if(studentSearchRequest != null && studentSearchRequest.getPens() != null && !studentSearchRequest.getPens().isEmpty()) { + scdSubList = gradStudentCertificatesRepository.findRecordsForUserRequest(subList); + } else { + scdSubList = gradStudentCertificatesRepository.findRecordsForUserRequestAndNullDistributionDate(subList); + } if (!scdSubList.isEmpty()) { scdList.addAll(scdSubList); } From e6bde5ea78231adf930a4fa1ee673c1c8d2c0fe2 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 29 Apr 2024 13:29:31 -0600 Subject: [PATCH 2/5] GRAD2-2579 (GRAD) Fix User Request Distribution Run options - Part 1 - Date Range --- .../GradStudentCertificatesRepository.java | 6 ++++++ .../api/grad/report/service/CommonService.java | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentCertificatesRepository.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentCertificatesRepository.java index 19cb0da8..b8d96fc1 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentCertificatesRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentCertificatesRepository.java @@ -39,4 +39,10 @@ public interface GradStudentCertificatesRepository extends JpaRepository findRecordsWithNullDistributionDateForUserRequest(List subList); + @Query("select new ca.bc.gov.educ.api.grad.report.model.dto.StudentCredentialDistribution(c.id,c.gradCertificateTypeCode,c.studentID,cert.paperType,c.documentStatusCode,c.distributionDate) from GradStudentCertificatesEntity c inner join GradCertificateTypesEntity cert on cert.code = c.gradCertificateTypeCode where c.studentID in (:subList) and c.distributionDate is null") + List findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(List subList); + + @Query("select new ca.bc.gov.educ.api.grad.report.model.dto.StudentCredentialDistribution(c.id,c.gradCertificateTypeCode,c.studentID,cert.paperType,c.documentStatusCode,c.distributionDate) from GradStudentCertificatesEntity c inner join GradCertificateTypesEntity cert on cert.code = c.gradCertificateTypeCode where c.studentID in (:subList)") + List findRecordsForUserRequestByStudentIdOnly(List subList); + } diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java index 270c9f3a..a356fe6f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java @@ -528,9 +528,16 @@ public List getStudentCredentialsForUserRequestDi private void processCertificate(List> partitions, StudentSearchRequest studentSearchRequest, List scdList, boolean onlyWithNullDistributionDate) { for (List subList : partitions) { - List scdSubList = onlyWithNullDistributionDate? - gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequest(subList) : - gradStudentCertificatesRepository.findRecordsForUserRequest(subList); + List scdSubList; + if (studentSearchRequest != null && studentSearchRequest.getPens() != null && !studentSearchRequest.getPens().isEmpty()) { + scdSubList = onlyWithNullDistributionDate? + gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(subList) : + gradStudentCertificatesRepository.findRecordsForUserRequestByStudentIdOnly(subList); + } else { + scdSubList = onlyWithNullDistributionDate? + gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequest(subList) + : gradStudentTranscriptsRepository.findRecordsForUserRequest(subList); + } if (!scdSubList.isEmpty()) { scdList.addAll(scdSubList); } @@ -540,7 +547,7 @@ private void processCertificate(List> partitions, StudentSearchReques private void processTranscript(List> partitions, StudentSearchRequest studentSearchRequest, List scdList, boolean onlyWithNullDistributionDate) { for (List subList : partitions) { List scdSubList; - if (!studentSearchRequest.getPens().isEmpty()) { + if (studentSearchRequest != null && studentSearchRequest.getPens() != null && !studentSearchRequest.getPens().isEmpty()) { scdSubList = onlyWithNullDistributionDate? gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(subList) : gradStudentTranscriptsRepository.findRecordsForUserRequestByStudentIdOnly(subList); From 7283bf0e76e83047c6d83bc48d0301cc740015e5 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 29 Apr 2024 13:34:02 -0600 Subject: [PATCH 3/5] GRAD2-2579 (GRAD) Fix User Request Distribution Run options - Part 1 - Date Range --- .../educ/api/grad/report/model/dto/StudentSearchRequest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/StudentSearchRequest.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/StudentSearchRequest.java index 6cade99c..5c87f3aa 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/StudentSearchRequest.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/StudentSearchRequest.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.grad.report.model.dto; +import ca.bc.gov.educ.api.grad.report.util.EducGradReportApiConstants; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Builder; @@ -25,9 +26,9 @@ public class StudentSearchRequest implements Serializable { private List programs; private List studentIDs; - @JsonFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern= EducGradReportApiConstants.DEFAULT_DATE_FORMAT) LocalDate gradDateFrom; - @JsonFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern= EducGradReportApiConstants.DEFAULT_DATE_FORMAT) LocalDate gradDateTo; Boolean validateInput; From 8228e3754b765511a3183f1f54aa29a6fcd6539b Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 1 May 2024 09:23:23 -0600 Subject: [PATCH 4/5] GRAD2-2579 Fix testing errors --- .../api/grad/report/service/CommonServiceTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java index 467aedd1..80e6f806 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java @@ -902,7 +902,11 @@ public void testGetStudentCredentialsForUserRequestDisRun_OC() { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); - Mockito.when(gradStudentCertificatesRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentCertificatesRepository.findRecordsForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); + + Mockito.when(gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList); List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,new StudentSearchRequest(),false,null); assertThat(result).isNotEmpty(); @@ -937,6 +941,10 @@ public void testGetStudentCredentialsForUserRequestDisRun_OC_with_Null_Distribut when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); Mockito.when(gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentCertificatesRepository.findRecordsForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); + + Mockito.when(gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList); List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,new StudentSearchRequest(),true,null); assertThat(result).isNotEmpty(); From 395ffc35f5bf6e9d27957ba59648c3c4ceabf6c2 Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 1 May 2024 09:42:08 -0600 Subject: [PATCH 5/5] GRAD2-2579 Fix testing errors --- .../report/service/CommonServiceTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java index 80e6f806..11e1eeb6 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java @@ -903,9 +903,13 @@ public void testGetStudentCredentialsForUserRequestDisRun_OC() { when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); Mockito.when(gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); Mockito.when(gradStudentCertificatesRepository.findRecordsForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentCertificatesRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList); Mockito.when(gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList); List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,new StudentSearchRequest(),false,null); @@ -913,6 +917,54 @@ public void testGetStudentCredentialsForUserRequestDisRun_OC() { } + @Test + public void testGetStudentCredentialsForUserRequestDisRun_OC_SearchRequest() { + + GraduationStudentRecordSearchResult res = new GraduationStudentRecordSearchResult(); + + List studList= new ArrayList<>(); + GraduationStudentRecord rec = new GraduationStudentRecord(); + rec.setLegalFirstName("asda"); + rec.setStudentID(new UUID(1,1)); + studList.add(rec.getStudentID()); + res.setStudentIDs(studList); + + List scdSubList = new ArrayList<>(); + StudentCredentialDistribution scdSub = new StudentCredentialDistribution(new UUID(4,4),"E",new UUID(5,5),"YED4","COMPL", new Date()); + scdSubList.add(scdSub); + + List studentList = new ArrayList<>(); + studentList.add(new UUID(1,1)); + + when(this.webClient.post()).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(constants.getGradStudentApiStudentForSpcGradListUrl())).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); + + StudentSearchRequest searchRequest = new StudentSearchRequest(); + searchRequest.setPens(new ArrayList<>()); + searchRequest.getPens().add("12345678"); + + Mockito.when(gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentCertificatesRepository.findRecordsForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentCertificatesRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList); + + Mockito.when(gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); + Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList); + + List result = commonService.getStudentCredentialsForUserRequestDisRun("OC",searchRequest,true,"accessToken"); + assertThat(result).isNotEmpty(); + + result = commonService.getStudentCredentialsForUserRequestDisRun("OT",searchRequest,false,"accessToken"); + assertThat(result).isNotEmpty(); + + } + @Test public void testGetStudentCredentialsForUserRequestDisRun_OC_with_Null_DistributionDate() {