Skip to content

Commit

Permalink
Merge pull request #259 from bcgov/grad-release
Browse files Browse the repository at this point in the history
Grad release 1.18.0
  • Loading branch information
githubmamatha authored Apr 24, 2024
2 parents f89cb2f + fa717f9 commit ce8d4aa
Show file tree
Hide file tree
Showing 10 changed files with 446 additions and 28 deletions.
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.45</version>
<version>1.8.46</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 @@ -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 @@ -19,6 +19,7 @@
import org.springframework.web.bind.annotation.*;

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

@CrossOrigin
Expand Down Expand Up @@ -271,13 +272,26 @@ 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("getStudentCredentialsForUserRequestDisRunWithNullDistributionDate : ");
boolean isPenNumberSearch = studentSearchRequest.getPens()!= null && !studentSearchRequest.getPens().isEmpty()
&& !studentSearchRequest.getPens().stream().filter(StringUtils::isNotBlank).toList().isEmpty();
return response.GET(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,studentSearchRequest,!isPenNumberSearch,accessToken.replace(BEARER, "")));
}

@DeleteMapping(EducGradReportApiConstants.ARCH_ACHIEVEMENTS_BY_STUDENTID)
Expand All @@ -303,9 +317,9 @@ public ResponseEntity<ApiResponseModel<SchoolReports>> saveSchoolReport(@Request
@PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_REPORTS)
@Operation(summary = "Read All School Reports by Mincode", description = "Read All School Reports by Mincode", tags = { "Reports" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<List<SchoolReports>> getAllSchoolReportsList(@PathVariable String mincode,@RequestHeader(name="Authorization") String accessToken) {
public ResponseEntity<List<SchoolReports>> getAllSchoolReportsList(@PathVariable String mincode) {
logger.debug("getAllSchoolReportsList : ");
return response.GET(commonService.getAllSchoolReportListByMincode(mincode, accessToken.replace(BEARER,"")));
return response.GET(commonService.getAllSchoolReportListByMincode(mincode));
}

@GetMapping(EducGradReportApiConstants.SCHOOL_REPORTS_BY_REPORT_TYPE)
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 @@ -6,6 +6,7 @@
import ca.bc.gov.educ.api.grad.report.model.transformer.*;
import ca.bc.gov.educ.api.grad.report.repository.*;
import ca.bc.gov.educ.api.grad.report.util.EducGradReportApiConstants;
import ca.bc.gov.educ.api.grad.report.util.Generated;
import ca.bc.gov.educ.api.grad.report.util.ThreadLocalStateUtil;
import jakarta.transaction.Transactional;
import org.apache.commons.codec.binary.Base64;
Expand Down Expand Up @@ -332,7 +333,7 @@ public List<GradStudentReports> getAllStudentReportList(UUID studentID) {
return reportList;
}

public List<SchoolReports> getAllSchoolReportListByMincode(String mincode, String accessToken) {
public List<SchoolReports> getAllSchoolReportListByMincode(String mincode) {
List<SchoolReports> reportList = new ArrayList<>();
if (StringUtils.isNotBlank(mincode)) {
if (StringUtils.contains(mincode, "*")) {
Expand All @@ -357,6 +358,7 @@ public List<SchoolReports> getAllSchoolReportListByReportType(String reportType,
return reportList;
}

@Generated
private void populateSchoolRepors(List<SchoolReports> reportList) {
reportList.forEach(rep -> {
String accessToken = fetchAccessToken();
Expand Down Expand Up @@ -503,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 @@ -516,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 Expand Up @@ -606,6 +614,7 @@ public boolean deleteSchoolReports(String minCode, String reportTypeCode) {
return false;
}

@Generated
private School getSchool(String minCode, String accessToken) {
try {
return webClient.get()
Expand All @@ -623,6 +632,7 @@ private School getSchool(String minCode, String accessToken) {
}
}

@Generated
private District getDistrict(String districtCode, String accessToken) {
try {
return webClient.get()
Expand Down Expand Up @@ -696,6 +706,7 @@ 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 All @@ -719,18 +730,21 @@ private List<ReportGradStudentData> processReportGradStudentDataList(Page<School
return result;
}

@Generated
private synchronized List<ReportGradStudentData> getNextPageStudentsFromGradStudentApi(Page<SchoolReportEntity> students, List<String> schools) {
List<ReportGradStudentData> result = new ArrayList<>();
List<UUID> studentGuidsInBatch = students.getContent().stream().map(SchoolReportEntity::getGraduationStudentRecordId).distinct().toList();
List<ReportGradStudentData> studentsInBatch = getReportGradStudentData(fetchAccessToken(), studentGuidsInBatch);
if(studentsInBatch != null && !schools.isEmpty()) {
boolean isDistrictSchool = schools.get(0).length() == 3;
if(isDistrictSchool) {
studentsInBatch.removeIf(st -> (!schools.contains(StringUtils.substring(st.getMincode(), 0, 3))));
studentsInBatch.removeIf(st -> (schools != null && !schools.isEmpty() && (StringUtils.isBlank(st.getMincodeAtGrad()) || StringUtils.equals(st.getMincode(), st.getMincodeAtGrad())) && !schools.contains(StringUtils.substring(st.getMincode(), 0, 3))));
studentsInBatch.removeIf(st -> (schools != null && !schools.isEmpty() && (StringUtils.isNotBlank(st.getMincodeAtGrad()) && !StringUtils.equals(st.getMincode(), st.getMincodeAtGrad())) && !schools.contains(StringUtils.substring(st.getMincodeAtGrad(), 0, 3))));
}
boolean isSchoolSchool = schools.get(0).length() > 3;
if(isSchoolSchool) {
studentsInBatch.removeIf(st -> (!schools.contains(StringUtils.trimToEmpty(st.getMincode()))));
studentsInBatch.removeIf(st -> (schools != null && !schools.isEmpty() && (StringUtils.isBlank(st.getMincodeAtGrad()) || StringUtils.equals(st.getMincode(), st.getMincodeAtGrad())) && !schools.contains(StringUtils.trimToEmpty(st.getMincode()))));
studentsInBatch.removeIf(st -> (schools != null && !schools.isEmpty() && (StringUtils.isNotBlank(st.getMincodeAtGrad()) && !StringUtils.equals(st.getMincode(), st.getMincodeAtGrad())) && !schools.contains(StringUtils.trimToEmpty(st.getMincodeAtGrad()))));
}
}
for(SchoolReportEntity e: students.getContent()) {
Expand All @@ -745,12 +759,18 @@ private synchronized List<ReportGradStudentData> getNextPageStudentsFromGradStud
} else {
dataResult.setCertificateTypeCode(certificateTypeCode);
}
result.add(dataResult);
if("YED4".equalsIgnoreCase(paperType) && "CUR".equalsIgnoreCase(s.getStudentStatus())) {
result.add(dataResult);
}
if (!"YED4".equalsIgnoreCase(paperType)) {
result.add(dataResult);
}
}
}
return result;
}

@Generated
private synchronized ReportGradStudentData getReportGradStudentDataByGraduationStudentRecordIdFromList(UUID id, List<ReportGradStudentData> studentsInBatch) {
for(ReportGradStudentData s: studentsInBatch) {
if(s.getGraduationStudentRecordId().equals(id)) {
Expand All @@ -760,6 +780,7 @@ private synchronized ReportGradStudentData getReportGradStudentDataByGraduationS
return null;
}

@Generated
private synchronized List<ReportGradStudentData> getReportGradStudentData(String accessToken, List<UUID> studentGuids) {
final ParameterizedTypeReference<List<ReportGradStudentData>> responseType = new ParameterizedTypeReference<>() {
};
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
@@ -0,0 +1,14 @@
package ca.bc.gov.educ.api.grad.report.util;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Documented
@Retention(RUNTIME)
@Target({TYPE, METHOD, CONSTRUCTOR})
public @interface Generated {
}
Loading

0 comments on commit ce8d4aa

Please sign in to comment.