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..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,7 @@ 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; import lombok.Data; @@ -7,6 +9,7 @@ import org.springframework.stereotype.Component; import java.io.Serializable; +import java.time.LocalDate; import java.util.List; import java.util.UUID; @@ -16,12 +19,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= EducGradReportApiConstants.DEFAULT_DATE_FORMAT) + LocalDate gradDateFrom; + @JsonFormat(pattern= EducGradReportApiConstants.DEFAULT_DATE_FORMAT) + 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 84faae7a..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 @@ -31,10 +31,18 @@ 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); @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 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 fc40181b..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 @@ -518,7 +518,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, onlyWithNullDistributionDate); + processCertificate(partitions, studentSearchRequest, scdList, onlyWithNullDistributionDate); } else if (credentialType.equalsIgnoreCase("OT") || credentialType.equalsIgnoreCase("RT")) { processTranscript(partitions, studentSearchRequest, scdList, onlyWithNullDistributionDate); } @@ -526,11 +526,18 @@ public List getStudentCredentialsForUserRequestDi return scdList; } - private void processCertificate(List> partitions, List scdList, boolean onlyWithNullDistributionDate) { + 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, 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); @@ -706,7 +713,6 @@ public List getSchoolReportGradStudentData() { return processReportGradStudentDataList(students, new ArrayList<>()); } - @Generated private List processReportGradStudentDataList(Page students, List schools) { List result = new ArrayList<>(); long startTime = System.currentTimeMillis(); 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..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 @@ -902,13 +902,69 @@ public void testGetStudentCredentialsForUserRequestDisRun_OC() { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); 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); assertThat(result).isNotEmpty(); } + @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() { @@ -937,6 +993,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();