Skip to content

Commit

Permalink
Merge pull request #256 from bcgov/feature/GRAD2-2570
Browse files Browse the repository at this point in the history
GRAD2-2570: user request distribution run supports for null distribut…
  • Loading branch information
arybakov-cgi authored Apr 22, 2024
2 parents ae6344e + af68b0d commit 2f40613
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public WebClient webClient() {
return WebClient.builder().uriBuilderFactory(defaultUriBuilderFactory).exchangeStrategies(ExchangeStrategies.builder()
.codecs(configurer -> configurer
.defaultCodecs()
.maxInMemorySize(300 * 1024 * 1024)) // 100 MB
.maxInMemorySize(300 * 1024 * 1024)) // 300 MB
.build())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,24 @@ public ResponseEntity<Boolean> updateStudentCredentialPosting(@RequestParam Stri

@PostMapping(EducGradReportApiConstants.USER_REQUEST_DIS_RUN)
@PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_CERTIFICATES)
@Operation(summary = "Read All Student Transcripts/Certificates for User Req Distribution", description = "Read All Student Transcripts for Distribution", tags = { "Certificates" })
@Operation(summary = "Read All Student Transcripts/Certificates for User Req Distribution", description = "Read All Student Credentials for Distribution", tags = { "Certificates" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<List<StudentCredentialDistribution>> getStudentCredentialsForUserRequestDisRun(
@PathVariable String credentialType, @RequestBody StudentSearchRequest studentSearchRequest,
@RequestHeader(name="Authorization") String accessToken) {
logger.debug("getStudentCredentialsForUserRequestDisRun : ");
return response.GET(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,studentSearchRequest,accessToken.replace(BEARER, "")));
return response.GET(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,studentSearchRequest,false,accessToken.replace(BEARER, "")));
}

