Skip to content

Commit

Permalink
Merge pull request #584 from bcgov/feature/GRAD2-2372
Browse files Browse the repository at this point in the history
GRAD2-2372: a P2 issue has been resolved.
  • Loading branch information
infstar authored Oct 24, 2023
2 parents 38bc102 + e924ebf commit 398ae18
Showing 1 changed file with 71 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ public Pair<GraduationStudentRecord, GradStatusEvent> saveGraduationStatus(UUID
GraduationStudentRecordEntity sourceObject = graduationStatusTransformer.transformToEntity(graduationStatus);
if (gradStatusOptional.isPresent()) {
GraduationStudentRecordEntity gradEntity = gradStatusOptional.get();
BeanUtils.copyProperties(sourceObject, gradEntity, CREATE_USER, CREATE_DATE, "recalculateGradStatus", "recalculateProjectedGrad", "programCompletionDate");
BeanUtils.copyProperties(sourceObject, gradEntity, CREATE_USER, CREATE_DATE, "recalculateGradStatus", "recalculateProjectedGrad", "programCompletionDate", "studentProjectedGradData");
gradEntity.setBatchId(batchId);
if(!gradEntity.getProgram().equalsIgnoreCase("SCCP") && !gradEntity.getProgram().equalsIgnoreCase("NOPROG")) {
gradEntity.setProgramCompletionDate(sourceObject.getProgramCompletionDate());
}

if (sourceObject.getStudentProjectedGradData() != null) {
gradEntity.setStudentProjectedGradData(sourceObject.getStudentProjectedGradData());
}
if(batchId != null) {
resetBatchFlags(gradEntity, false);
}
Expand Down Expand Up @@ -225,7 +227,7 @@ public Pair<GraduationStudentRecord, GradStatusEvent> updateGraduationStatus(UUI
gradEntity.setRecalculateProjectedGrad(hasDataChanged.getRecalculateProgectedGrad());
}

BeanUtils.copyProperties(sourceObject, gradEntity, CREATE_USER, CREATE_DATE, "studentGradData", "recalculateGradStatus", "recalculateProjectedGrad");
BeanUtils.copyProperties(sourceObject, gradEntity, CREATE_USER, CREATE_DATE, "studentGradData", "studentProjectedGradData", "recalculateGradStatus", "recalculateProjectedGrad");
gradEntity.setProgramCompletionDate(sourceObject.getProgramCompletionDate());
gradEntity.setUpdateUser("");
gradEntity = graduationStatusRepository.saveAndFlush(gradEntity);
Expand Down Expand Up @@ -572,48 +574,48 @@ private void validateStudentStatus(String studentStatus) {

private void validateProgram(GraduationStudentRecordEntity sourceEntity, String accessToken) {
GradProgram gradProgram = webClient.get()
.uri(String.format(constants.getGradProgramNameUrl(), sourceEntity.getProgram()))
.headers(h -> {
.uri(String.format(constants.getGradProgramNameUrl(), sourceEntity.getProgram()))
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve()
.bodyToMono(GradProgram.class)
.block();
.retrieve()
.bodyToMono(GradProgram.class)
.block();
if (gradProgram == null) {
validation.addError(String.format("Program [%s] is invalid", sourceEntity.getProgram()));
} else {
if (sourceEntity.getProgram().contains("1950")) {
if (!sourceEntity.getStudentGrade().equalsIgnoreCase("AD")
&& !sourceEntity.getStudentGrade().equalsIgnoreCase("AN")) {
&& !sourceEntity.getStudentGrade().equalsIgnoreCase("AN")) {
validation.addError(
String.format("Student grade should be one of AD or AN if the student program is [%s]",
sourceEntity.getProgram()));
String.format("Student grade should be one of AD or AN if the student program is [%s]",
sourceEntity.getProgram()));
}
} else {
if (sourceEntity.getStudentGrade().equalsIgnoreCase("AD")
|| sourceEntity.getStudentGrade().equalsIgnoreCase("AN")) {
|| sourceEntity.getStudentGrade().equalsIgnoreCase("AN")) {
validation.addError(
String.format("Student grade should not be AD or AN for this program [%s]",
sourceEntity.getProgram()));
String.format("Student grade should not be AD or AN for this program [%s]",
sourceEntity.getProgram()));
}
}
}
}

private void validateSchool(String minCode, String accessToken) {
School schObj = webClient.get()
.uri(String.format(constants.getSchoolByMincodeUrl(), minCode))
.headers(h -> {
.uri(String.format(constants.getSchoolByMincodeUrl(), minCode))
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve()
.bodyToMono(School.class)
.block();
.retrieve()
.bodyToMono(School.class)
.block();
if (schObj == null) {
validation.addError(
String.format("Invalid School entered, School [%s] does not exist on the School table", minCode));
String.format("Invalid School entered, School [%s] does not exist on the School table", minCode));
} else {
if (schObj.getOpenFlag().equalsIgnoreCase("N")) {
validation.addWarning(String.format("This School [%s] is Closed", minCode));
Expand All @@ -623,14 +625,14 @@ private void validateSchool(String minCode, String accessToken) {

private void validateStudentGrade(GraduationStudentRecordEntity sourceEntity, GraduationStudentRecordEntity existingEntity, String accessToken) {
Student studentObj = webClient.get()
.uri(String.format(constants.getPenStudentApiByStudentIdUrl(), sourceEntity.getStudentID()))
.headers(h -> {
.uri(String.format(constants.getPenStudentApiByStudentIdUrl(), sourceEntity.getStudentID()))
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve()
.bodyToMono(Student.class)
.block();
.retrieve()
.bodyToMono(Student.class)
.block();
if(studentObj != null) {
if (sourceEntity.getStudentStatus() != null && studentObj.getStatusCode() != null &&
!PenGradStudentStatusEnum.valueOf(sourceEntity.getStudentStatus()).toString().equalsIgnoreCase(studentObj.getStatusCode())
Expand Down Expand Up @@ -709,17 +711,17 @@ private String getHonoursFlag(String gPA) {

public List<StudentOptionalProgram> getStudentGradOptionalProgram(UUID studentID, String accessToken) {
List<StudentOptionalProgram> optionalProgramList =
gradStudentOptionalProgramTransformer.transformToDTO(gradStudentOptionalProgramRepository.findByStudentID(studentID));
gradStudentOptionalProgramTransformer.transformToDTO(gradStudentOptionalProgramRepository.findByStudentID(studentID));
optionalProgramList.forEach(sP -> {
OptionalProgram gradOptionalProgram = webClient.get()
.uri(String.format(constants.getGradOptionalProgramNameUrl(), sP.getOptionalProgramID()))
.headers(h -> {
.uri(String.format(constants.getGradOptionalProgramNameUrl(), sP.getOptionalProgramID()))
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve()
.bodyToMono(OptionalProgram.class)
.block();
.retrieve()
.bodyToMono(OptionalProgram.class)
.block();
if(gradOptionalProgram != null) {
sP.setOptionalProgramName(gradOptionalProgram.getOptionalProgramName());
sP.setOptionalProgramCode(gradOptionalProgram.getOptProgramCode());
Expand All @@ -738,7 +740,7 @@ public int calculateAge(String dob) {

public StudentOptionalProgram saveStudentGradOptionalProgram(StudentOptionalProgram gradStudentOptionalProgram) {
Optional<StudentOptionalProgramEntity> gradStudentOptionalOptional =
gradStudentOptionalProgramRepository.findById(gradStudentOptionalProgram.getId());
gradStudentOptionalProgramRepository.findById(gradStudentOptionalProgram.getId());
logger.debug("Save with payload ==> Student Optional Program ID: {}", gradStudentOptionalProgram.getId());
StudentOptionalProgramEntity sourceObject = gradStudentOptionalProgramTransformer.transformToEntity(gradStudentOptionalProgram);
sourceObject.setUpdateUser(null); //this change is just till idir login is fixed
Expand All @@ -763,14 +765,14 @@ public StudentOptionalProgram updateStudentGradOptionalProgram(StudentOptionalPr

StudentOptionalProgramEntity sourceObject = new StudentOptionalProgramEntity();
OptionalProgram gradOptionalProgram = webClient.get()
.uri(String.format(constants.getGradOptionalProgramDetailsUrl(), gradStudentOptionalProgramReq.getMainProgramCode(),gradStudentOptionalProgramReq.getOptionalProgramCode()))
.headers(h -> {
.uri(String.format(constants.getGradOptionalProgramDetailsUrl(), gradStudentOptionalProgramReq.getMainProgramCode(),gradStudentOptionalProgramReq.getOptionalProgramCode()))
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve()
.bodyToMono(OptionalProgram.class)
.block();
.retrieve()
.bodyToMono(OptionalProgram.class)
.block();
sourceObject.setId(gradStudentOptionalProgramReq.getId());
sourceObject.setStudentID(gradStudentOptionalProgramReq.getStudentID());
sourceObject.setOptionalProgramCompletionDate(gradStudentOptionalProgramReq.getOptionalProgramCompletionDate() != null ?Date.valueOf(gradStudentOptionalProgramReq.getOptionalProgramCompletionDate()) : null);
Expand Down Expand Up @@ -809,21 +811,21 @@ public BatchGraduationStudentRecord getStudentForBatch(UUID studentID) {

@Retry(name = "generalgetcall")
public StudentOptionalProgram getStudentGradOptionalProgramByProgramCodeAndOptionalProgramCode(
UUID studentID, String optionalProgramID, String accessToken) {
UUID studentID, String optionalProgramID, String accessToken) {
UUID optionalProgramIDUUID = UUID.fromString(optionalProgramID);
Optional<StudentOptionalProgramEntity> gradStudentOptionalOptional =
gradStudentOptionalProgramRepository.findByStudentIDAndOptionalProgramID(studentID, optionalProgramIDUUID);
gradStudentOptionalProgramRepository.findByStudentIDAndOptionalProgramID(studentID, optionalProgramIDUUID);
if (gradStudentOptionalOptional.isPresent()) {
StudentOptionalProgram responseObj = gradStudentOptionalProgramTransformer.transformToDTO(gradStudentOptionalOptional);
OptionalProgram gradOptionalProgram = webClient.get()
.uri(String.format(constants.getGradOptionalProgramNameUrl(), responseObj.getOptionalProgramID()))
.headers(h -> {
.uri(String.format(constants.getGradOptionalProgramNameUrl(), responseObj.getOptionalProgramID()))
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve()
.bodyToMono(OptionalProgram.class)
.block();
.retrieve()
.bodyToMono(OptionalProgram.class)
.block();
if(gradOptionalProgram != null) {
responseObj.setOptionalProgramName(gradOptionalProgram.getOptionalProgramName());
responseObj.setOptionalProgramCode(gradOptionalProgram.getOptProgramCode());
Expand All @@ -843,18 +845,18 @@ public boolean getStudentStatus(String statusCode) {
@Retry(name = "generalpostcall")
public Pair<GraduationStudentRecord, GradStatusEvent> undoCompletionStudent(UUID studentID, String ungradReasonCode, String ungradDesc, String accessToken) throws JsonProcessingException {
if(StringUtils.isNotBlank(ungradReasonCode)) {
UndoCompletionReason ungradReasonObj = webClient.get().uri(String.format(constants.getUndoCompletionReasonDetailsUrl(),ungradReasonCode))
UndoCompletionReason ungradReasonObj = webClient.get().uri(String.format(constants.getUndoCompletionReasonDetailsUrl(),ungradReasonCode))
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve().bodyToMono(UndoCompletionReason.class).block();
if(ungradReasonObj != null) {
Optional<GraduationStudentRecordEntity> gradStatusOptional = graduationStatusRepository.findById(studentID);
if (gradStatusOptional.isPresent()) {
GraduationStudentRecordEntity gradEntity = gradStatusOptional.get();
saveUndoCompletionReason(studentID,ungradReasonCode,ungradDesc,accessToken);
deleteStudentAchievements(studentID,accessToken);
if(ungradReasonObj != null) {
Optional<GraduationStudentRecordEntity> gradStatusOptional = graduationStatusRepository.findById(studentID);
if (gradStatusOptional.isPresent()) {
GraduationStudentRecordEntity gradEntity = gradStatusOptional.get();
saveUndoCompletionReason(studentID,ungradReasonCode,ungradDesc,accessToken);
deleteStudentAchievements(studentID,accessToken);
gradEntity.setRecalculateGradStatus("Y");
gradEntity.setRecalculateProjectedGrad("Y");
gradEntity.setStudentGradData(null);
Expand All @@ -870,22 +872,22 @@ public Pair<GraduationStudentRecord, GradStatusEvent> undoCompletionStudent(UUID
gradStatusEventRepository.save(gradStatusEvent);
}
return Pair.of(graduationStatusTransformer.transformToDTO(gradEntity), gradStatusEvent);
} else {
validation.addErrorAndStop(String.format("Student ID [%s] does not exists", studentID));
return Pair.of(null, null);
}
}else {
validation.addErrorAndStop(String.format("Invalid Ungrad Reason Code [%s]",ungradReasonCode));
} else {
validation.addErrorAndStop(String.format("Student ID [%s] does not exists", studentID));
return Pair.of(null, null);
}
}else {
validation.addErrorAndStop(String.format("Invalid Ungrad Reason Code [%s]",ungradReasonCode));
return Pair.of(null, null);
}
}
}else {
validation.addErrorAndStop("Ungrad Reason Code is required");
validation.addErrorAndStop("Ungrad Reason Code is required");
return Pair.of(null, null);
}
}

public void deleteStudentAchievements(UUID studentID,String accessToken) {
try {
try {
webClient.delete().uri(String.format(constants.getDeleteStudentAchievements(), studentID))
.headers(h -> {
h.setBearerAuth(accessToken);
Expand All @@ -894,7 +896,7 @@ public void deleteStudentAchievements(UUID studentID,String accessToken) {
}catch (Exception e) {
logger.error(e.getLocalizedMessage());
}
}
}

public void archiveStudentAchievements(UUID studentID,String accessToken) {
try {
Expand All @@ -909,7 +911,7 @@ public void archiveStudentAchievements(UUID studentID,String accessToken) {
}


public void saveUndoCompletionReason(UUID studentID, String ungradReasonCode, String unGradDesc,String accessToken) {
public void saveUndoCompletionReason(UUID studentID, String ungradReasonCode, String unGradDesc,String accessToken) {
StudentUndoCompletionReason toBeSaved = new StudentUndoCompletionReason();
toBeSaved.setGraduationStudentRecordID(studentID);
toBeSaved.setUndoCompletionReasonCode(ungradReasonCode);
Expand Down Expand Up @@ -954,22 +956,22 @@ private GradStatusEvent createGradStatusEvent(String updateUser,
}

@Retry(name = "generalpostcall")
public boolean restoreGradStudentRecord(UUID studentID,boolean isGraduated) {
Optional<GraduationStudentRecordEntity> gradStatusOptional = graduationStatusRepository.findById(studentID);
public boolean restoreGradStudentRecord(UUID studentID,boolean isGraduated) {
Optional<GraduationStudentRecordEntity> gradStatusOptional = graduationStatusRepository.findById(studentID);
if (gradStatusOptional.isPresent()) {
GraduationStudentRecordEntity gradEnity = gradStatusOptional.get();
gradEnity.setRecalculateGradStatus("Y");
if(!isGraduated) {
gradEnity.setProgramCompletionDate(null);
gradEnity.setHonoursStanding(null);
gradEnity.setGpa(null);
gradEnity.setSchoolAtGrad(null);
gradEnity.setProgramCompletionDate(null);
gradEnity.setHonoursStanding(null);
gradEnity.setGpa(null);
gradEnity.setSchoolAtGrad(null);
}
graduationStatusRepository.save(gradEnity);
return true;
}
return false;
}
}

@Retry(name = "generalpostcall")
public GraduationStudentRecord saveStudentRecordDistributionRun(UUID studentID, Long batchId,String activityCode) {
Expand Down

0 comments on commit 398ae18

Please sign in to comment.