Skip to content

Commit

Permalink
Grad release 1.24.0 (#690)
Browse files Browse the repository at this point in the history
* GRAD2-2934: task is completed.

GRAD2-2934: task is completed.

* Merging changes from hotfix 1.23.3 (#687)

* Update update-configmap.sh

* Update pom.xml

* GRAD2-2971
Student Archive for one school needs to be able to handle > 1000 students

---------

Co-authored-by: githubmamatha <106563495+githubmamatha@users.noreply.github.com>
Co-authored-by: arybakov <alex.rybakov@cgi.com>
Co-authored-by: Jinil Sung <infstar@gmail.com>

* Enhancement is done after code review.

Enhancement is done after code review.

* GRAD2-2950: missing requirements are implemented.

GRAD2-2950: missing requirements are implemented.

---------

Co-authored-by: Jinil Sung <infstar@gmail.com>
Co-authored-by: githubmamatha <106563495+githubmamatha@users.noreply.github.com>
Co-authored-by: arybakov <alex.rybakov@cgi.com>
  • Loading branch information
4 people authored Oct 3, 2024
1 parent 464776c commit ea85462
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
*/
@Slf4j
@Service
public class DataConversionService {
public class DataConversionService extends GradBaseService {

public static final String NULL_VALUE = "NULL"; // NULL String => Nullify (set to NULL)
private static final String CREATE_USER = "createUser";
private static final String CREATE_DATE = "createDate";
public static final String DEFAULT_CREATED_BY = "DATA_CONV";
Expand All @@ -45,6 +46,7 @@ public class DataConversionService {
private static final String UPDATE_ONGOING_HISTORY_ACTIVITY_CODE = "TRAXUPDATE";
private static final String DELETE_ONGOING_HISTORY_ACTIVITY_CODE = "TRAXDELETE";
private static final String ONGOING_UPDATE_FIELD_STR = " ==> {} for old value={}";

final WebClient webClient;
final GraduationStudentRecordRepository graduationStatusRepository;
final GraduationStatusTransformer graduationStatusTransformer;
Expand Down Expand Up @@ -117,6 +119,7 @@ public GraduationStudentRecord updateGraduationStatusByFields(OngoingUpdateReque
populateOngoingUpdateFields(requestDTO.getUpdateFields(), gradEntity, accessToken);
gradEntity.setUpdateDate(null);
gradEntity.setUpdateUser(null);
validateStudentStatusAndResetBatchFlags(gradEntity);
gradEntity = graduationStatusRepository.saveAndFlush(gradEntity);
historyService.createStudentHistory(gradEntity, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE);
if (constants.isStudentGuidPenXrefEnabled() && StringUtils.isNotBlank(requestDTO.getPen())) {
Expand Down Expand Up @@ -296,7 +299,7 @@ private void handleStudentAchievements(String currentProgram, String newProgram,
}

private void resetAdultStartDate(String currentProgram, String newProgram, GraduationStudentRecordEntity targetObject) {
// Only when 1950 adult program is channged to another, reset adultStartDate to null
// Only when 1950 adult program is changed to another, reset adultStartDate to null
if (!StringUtils.equalsIgnoreCase(currentProgram, newProgram) && "1950".equalsIgnoreCase(currentProgram)) {
targetObject.setAdultStartDate(null);
}
Expand Down Expand Up @@ -348,9 +351,10 @@ private void populate(OngoingUpdateFieldDTO field, GraduationStudentRecordEntity
}

private String getStringValue(Object value) {
if (value == null)
return null;
return (String) value;
if (value instanceof String str) {
return NULL_VALUE.equalsIgnoreCase(str) ? null : str;
}
return null;
}

private StudentOptionalProgramEntity handleExistingOptionalProgram(StudentOptionalProgramRequestDTO studentOptionalProgramReq, StudentOptionalProgramEntity gradEntity) {
Expand Down Expand Up @@ -386,4 +390,5 @@ private StudentOptionalProgramEntity handleNewOptionalProgram(StudentOptionalPro
return sourceObject;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ca.bc.gov.educ.api.gradstudent.service;

import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordEntity;

public abstract class GradBaseService {
// Student Status
public static final String STUDENT_STATUS_ARCHIVED = "ARC";
public static final String STUDENT_STATUS_MERGED = "MER";
public static final String STUDENT_STATUS_TERMINATED = "TER";

protected void validateStudentStatusAndResetBatchFlags(GraduationStudentRecordEntity gradEntity) {
String currentStudentStatus = gradEntity.getStudentStatus();
// GRAD2-2934
// 1. If a student in GRAD is ARC/TER then do not set TVR flag when their other data changes
// 2. If a student in GRAD is changed to ARC/TER then set TVR flag to NULL
if (STUDENT_STATUS_ARCHIVED.equalsIgnoreCase(currentStudentStatus) || STUDENT_STATUS_TERMINATED.equalsIgnoreCase(currentStudentStatus)) {
gradEntity.setRecalculateProjectedGrad(null);
}
// GRAD2-2922 & GRAD2-2950
// 1. If a student in GRAD is MER then do not set Transcript & TVR flags when their other data changes
// 2. If a student in GRAD is changed to MER then set Transcript & TVR flags to NULL
if (STUDENT_STATUS_MERGED.equalsIgnoreCase(currentStudentStatus)) {
gradEntity.setRecalculateGradStatus(null);
gradEntity.setRecalculateProjectedGrad(null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import static ca.bc.gov.educ.api.gradstudent.constant.EventStatus.DB_COMMITTED;

@Service
public class GraduationStatusService {
public class GraduationStatusService extends GradBaseService {

public static final int PAGE_SIZE = 500;

Expand Down Expand Up @@ -273,6 +273,7 @@ public Pair<GraduationStudentRecord, GradStatusEvent> updateGraduationStatus(UUI
BeanUtils.copyProperties(sourceObject, gradEntity, CREATE_USER, CREATE_DATE, "studentGradData", "studentProjectedGradData", "recalculateGradStatus", "recalculateProjectedGrad");
gradEntity.setProgramCompletionDate(sourceObject.getProgramCompletionDate());
gradEntity.setUpdateUser(null);
validateStudentStatusAndResetBatchFlags(gradEntity);
gradEntity = graduationStatusRepository.saveAndFlush(gradEntity);
historyService.createStudentHistory(gradEntity, USER_EDIT);
final GradStatusEvent gradStatusEvent = createGradStatusEvent(gradEntity.getUpdateUser(), gradEntity,
Expand Down Expand Up @@ -668,7 +669,7 @@ private void validateSchool(String minCode, String accessToken) {
}
}

private void validateStudentGrade(GraduationStudentRecordEntity sourceEntity, GraduationStudentRecordEntity existingEntity, String accessToken) {
private void validateGradeAndStatusWithPENStudent(GraduationStudentRecordEntity sourceEntity, GraduationStudentRecordEntity existingEntity, String accessToken) {
Student studentObj = webClient.get()
.uri(String.format(constants.getPenStudentApiByStudentIdUrl(), sourceEntity.getStudentID()))
.headers(h -> {
Expand Down Expand Up @@ -768,12 +769,12 @@ private ValidateDataResult validateData(GraduationStudentRecordEntity sourceEnti

if ((sourceEntity.getStudentGrade() != null && !sourceEntity.getStudentGrade().equalsIgnoreCase(existingEntity.getStudentGrade()))) {
hasDataChanged.recalculateAll();
validateStudentGrade(sourceEntity,existingEntity,accessToken);
validateGradeAndStatusWithPENStudent(sourceEntity,existingEntity,accessToken);
}

if (sourceEntity.getStudentStatus() != null && !sourceEntity.getStudentStatus().equalsIgnoreCase(existingEntity.getStudentStatus())) {
hasDataChanged.recalculateAll();
validateStudentGrade(sourceEntity,existingEntity,accessToken);
validateGradeAndStatusWithPENStudent(sourceEntity,existingEntity,accessToken);
}

return hasDataChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void testGraduationStudentRecordAsUpdate() {
GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity();
graduationStatusEntity.setStudentID(studentID);
graduationStatusEntity.setPen("123456789");
graduationStatusEntity.setStudentStatus("A");
graduationStatusEntity.setStudentStatus("CUR");
graduationStatusEntity.setRecalculateGradStatus("Y");
graduationStatusEntity.setProgram("2018-EN");
graduationStatusEntity.setSchoolOfRecord(mincode);
Expand Down Expand Up @@ -181,7 +181,7 @@ public void testGraduationStudentRecordAsOngoingUpdate() {
GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity();
graduationStatusEntity.setStudentID(studentID);
graduationStatusEntity.setPen(pen);
graduationStatusEntity.setStudentStatus("A");
graduationStatusEntity.setStudentStatus("CUR");
graduationStatusEntity.setStudentGrade(oldGrade);
graduationStatusEntity.setRecalculateGradStatus("Y");
graduationStatusEntity.setProgram(oldProgram);
Expand Down Expand Up @@ -384,6 +384,68 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentMergedStatus() {
assertThat(result.getRecalculateProjectedGrad()).isNull();
}

@Test
public void testGraduationStudentRecordAsOngoingUpdateForStudentArchivedStatus() {
// ID
UUID studentID = UUID.randomUUID();
String pen = "123456789";
String mincode = "12345678";
String oldStatus = "CUR";
String newStatus = "ARC";

GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity();
graduationStatusEntity.setStudentID(studentID);
graduationStatusEntity.setPen(pen);
graduationStatusEntity.setStudentStatus(oldStatus);
graduationStatusEntity.setRecalculateGradStatus("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.UPD_STD_STATUS);

OngoingUpdateFieldDTO field = OngoingUpdateFieldDTO.builder()
.type(FieldType.STRING).name(FieldName.STUDENT_STATUS).value(newStatus)
.build();
requestDTO.getUpdateFields().add(field);

GraduationStudentRecordEntity savedGraduationStatus = new GraduationStudentRecordEntity();
BeanUtils.copyProperties(graduationStatusEntity, savedGraduationStatus);
savedGraduationStatus.setRecalculateGradStatus(null);
savedGraduationStatus.setRecalculateProjectedGrad(null);
savedGraduationStatus.setStudentGradData(null);
savedGraduationStatus.setStudentProjectedGradData(null);
savedGraduationStatus.setStudentStatus(newStatus);

when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity));
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.getStudentStatus()).isEqualTo(newStatus);
assertThat(result.getSchoolOfRecord()).isEqualTo(graduationStatusEntity.getSchoolOfRecord());
assertThat(result.getGpa()).isEqualTo(graduationStatusEntity.getGpa());

assertThat(result.getStudentGradData()).isNull();
assertThat(result.getStudentProjectedGradData()).isNull();
assertThat(result.getRecalculateGradStatus()).isNull();
assertThat(result.getRecalculateProjectedGrad()).isNull();
}

@Test
public void testGraduationStudentRecordAsOngoingUpdateWhenSCCPStudent_isChangedTo_2018EN() {
// ID
Expand Down

0 comments on commit ea85462

Please sign in to comment.