@PostMapping(EducGradReportApiConstants.USER_REQUEST_DIS_RUN_WITH_NULL_DISTRIBUTION_DATE)
@PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_CERTIFICATES)
@Operation(summary = "Read All Student Transcripts/Certificates with Null Distribution Date for User Req Distribution", description = "Read All Student Credentials with Null Distribution Date for Distribution", tags = { "Certificates" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<List<StudentCredentialDistribution>> getStudentCredentialsForUserRequestDisRunWithNullDistributionDate(
@PathVariable String credentialType, @RequestBody StudentSearchRequest studentSearchRequest,
@RequestHeader(name="Authorization") String accessToken) {
logger.debug("getStudentCredentialsForRegenCertRun : ");
return response.GET(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,studentSearchRequest,true,accessToken.replace(BEARER, "")));
}

@DeleteMapping(EducGradReportApiConstants.ARCH_ACHIEVEMENTS_BY_STUDENTID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ 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.studentID in (:subList) and c.documentStatusCode='COMPL'")
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> findRecordsWithNullDistributionDateForUserRequest(List<UUID> subList);

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public interface GradStudentTranscriptsRepository extends JpaRepository<GradStud
@Query("select new ca.bc.gov.educ.api.grad.report.model.dto.StudentCredentialDistribution(c.id,c.transcriptTypeCode,c.studentID,tran.paperType,c.documentStatusCode,c.distributionDate) from GradStudentTranscriptsEntity c inner join TranscriptTypesEntity tran on tran.code = c.transcriptTypeCode where c.studentID in (:subList)")
List<StudentCredentialDistribution> findRecordsForUserRequestByStudentIdOnly(List<UUID> subList);

@Query("select new ca.bc.gov.educ.api.grad.report.model.dto.StudentCredentialDistribution(c.id,c.transcriptTypeCode,c.studentID,tran.paperType,c.documentStatusCode,c.distributionDate) from GradStudentTranscriptsEntity c inner join TranscriptTypesEntity tran on tran.code = c.transcriptTypeCode where c.studentID in (:subList) and c.documentStatusCode='COMPL' 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.transcriptTypeCode,c.studentID,tran.paperType,c.documentStatusCode,c.distributionDate) from GradStudentTranscriptsEntity c inner join TranscriptTypesEntity tran on tran.code = c.transcriptTypeCode 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.SchoolStudentCredentialDistribution(c.id,c.transcriptTypeCode,c.studentID,c.documentStatusCode) from GradStudentTranscriptsEntity c where c.transcriptUpdateDate is null or c.transcriptUpdateDate < c.updateDate")
List<SchoolStudentCredentialDistribution> findByTranscriptUpdateDate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public boolean updateStudentCredentialPosting(UUID studentID, String credentialT
return false;
}

public List<StudentCredentialDistribution> getStudentCredentialsForUserRequestDisRun(String credentialType, StudentSearchRequest studentSearchRequest, String accessToken) {
public List<StudentCredentialDistribution> getStudentCredentialsForUserRequestDisRun(String credentialType, StudentSearchRequest studentSearchRequest, boolean onlyWithNullDistributionDate, String accessToken) {
List<StudentCredentialDistribution> scdList = new ArrayList<>();
List<UUID> studentIDs = studentSearchRequest.getStudentIDs();
if(studentIDs == null || studentIDs.isEmpty()) {
Expand All @@ -518,30 +518,36 @@ 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);
processCertificate(partitions, scdList, onlyWithNullDistributionDate);
} else if (credentialType.equalsIgnoreCase("OT") || credentialType.equalsIgnoreCase("RT")) {
processTranscript(partitions, studentSearchRequest, scdList);
processTranscript(partitions, studentSearchRequest, scdList, onlyWithNullDistributionDate);
}
}
return scdList;
}

private void processCertificate(List<List<UUID>> partitions, List<StudentCredentialDistribution> scdList) {
private void processCertificate(List<List<UUID>> partitions, List<StudentCredentialDistribution> scdList, boolean onlyWithNullDistributionDate) {
for (List<UUID> subList : partitions) {
List<StudentCredentialDistribution> scdSubList = gradStudentCertificatesRepository.findRecordsForUserRequest(subList);
List<StudentCredentialDistribution> scdSubList = onlyWithNullDistributionDate?
gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequest(subList) :
gradStudentCertificatesRepository.findRecordsForUserRequest(subList);
if (!scdSubList.isEmpty()) {
scdList.addAll(scdSubList);
}
}
}

private void processTranscript(List<List<UUID>> partitions, StudentSearchRequest studentSearchRequest, List<StudentCredentialDistribution> scdList) {
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()) {
scdSubList = gradStudentTranscriptsRepository.findRecordsForUserRequestByStudentIdOnly(subList);
scdSubList = onlyWithNullDistributionDate?
gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(subList)
: gradStudentTranscriptsRepository.findRecordsForUserRequestByStudentIdOnly(subList);
} else {
scdSubList = gradStudentTranscriptsRepository.findRecordsForUserRequest(subList);
scdSubList = onlyWithNullDistributionDate?
gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequest(subList)
: gradStudentTranscriptsRepository.findRecordsForUserRequest(subList);
}
if (!scdSubList.isEmpty()) {
scdList.addAll(scdSubList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private EducGradReportApiConstants(){}

public static final String STUDENT_TRANSCRIPT_BY_DIST_DATE_N_STATUS_YEARLY = "/gettranscriptsfordistributionyearly";
public static final String USER_REQUEST_DIS_RUN = "/userrequest/{credentialType}";
public static final String USER_REQUEST_DIS_RUN_WITH_NULL_DISTRIBUTION_DATE = "/userrequest/notyetdistributed/{credentialType}";

public static final String GET_STUDENT_CERTIFICATE_BY_CERTIFICATE_CODE_MAPPING = "/certificate/{certificateTypeCode}";
public static final String GET_STUDENT_REPORT_BY_REPORT_CODE_MAPPING = "/report/{reportTypeCode}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,30 @@ public void testGetAllStudentCredentialDistributionList() {
final StudentCredentialDistribution cred = new StudentCredentialDistribution(UUID.randomUUID(),"BC2018-IND",studentID,"YED4","COMPL", new Date());
list.add(cred);

Mockito.when(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,"accessToken")).thenReturn(list);
Mockito.when(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,false,"accessToken")).thenReturn(list);
commonController.getStudentCredentialsForUserRequestDisRun(credentialType,req,"accessToken");
Mockito.verify(commonService).getStudentCredentialsForUserRequestDisRun(credentialType,req,"accessToken");
Mockito.verify(commonService).getStudentCredentialsForUserRequestDisRun(credentialType,req,false,"accessToken");
}

@Test
public void testGetAllStudentCredentialDistributionListWithNullDistributionDate() {
// UUID
final UUID studentID = UUID.randomUUID();
final String credentialType = "E";
final StudentSearchRequest req = new StudentSearchRequest();
req.setPens(List.of("2131231213"));

// Student Certificate Types
final List<StudentCredentialDistribution> list = new ArrayList<>();
final StudentCredentialDistribution cred = new StudentCredentialDistribution(UUID.randomUUID(),"BC2018-IND",studentID,"YED4","COMPL", new Date());
list.add(cred);

Mockito.when(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,true,"accessToken")).thenReturn(list);
commonController.getStudentCredentialsForUserRequestDisRunWithNullDistributionDate(credentialType,req,"accessToken");
Mockito.verify(commonService).getStudentCredentialsForUserRequestDisRun(credentialType,req,true,"accessToken");
}


