Skip to content

Commit

Permalink
GRAD2-3019: task is complete.
Browse files Browse the repository at this point in the history
GRAD2-3019: task is complete.
  • Loading branch information
infstar committed Nov 4, 2024
1 parent d76a1e1 commit 5207c0b
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public enum TraxEventType {
NEWSTUDENT,
UPD_DEMOG,
UPD_GRAD,
UPD_STD_STATUS,
XPROGRAM,
ASSESSMENT,
COURSE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GraduationStudentRecord extends BaseModel {
private String schoolOfRecord;
private UUID schoolOfRecordId;
private String schoolName;
private String studentGrade;
private String studentGrade;
private String studentStatus;
private String studentStatusName;
private UUID studentID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,60 @@ INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (
@Query(value= INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_AND_STUDENT_ID_IN_SQL, nativeQuery=true)
Integer insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(@Param(value = "batchId") Long batchId, @Param(value = "studentIDs") List<UUID> studentIDs, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser);

@Modifying
@Query(value= INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_STUDENT_ID_IN_SQL, nativeQuery=true)
Integer insertGraduationStudentRecordHistoryByStudentId(@Param(value = "studentID") UUID studentID, @Param(value = "activityCode") String activityCode);

String INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_STUDENT_ID_IN_SQL = """
INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (
GRADUATION_STUDENT_RECORD_HISTORY_ID,
HISTORY_ACTIVITY_CODE,
GRADUATION_STUDENT_RECORD_ID,
GRADUATION_PROGRAM_CODE,
GPA,
STUDENT_STATUS_CODE,
HONOURS_STANDING,
PROGRAM_COMPLETION_DATE,
RECALCULATE_GRAD_STATUS,
SCHOOL_OF_RECORD,
STUDENT_GRADE,
SCHOOL_AT_GRADUATION,
CREATE_USER,
CREATE_DATE,
UPDATE_USER,
UPDATE_DATE,
RECALCULATE_PROJECTED_GRAD,
BATCH_ID,
CONSUMER_EDUC_REQT_MET,
STUDENT_CITIZENSHIP_CODE,
ADULT_START_DATE,
SCHOOL_OF_RECORD_ID,
SCHOOL_AT_GRADUATION_ID
) SELECT
SYS_GUID(),
:activityCode,
GRADUATION_STUDENT_RECORD_ID,
GRADUATION_PROGRAM_CODE,
GPA,
STUDENT_STATUS_CODE,
HONOURS_STANDING,
PROGRAM_COMPLETION_DATE,
RECALCULATE_GRAD_STATUS,
SCHOOL_OF_RECORD,
STUDENT_GRADE,
SCHOOL_AT_GRADUATION,
CREATE_USER,
CREATE_DATE,
UPDATE_USER,
SYSDATE,
RECALCULATE_PROJECTED_GRAD,
BATCH_ID,
CONSUMER_EDUC_REQT_MET,
STUDENT_CITIZENSHIP_CODE,
ADULT_START_DATE,
SCHOOL_OF_RECORD_ID,
SCHOOL_AT_GRADUATION_ID
FROM GRADUATION_STUDENT_RECORD
WHERE GRADUATION_STUDENT_RECORD_ID = :studentID
""";
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,13 @@ public GraduationStudentRecord updateGraduationStatusByFields(OngoingUpdateReque
gradEntity.setUpdateDate(null);
gradEntity.setUpdateUser(null);
validateStudentStatusAndResetBatchFlags(gradEntity);
gradEntity = graduationStatusRepository.saveAndFlush(gradEntity);
historyService.createStudentHistory(gradEntity, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE);
if (isBatchFlagUpdatesOnly(eventType)) {
gradEntity = saveBatchFlagsWithAuditHistory(gradEntity.getStudentID(), gradEntity.getRecalculateGradStatus(),
gradEntity.getRecalculateProjectedGrad(), UPDATE_ONGOING_HISTORY_ACTIVITY_CODE);
} else {
gradEntity = graduationStatusRepository.saveAndFlush(gradEntity);
historyService.createStudentHistory(gradEntity, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE);
}
if (constants.isStudentGuidPenXrefEnabled() && StringUtils.isNotBlank(requestDTO.getPen())) {
saveStudentGuidPenXref(gradEntity.getStudentID(), requestDTO.getPen());
}
Expand All @@ -130,6 +135,10 @@ public GraduationStudentRecord updateGraduationStatusByFields(OngoingUpdateReque
return null;
}

private boolean isBatchFlagUpdatesOnly(TraxEventType eventType) {
return TraxEventType.NEWSTUDENT != eventType && TraxEventType.UPD_GRAD != eventType;
}

@Transactional
@Retry(name = "generalpostcall")
public StudentOptionalProgram saveStudentOptionalProgram(StudentOptionalProgramRequestDTO studentOptionalProgramReq, String accessToken) {
Expand Down Expand Up @@ -214,6 +223,15 @@ private void saveStudentGuidPenXref(UUID studentId, String pen) {
}
}

/**
* Update Batch Flags in Graduation Status for Ongoing Updates
*/
private GraduationStudentRecordEntity saveBatchFlagsWithAuditHistory(UUID studentID, String recalculateGradStatus, String recalculateProjectedGrad, String historyActivityCode) {
graduationStatusRepository.updateGradStudentRecalculationAllFlags(studentID, recalculateGradStatus, recalculateProjectedGrad);
gradStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByStudentId(studentID, historyActivityCode);
return graduationStatusRepository.findByStudentID(studentID);
}

@Transactional
public void deleteGraduationStatus(UUID studentID) {
// graduation_student_record
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentStatus() {
OngoingUpdateRequestDTO requestDTO = new OngoingUpdateRequestDTO();
requestDTO.setPen(pen);
requestDTO.setStudentID(studentID.toString());
requestDTO.setEventType(TraxEventType.UPD_STD_STATUS);
requestDTO.setEventType(TraxEventType.UPD_GRAD);

OngoingUpdateFieldDTO field = OngoingUpdateFieldDTO.builder()
.type(FieldType.STRING).name(FieldName.STUDENT_STATUS).value(newStatus)
Expand Down Expand Up @@ -322,6 +322,68 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentStatus() {
assertThat(result.getRecalculateGradStatus()).isNull();
}

@Test
public void testGraduationStudentRecordAsOngoingUpdateForBatchFlags() {
// ID
UUID studentID = UUID.randomUUID();
String pen = "123456789";
String mincode = "12345678";

GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity();
graduationStatusEntity.setStudentID(studentID);
graduationStatusEntity.setPen(pen);
graduationStatusEntity.setStudentStatus("CUR");
graduationStatusEntity.setRecalculateGradStatus(null);
graduationStatusEntity.setRecalculateProjectedGrad("Y");
graduationStatusEntity.setProgram("2018-EN");
graduationStatusEntity.setSchoolOfRecord(mincode);
graduationStatusEntity.setSchoolAtGrad(mincode);
graduationStatusEntity.setGpa("4");
graduationStatusEntity.setProgramCompletionDate(new Date(System.currentTimeMillis()));

OngoingUpdateRequestDTO requestDTO = new OngoingUpdateRequestDTO();
requestDTO.setPen(pen);
requestDTO.setStudentID(studentID.toString());
requestDTO.setEventType(TraxEventType.COURSE);

OngoingUpdateFieldDTO field1 = OngoingUpdateFieldDTO.builder()
.type(FieldType.STRING).name(FieldName.RECALC_GRAD_ALG).value("Y")
.build();
requestDTO.getUpdateFields().add(field1);

OngoingUpdateFieldDTO field2 = OngoingUpdateFieldDTO.builder()
.type(FieldType.STRING).name(FieldName.RECALC_TVR).value("NULL")
.build();
requestDTO.getUpdateFields().add(field2);

GraduationStudentRecordEntity savedGraduationStatus = new GraduationStudentRecordEntity();
BeanUtils.copyProperties(graduationStatusEntity, savedGraduationStatus);
savedGraduationStatus.setRecalculateGradStatus("Y");
savedGraduationStatus.setRecalculateProjectedGrad(null);

when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity));
when(graduationStatusRepository.findByStudentID(studentID)).thenReturn(savedGraduationStatus);
when(graduationStatusRepository.saveAndFlush(graduationStatusEntity)).thenReturn(savedGraduationStatus);

when(this.webClient.delete()).thenReturn(this.requestHeadersUriMock);
when(this.requestHeadersUriMock.uri(String.format(constants.getDeleteStudentAchievements(),studentID))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock);
when(this.requestBodyMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.bodyToMono(Integer.class)).thenReturn(Mono.just(0));

var result = dataConversionService.updateGraduationStatusByFields(requestDTO, "accessToken");

assertThat(result).isNotNull();
assertThat(result.getStudentID()).isEqualTo(graduationStatusEntity.getStudentID());
assertThat(result.getPen()).isEqualTo(graduationStatusEntity.getPen());

assertThat(result.getSchoolOfRecord()).isEqualTo(graduationStatusEntity.getSchoolOfRecord());
assertThat(result.getGpa()).isEqualTo(graduationStatusEntity.getGpa());

assertThat(result.getRecalculateGradStatus()).isEqualTo("Y");
assertThat(result.getRecalculateProjectedGrad()).isNull();
}

@Test
public void testGraduationStudentRecordAsOngoingUpdateForStudentMergedStatus() {
// ID
Expand All @@ -345,7 +407,7 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentMergedStatus() {
OngoingUpdateRequestDTO requestDTO = new OngoingUpdateRequestDTO();
requestDTO.setPen(pen);
requestDTO.setStudentID(studentID.toString());
requestDTO.setEventType(TraxEventType.UPD_STD_STATUS);
requestDTO.setEventType(TraxEventType.UPD_GRAD);

OngoingUpdateFieldDTO field = OngoingUpdateFieldDTO.builder()
.type(FieldType.STRING).name(FieldName.STUDENT_STATUS).value(newStatus)
Expand Down Expand Up @@ -407,7 +469,7 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentArchivedStatus()
OngoingUpdateRequestDTO requestDTO = new OngoingUpdateRequestDTO();
requestDTO.setPen(pen);
requestDTO.setStudentID(studentID.toString());
requestDTO.setEventType(TraxEventType.UPD_STD_STATUS);
requestDTO.setEventType(TraxEventType.UPD_GRAD);

OngoingUpdateFieldDTO field = OngoingUpdateFieldDTO.builder()
.type(FieldType.STRING).name(FieldName.STUDENT_STATUS).value(newStatus)
Expand Down

0 comments on commit 5207c0b

Please sign in to comment.