Skip to content

Commit

Permalink
Merge pull request #232 from bcgov/develop/alex
Browse files Browse the repository at this point in the history
Fix missing certificates
  • Loading branch information
infstar authored Jul 25, 2023
2 parents 1392bd6 + ad5204f commit 18df823
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
public class BaseModel {
public class BaseModel implements Serializable {
private String createUser;
private Date createDate;
private String updateUser;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ca.bc.gov.educ.api.grad.report.model.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Id;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.MappedSuperclass;
import lombok.Data;

Expand All @@ -11,14 +10,35 @@
@MappedSuperclass
public class SchoolReportEntity {

@Id
@Column(name = "GRADUATION_STUDENT_RECORD_ID", nullable = false)
protected UUID graduationStudentRecordId;
@EmbeddedId
protected SchoolReportEntityId schoolReportEntityId;

@Column(name = "PAPER_TYPE")
private String paperType;
public UUID getGraduationStudentRecordId() {
return schoolReportEntityId.graduationStudentRecordId;
}

@Column(name = "CERTIFICATE_TYPE_CODE")
private String certificateTypeCode;
public void setGraduationStudentRecordId(UUID graduationStudentRecordId) {
this.schoolReportEntityId.graduationStudentRecordId = graduationStudentRecordId;
}

public String getPaperType() {
return schoolReportEntityId.paperType;
}

public void setPaperType(String paperType) {
this.schoolReportEntityId.paperType = paperType;
}

public String getCertificateTypeCode() {
return schoolReportEntityId.certificateTypeCode;
}

public void setCertificateTypeCode(String certificateTypeCode) {
this.schoolReportEntityId.certificateTypeCode = certificateTypeCode;
}

@Override
public String toString() {
return "SchoolReportEntity {" + schoolReportEntityId + "}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ca.bc.gov.educ.api.grad.report.model.entity;

import jakarta.persistence.Column;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Objects;
import java.util.UUID;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class SchoolReportEntityId implements Serializable {

@Column(name = "GRADUATION_STUDENT_RECORD_ID", nullable = false)
protected UUID graduationStudentRecordId;
@Column(name = "PAPER_TYPE")
protected String paperType;
@Column(name = "CERTIFICATE_TYPE_CODE")
protected String certificateTypeCode;

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SchoolReportEntityId that = (SchoolReportEntityId) o;
return Objects.equals(graduationStudentRecordId, that.graduationStudentRecordId) && Objects.equals(paperType, that.paperType) && Objects.equals(certificateTypeCode, that.certificateTypeCode);
}

@Override
public int hashCode() {
return Objects.hash(graduationStudentRecordId, paperType, certificateTypeCode);
}

@Override
public String toString() {
return "SchoolReportEntityId {" +
"graduationStudentRecordId=" + graduationStudentRecordId +
", paperType='" + paperType + '\'' +
", certificateTypeCode='" + certificateTypeCode + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected UUID convertStringToGuid(String studentGuid) {
return new UUID(ByteBuffer.wrap(data, 0, 8).getLong(), ByteBuffer.wrap(data, 8, 8).getLong());
}

protected void processReportGradStudentDataTasksAsync(List<Callable<Object>> tasks, List<ReportGradStudentData> result, int numberOfThreads) throws ExecutionException, InterruptedException {
protected void processReportGradStudentDataTasksAsync(List<Callable<Object>> tasks, List<ReportGradStudentData> result, int numberOfThreads) {
List<Future<Object>> executionResult;
ExecutorService executorService = Executors.newFixedThreadPool(numberOfThreads);
try {
Expand All @@ -72,7 +72,7 @@ protected void processReportGradStudentDataTasksAsync(List<Callable<Object>> tas
}
}
} catch (InterruptedException | ExecutionException ex) {
throw new InterruptedException(ex.toString());
logger.error("Multithreading error during the task execution: {}", ex.getLocalizedMessage());
} finally {
executorService.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import ca.bc.gov.educ.api.grad.report.util.EducGradReportApiConstants;
import ca.bc.gov.educ.api.grad.report.util.ThreadLocalStateUtil;
import jakarta.transaction.Transactional;
import lombok.SneakyThrows;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
Expand Down Expand Up @@ -693,7 +693,6 @@ public List<ReportGradStudentData> getSchoolReportGradStudentData() {
return processReportGradStudentDataList(students, new ArrayList<>());
}

@SneakyThrows
private List<ReportGradStudentData> processReportGradStudentDataList(Page<SchoolReportEntity> students, List<String> schools) {
List<ReportGradStudentData> result = new ArrayList<>();
long startTime = System.currentTimeMillis();
Expand All @@ -717,8 +716,9 @@ private List<ReportGradStudentData> processReportGradStudentDataList(Page<School
return result;
}

private List<ReportGradStudentData> getNextPageStudentsFromGradStudentApi(Page<SchoolReportEntity> students, List<String> schools) {
List<UUID> studentGuidsInBatch = students.getContent().stream().map(SchoolReportEntity::getGraduationStudentRecordId).toList();
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;
Expand All @@ -733,21 +733,31 @@ private List<ReportGradStudentData> getNextPageStudentsFromGradStudentApi(Page<S
for(SchoolReportEntity e: students.getContent()) {
String paperType = e.getPaperType();
String certificateTypeCode = e.getCertificateTypeCode(); //either transcript or certificate codes
for(ReportGradStudentData s: studentsInBatch) {
if(s.getGraduationStudentRecordId().equals(e.getGraduationStudentRecordId())) {
s.setPaperType(paperType);
if("YED4".equalsIgnoreCase(paperType)) {
s.setTranscriptTypeCode(certificateTypeCode);
} else {
s.setCertificateTypeCode(certificateTypeCode);
}
ReportGradStudentData s = getReportGradStudentDataByGraduationStudentRecordIdFromList(e.getGraduationStudentRecordId(), studentsInBatch);
if(s != null) {
ReportGradStudentData dataResult = SerializationUtils.clone(s);
dataResult.setPaperType(paperType);
if ("YED4".equalsIgnoreCase(paperType)) {
dataResult.setTranscriptTypeCode(certificateTypeCode);
} else {
dataResult.setCertificateTypeCode(certificateTypeCode);
}
result.add(dataResult);
}
}
return studentsInBatch;
return result;
}

private synchronized ReportGradStudentData getReportGradStudentDataByGraduationStudentRecordIdFromList(UUID id, List<ReportGradStudentData> studentsInBatch) {
for(ReportGradStudentData s: studentsInBatch) {
if(s.getGraduationStudentRecordId().equals(id)) {
return s;
}
}
return null;
}

private List<ReportGradStudentData> getReportGradStudentData(String accessToken, List<UUID> studentGuids) {
private synchronized List<ReportGradStudentData> getReportGradStudentData(String accessToken, List<UUID> studentGuids) {
final ParameterizedTypeReference<List<ReportGradStudentData>> responseType = new ParameterizedTypeReference<>() {
};
return this.webClient.post()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ public void testGetSchoolReportGradStudentData() {
reportGradStudentDataList.add(reportGradStudentData);

SchoolReportEntity schoolReportEntity = new SchoolReportEntity();
schoolReportEntity.setGraduationStudentRecordId(studentId);
schoolReportEntity.setSchoolReportEntityId(new SchoolReportEntityId(studentId, "EBDR", "E"));

when(schoolReportYearEndRepository.findStudentForSchoolYearEndReport(PageRequest.of(0, PAGE_SIZE))).thenReturn(new Page() {

Expand Down

0 comments on commit 18df823

Please sign in to comment.