Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grad release 1.19.0 #265

Merged
merged 19 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.bc.gov.educ</groupId>
<artifactId>educ-grad-graduation-report-api</artifactId>
<version>1.8.46</version>
<version>1.8.47</version>
<name>educ-grad-graduation-report-api</name>
<description>Grad Graduation Report API for GRAD team</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;
import java.util.UUID;

@CrossOrigin
Expand Down Expand Up @@ -278,7 +277,10 @@ public ResponseEntity<List<StudentCredentialDistribution>> getStudentCredentials
@PathVariable String credentialType, @RequestBody StudentSearchRequest studentSearchRequest,
@RequestHeader(name="Authorization") String accessToken) {
logger.debug("getStudentCredentialsForUserRequestDisRun : ");
return response.GET(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,studentSearchRequest,false,accessToken.replace(BEARER, "")));
boolean isPenNumberSearch = studentSearchRequest.getPens() != null && !studentSearchRequest.getPens().isEmpty()
&& !studentSearchRequest.getPens().stream().filter(StringUtils::isNotBlank).toList().isEmpty();
boolean onlyWithNullDistributionDate = !isPenNumberSearch && studentSearchRequest.getGradDateFrom() == null && studentSearchRequest.getGradDateTo() == null && !StringUtils.equalsAnyIgnoreCase(credentialType, "OT", "RT");
return response.GET(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,studentSearchRequest,onlyWithNullDistributionDate,accessToken.replace(BEARER, "")));
}

