diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordEntity.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordEntity.java index 665bc4ac..c429104b 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordEntity.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordEntity.java @@ -1,9 +1,9 @@ package ca.bc.gov.educ.api.gradstudent.model.entity; +import jakarta.persistence.*; import lombok.Data; import lombok.EqualsAndHashCode; -import jakarta.persistence.*; import java.util.Date; import java.util.UUID; @@ -78,6 +78,12 @@ public GraduationStudentRecordEntity() { @Column(name = "STUDENT_PROJECTED_GRAD_DATA", columnDefinition="CLOB") private String studentProjectedGradData; + @Column(name = "SCHOOL_OF_RECORD_ID", nullable = true) + private UUID schoolOfRecordId; + + @Column(name = "SCHOOL_AT_GRADUATION_ID", nullable = true) + private UUID schoolAtGraduationId; + @Transient private String legalFirstName; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordHistoryEntity.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordHistoryEntity.java index 6556a4c3..a7b4c323 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordHistoryEntity.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordHistoryEntity.java @@ -1,10 +1,10 @@ package ca.bc.gov.educ.api.gradstudent.model.entity; +import jakarta.persistence.*; import lombok.Data; import lombok.EqualsAndHashCode; import org.hibernate.annotations.GenericGenerator; -import jakarta.persistence.*; import java.util.Date; import java.util.UUID; @@ -75,6 +75,12 @@ public class GraduationStudentRecordHistoryEntity extends BaseEntity { @Column(name = "ADULT_START_DATE", nullable = true) private Date adultStartDate; + @Column(name = "SCHOOL_OF_RECORD_ID", nullable = true) + private UUID schoolOfRecordId; + + @Column(name = "SCHOOL_AT_GRADUATION_ID", nullable = true) + private UUID schoolAtGraduationId; + //@Lob //@Column(name = "STUDENT_PROJECTED_GRAD_DATA", columnDefinition="CLOB") @Transient diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordView.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordView.java index 8a7c834d..6e19ec77 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordView.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordView.java @@ -22,6 +22,8 @@ public interface GraduationStudentRecordView { public String getStudentCitizenship(); public Date getAdultStartDate(); public String getStudentProjectedGradData() ; + public UUID getSchoolOfRecordId(); + public UUID getSchoolAtGraduationId(); public LocalDateTime getCreateDate(); public LocalDateTime getUpdateDate(); } \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java index e8ed5be9..10a8b237 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java @@ -1234,17 +1234,16 @@ public GraduationStudentRecord saveStudentRecordDistributionRun(UUID studentID, } @Retry(name = "generalpostcall") - public void saveStudentHistoryRecordDistributionRun(UUID studentID, Long batchId, String activityCode, String studentStatus) { - Optional gradStatusOptional = graduationStatusRepository.findById(studentID); - if (gradStatusOptional.isPresent()) { - GraduationStudentRecordEntity gradEntity = gradStatusOptional.get(); - if(StringUtils.isNotBlank(studentStatus)) { - gradEntity.setStudentStatus(studentStatus); - } - gradEntity.setUpdateUser(null); - gradEntity.setUpdateDate(null); - gradEntity.setBatchId(batchId); - historyService.createStudentHistory(gradEntity, activityCode); + public void saveStudentHistoryRecordArchiveStudentsRun(UUID studentID, Long batchId, String activityCode) { + List graduationStudentRecordViews = graduationStatusRepository.findByStudentIDIn(List.of(studentID)); + for(GraduationStudentRecordView st: graduationStudentRecordViews) { + GraduationStudentRecordEntity toBeSaved = new GraduationStudentRecordEntity(); + BeanUtils.copyProperties(st, toBeSaved); + toBeSaved.setStudentStatus("ARC"); + toBeSaved.setUpdateUser(null); + toBeSaved.setUpdateDate(null); + toBeSaved.setBatchId(batchId); + historyService.createStudentHistory(toBeSaved, activityCode); } } @@ -1320,6 +1319,7 @@ private List processStudentDataList(Page studentGuids) { return result; } + @Generated private void processUUIDDataTasksAsync(List> tasks, List result) { if(tasks.isEmpty()) return; List> executionResult; @@ -1395,19 +1395,21 @@ public Long countBySchoolOfRecordsAndStudentStatus(List schoolOfRecords, @Transactional public Integer archiveStudents(long batchId, List schoolOfRecords, String studentStatus) { String recordStudentStatus = StringUtils.defaultString(studentStatus, "CUR"); + Integer archivedStudentsCount = 0; if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) { List graduationStudentRecordGuids = graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(schoolOfRecords, recordStudentStatus); for(UUID graduationStudentRecordGuid: graduationStudentRecordGuids) { - saveStudentHistoryRecordDistributionRun(graduationStudentRecordGuid, batchId, "USERSTUDARC", "ARC"); + saveStudentHistoryRecordArchiveStudentsRun(graduationStudentRecordGuid, batchId, "USERSTUDARC"); } - return graduationStatusRepository.archiveStudents(schoolOfRecords, recordStudentStatus, "ARC", batchId); + archivedStudentsCount = graduationStatusRepository.archiveStudents(schoolOfRecords, recordStudentStatus, "ARC", batchId); } else { List graduationStudentRecordGuids = graduationStatusRepository.findByStudentStatus(recordStudentStatus); for(UUID graduationStudentRecordGuid: graduationStudentRecordGuids) { - saveStudentHistoryRecordDistributionRun(graduationStudentRecordGuid, batchId, "USERSTUDARC", "ARC"); + saveStudentHistoryRecordArchiveStudentsRun(graduationStudentRecordGuid, batchId, "USERSTUDARC"); } - return graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId); + archivedStudentsCount = graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId); } + return archivedStudentsCount; } public void updateStudentFlagReadyForBatchJobByStudentIDs(String batchJobType, List studentIDs) { diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java index b55205e0..7c8db130 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java @@ -65,7 +65,7 @@ public void createStudentHistory(GraduationStudentRecordEntity curStudentEntity, graduationStudentRecordHistoryEntity.setCreateDate(curStudentEntity.getCreateDate()); graduationStudentRecordHistoryEntity.setActivityCode(historyActivityCode); graduationStudentRecordHistoryEntity.setStudentGradData("{ EMPTY CLOB }"); - graduationStudentRecordHistoryRepository.save(graduationStudentRecordHistoryEntity); + graduationStudentRecordHistoryRepository.saveAndFlush(graduationStudentRecordHistoryEntity); } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java index 50f27a05..fc78eb7e 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java @@ -422,6 +422,16 @@ public String getStudentProjectedGradData() { return null; } + @Override + public UUID getSchoolOfRecordId() { + return null; + } + + @Override + public UUID getSchoolAtGraduationId() { + return null; + } + @Override public LocalDateTime getCreateDate() { return null; @@ -432,10 +442,10 @@ public LocalDateTime getUpdateDate() { return null; } }; + List studentSubList = new ArrayList<>(); studentSubList.add(graduationStatusView.getStudentID()); - when(this.graduationStatusRepository.findByStudentID(studentID)).thenReturn(graduationStatusEntity); when(this.graduationStatusTransformer.transformToDTOWithModifiedProgramCompletionDate(graduationStatusEntity)).thenReturn(graduationStatus); when(this.graduationStatusRepository.findByStudentIDIn(studentSubList)).thenReturn(List.of(graduationStatusView)); diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java index 7fc023b2..e45fb6b0 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java @@ -2224,21 +2224,117 @@ public void testSaveStudentRecord_DistributionRun_2() { UUID studentID = new UUID(1, 1); Long batchId = null; - GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity(); - graduationStatusEntity.setStudentID(studentID); - graduationStatusEntity.setPen("12321321"); - graduationStatusEntity.setStudentStatus("A"); - graduationStatusEntity.setSchoolOfRecord("12345678"); + GraduationStudentRecordView graduationStatusEntity = new GraduationStudentRecordView() { - when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity)); + @Override + public String getProgram() { + return null; + } - doNothing().when(graduationStatusServiceMock).saveStudentHistoryRecordDistributionRun(studentID, batchId, "ACTIVITYCODE", "ARC"); - graduationStatusServiceMock.saveStudentHistoryRecordDistributionRun(studentID, batchId, "ACTIVITYCODE", "ARC"); - Mockito.verify(graduationStatusServiceMock).saveStudentHistoryRecordDistributionRun(studentID, batchId, "ACTIVITYCODE", "ARC"); + @Override + public java.util.Date getProgramCompletionDate() { + return null; + } + + @Override + public String getGpa() { + return null; + } + + @Override + public String getHonoursStanding() { + return null; + } + + @Override + public String getRecalculateGradStatus() { + return null; + } + + @Override + public String getSchoolOfRecord() { + return "12345678"; + } + + @Override + public String getStudentGrade() { + return null; + } + + @Override + public String getStudentStatus() { + return "A"; + } + + @Override + public UUID getStudentID() { + return studentID; + } + + @Override + public String getSchoolAtGrad() { + return null; + } + + @Override + public String getRecalculateProjectedGrad() { + return null; + } + + @Override + public Long getBatchId() { + return null; + } + + @Override + public String getConsumerEducationRequirementMet() { + return null; + } + + @Override + public String getStudentCitizenship() { + return null; + } + + @Override + public java.util.Date getAdultStartDate() { + return null; + } + + @Override + public String getStudentProjectedGradData() { + return null; + } + + @Override + public UUID getSchoolOfRecordId() { + return null; + } + + @Override + public UUID getSchoolAtGraduationId() { + return null; + } + + @Override + public LocalDateTime getCreateDate() { + return null; + } + + @Override + public LocalDateTime getUpdateDate() { + return null; + } + }; + + when(graduationStatusRepository.findByStudentIDIn(List.of(studentID))).thenReturn(List.of(graduationStatusEntity)); + + doNothing().when(graduationStatusServiceMock).saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE"); + graduationStatusServiceMock.saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE"); + Mockito.verify(graduationStatusServiceMock).saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE"); + + graduationStatusService.saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE"); - doNothing().when(graduationStatusServiceMock).saveStudentHistoryRecordDistributionRun(studentID, batchId, "ACTIVITYCODE", null); - graduationStatusServiceMock.saveStudentHistoryRecordDistributionRun(studentID, batchId, "ACTIVITYCODE", null); - Mockito.verify(graduationStatusServiceMock).saveStudentHistoryRecordDistributionRun(studentID, batchId, "ACTIVITYCODE", null); } @Test @@ -2336,6 +2432,16 @@ public String getStudentProjectedGradData() { return null; } + @Override + public UUID getSchoolOfRecordId() { + return null; + } + + @Override + public UUID getSchoolAtGraduationId() { + return null; + } + @Override public LocalDateTime getCreateDate() { return null; @@ -2810,6 +2916,16 @@ public String getStudentProjectedGradData() { return null; } + @Override + public UUID getSchoolOfRecordId() { + return null; + } + + @Override + public UUID getSchoolAtGraduationId() { + return null; + } + @Override public LocalDateTime getCreateDate() { return null; @@ -3058,6 +3174,16 @@ public String getStudentProjectedGradData() { return jsonTransformer.marshall(projectedRunClob); } + @Override + public UUID getSchoolOfRecordId() { + return null; + } + + @Override + public UUID getSchoolAtGraduationId() { + return null; + } + @Override public LocalDateTime getCreateDate() { return null;