@Test
public void testGetAllStudentTranscriptDistributionYearlyList() {
// Student Certificate Types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,41 @@ public void testGetStudentCredentialsForUserRequestDisRun_OC() {

Mockito.when(gradStudentCertificatesRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList);

List<StudentCredentialDistribution> result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,new StudentSearchRequest(),null);
List<StudentCredentialDistribution> result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,new StudentSearchRequest(),false,null);
assertThat(result).isNotEmpty();

}

@Test
public void testGetStudentCredentialsForUserRequestDisRun_OC_with_Null_DistributionDate() {

String credentialType = "OC";
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));

Mockito.when(gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList);

List<StudentCredentialDistribution> result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,new StudentSearchRequest(),true,null);
assertThat(result).isNotEmpty();

}
Expand Down Expand Up @@ -973,7 +1007,46 @@ public void testGetStudentCredentialsForUserRequestDisRun_OT() {

Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList);

List<StudentCredentialDistribution> result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,null);
List<StudentCredentialDistribution> result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,false,null);
assertThat(result.size()).isEqualTo(1);

}

@Test
public void testGetStudentCredentialsWithNullDistributionDateForUserRequestDisRun_OT() {

String credentialType = "OT";
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));

StudentSearchRequest req = new StudentSearchRequest();
List<String> penList = new ArrayList<>();
penList.add("13123111");
req.setPens(penList);

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));

Mockito.when(gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList);

List<StudentCredentialDistribution> result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,true,null);
assertThat(result.size()).isEqualTo(1);

}
Expand Down Expand Up @@ -1013,7 +1086,47 @@ public void testGetStudentCredentialsForUserRequestDisRun_OT_Prgm() {

Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList);

List<StudentCredentialDistribution> result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,null);
List<StudentCredentialDistribution> result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,false,null);
assertThat(result.size()).isEqualTo(1);

}

@Test
public void testGetStudentCredentialsWithNullDistributionDateForUserRequestDisRun_OT_Prgm() {

String credentialType = "OT";
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));

StudentSearchRequest req = new StudentSearchRequest();
List<String> pgList = new ArrayList<>();
pgList.add("2018-EN");
req.setPrograms(pgList);
req.setPens(new ArrayList<>());

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));

Mockito.when(gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList);

List<StudentCredentialDistribution> result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,true,null);
assertThat(result.size()).isEqualTo(1);

}
Expand Down

0 comments on commit 2f40613

Please sign in to comment.