@PostMapping(EducGradReportApiConstants.USER_REQUEST_DIS_RUN_WITH_NULL_DISTRIBUTION_DATE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;

Expand All @@ -16,12 +19,19 @@
@AllArgsConstructor
@Builder
public class StudentSearchRequest implements Serializable {
List<String> schoolOfRecords;
List<String> districts;
List<String> schoolCategoryCodes;
List<String> pens;
List<String> programs;
private List<String> schoolOfRecords;
private List<String> districts;
private List<String> schoolCategoryCodes;
private List<String> pens;
private List<String> programs;
private List<UUID> studentIDs;

@JsonFormat(pattern= EducGradReportApiConstants.DEFAULT_DATE_FORMAT)
LocalDate gradDateFrom;
@JsonFormat(pattern= EducGradReportApiConstants.DEFAULT_DATE_FORMAT)
LocalDate gradDateTo;

Boolean validateInput;
String activityCode;

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ public interface GradStudentCertificatesRepository extends JpaRepository<GradStu
@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.documentStatusCode=:documentStatusCode")
List<StudentCredentialDistribution> 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<StudentCredentialDistribution> findRecordsForUserRequest(List<UUID> 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<StudentCredentialDistribution> findRecordsForUserRequestAndNullDistributionDate(List<UUID> 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<StudentCredentialDistribution> findRecordsWithNullDistributionDateForUserRequest(List<UUID> 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<StudentCredentialDistribution> findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(List<UUID> 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<StudentCredentialDistribution> findRecordsForUserRequestByStudentIdOnly(List<UUID> subList);

}
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ public boolean updateStudentCredentialPosting(UUID studentID, String credentialT

public List<StudentCredentialDistribution> getStudentCredentialsForUserRequestDisRun(String credentialType, StudentSearchRequest studentSearchRequest, boolean onlyWithNullDistributionDate, String accessToken) {
List<StudentCredentialDistribution> scdList = new ArrayList<>();
if(StringUtils.isBlank(studentSearchRequest.getActivityCode())) {
studentSearchRequest.setActivityCode("USERDIST" + StringUtils.upperCase(credentialType));
}
List<UUID> studentIDs = studentSearchRequest.getStudentIDs();
if(studentIDs == null || studentIDs.isEmpty()) {
studentIDs = getStudentsForSpecialGradRun(studentSearchRequest, accessToken);
Expand All @@ -518,19 +521,26 @@ public List<StudentCredentialDistribution> 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);
}
}
return scdList;
}

private void processCertificate(List<List<UUID>> partitions, List<StudentCredentialDistribution> scdList, boolean onlyWithNullDistributionDate) {
private void processCertificate(List<List<UUID>> partitions, StudentSearchRequest studentSearchRequest, List<StudentCredentialDistribution> scdList, boolean onlyWithNullDistributionDate) {
for (List<UUID> subList : partitions) {
List<StudentCredentialDistribution> scdSubList = onlyWithNullDistributionDate?
gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequest(subList) :
gradStudentCertificatesRepository.findRecordsForUserRequest(subList);
List<StudentCredentialDistribution> scdSubList;
if (studentSearchRequest != null && studentSearchRequest.getPens() != null && !studentSearchRequest.getPens().isEmpty()) {
scdSubList = onlyWithNullDistributionDate?
gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(subList) :
gradStudentCertificatesRepository.findRecordsForUserRequestByStudentIdOnly(subList);
} else {
scdSubList = onlyWithNullDistributionDate?
gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequest(subList)
: gradStudentCertificatesRepository.findRecordsForUserRequest(subList);
}
if (!scdSubList.isEmpty()) {
scdList.addAll(scdSubList);
}
Expand All @@ -540,7 +550,7 @@ private void processCertificate(List<List<UUID>> partitions, List<StudentCredent
private void processTranscript(List<List<UUID>> partitions, StudentSearchRequest studentSearchRequest, List<StudentCredentialDistribution> scdList, boolean onlyWithNullDistributionDate) {
for (List<UUID> subList : partitions) {
List<StudentCredentialDistribution> scdSubList;
if (!studentSearchRequest.getPens().isEmpty()) {
if (studentSearchRequest != null && studentSearchRequest.getPens() != null && !studentSearchRequest.getPens().isEmpty()) {
scdSubList = onlyWithNullDistributionDate?
gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(subList)
: gradStudentTranscriptsRepository.findRecordsForUserRequestByStudentIdOnly(subList);
Expand Down Expand Up @@ -706,7 +716,6 @@ public List<ReportGradStudentData> getSchoolReportGradStudentData() {
return processReportGradStudentDataList(students, new ArrayList<>());
}

@Generated
private List<ReportGradStudentData> processReportGradStudentDataList(Page<SchoolReportEntity> students, List<String> schools) {
List<ReportGradStudentData> result = new ArrayList<>();
long startTime = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,13 +902,71 @@ 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<StudentCredentialDistribution> result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,new StudentSearchRequest(),false,null);
assertThat(result).isNotEmpty();

}

@Test
public void testGetStudentCredentialsForUserRequestDisRun_OC_SearchRequest() {

GraduationStudentRecordSearchResult res = new GraduationStudentRecordSearchResult();

List<UUID> studList= new ArrayList<>();
GraduationStudentRecord rec = new GraduationStudentRecord();
rec.setLegalFirstName("asda");
rec.setStudentID(new UUID(1,1));
studList.add(rec.getStudentID());
res.setStudentIDs(studList);

List<StudentCredentialDistribution> scdSubList = new ArrayList<>();
StudentCredentialDistribution scdSub = new StudentCredentialDistribution(new UUID(4,4),"E",new UUID(5,5),"YED4","COMPL", new Date());
scdSubList.add(scdSub);

List<UUID> 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<StudentCredentialDistribution> result = commonService.getStudentCredentialsForUserRequestDisRun("OC",searchRequest,true,"accessToken");
assertThat(result).isNotEmpty();

searchRequest.setActivityCode("USERDIST");

result = commonService.getStudentCredentialsForUserRequestDisRun("OT",searchRequest,false,"accessToken");
assertThat(result).isNotEmpty();

}

@Test
public void testGetStudentCredentialsForUserRequestDisRun_OC_with_Null_DistributionDate() {

Expand Down Expand Up @@ -937,6 +995,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<StudentCredentialDistribution> result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,new StudentSearchRequest(),true,null);
assertThat(result).isNotEmpty();
Expand Down
Loading