Skip to content

Commit

Permalink
GRAD2-2389: NewStudent event is enhanced to use the right history act…
Browse files Browse the repository at this point in the history
…ivity code.

GRAD2-2389: NewStudent event is enhanced to use the right history activity code.
  • Loading branch information
infstar committed Nov 29, 2023
1 parent a7b48aa commit fd06516
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void clearMaps() {
specialCaseMap.clear();
}

public ConvGradStudent convertStudent(ConvGradStudent convGradStudent, ConversionStudentSummaryDTO summary, boolean reload) throws Exception {
public ConvGradStudent convertStudent(ConvGradStudent convGradStudent, ConversionStudentSummaryDTO summary, boolean reload, boolean ongoingUpdate) throws Exception {
long startTime = System.currentTimeMillis();
summary.setProcessedCount(summary.getProcessedCount() + 1L);

Expand All @@ -91,7 +91,7 @@ public ConvGradStudent convertStudent(ConvGradStudent convGradStudent, Conversio
}

// Student conversion process
process(convGradStudent, students, summary, reload);
process(convGradStudent, students, summary, reload, ongoingUpdate);

long diff = (System.currentTimeMillis() - startTime) / 1000L;
log.info("** PEN: {} - {} secs", convGradStudent.getPen(), diff);
Expand Down Expand Up @@ -155,24 +155,24 @@ private boolean validateProgramCompletionDate(ConvGradStudent convGradStudent, C
return true;
}

private void process(ConvGradStudent convGradStudent, List<Student> students, ConversionStudentSummaryDTO summary, boolean reload) {
private void process(ConvGradStudent convGradStudent, List<Student> students, ConversionStudentSummaryDTO summary, boolean reload, boolean ongoingUpdate) {
convGradStudent.setOriginalStudentLoadType(convGradStudent.getStudentLoadType());
switch (convGradStudent.getStudentLoadType()) {
case UNGRAD -> {
log.debug("Process Non-Graduated Student for pen# : " + convGradStudent.getPen());
processConversion(convGradStudent, students, summary, reload);
processConversion(convGradStudent, students, summary, reload, ongoingUpdate);
}
case GRAD_ONE -> {
log.debug("Process Graduated Student - 1 Program for pen# : " + convGradStudent.getPen());
processConversion(convGradStudent, students, summary, reload);
processConversion(convGradStudent, students, summary, reload, ongoingUpdate);
}
case GRAD_TWO -> {
log.debug("Process Graduated Student - 2 Programs for pen# : " + convGradStudent.getPen());
// phase 1
String graduationRequirementYear = convGradStudent.getGraduationRequirementYear();
convGradStudent.setGraduationRequirementYear("SCCP");
convGradStudent.setStudentLoadType(StudentLoadType.GRAD_ONE);
processConversion(convGradStudent, students, summary, reload);
processConversion(convGradStudent, students, summary, reload, ongoingUpdate);
// phase 2
convGradStudent.setGraduationRequirementYear(graduationRequirementYear);
convGradStudent.setSccDate(null);
Expand All @@ -182,20 +182,20 @@ private void process(ConvGradStudent convGradStudent, List<Student> students, Co
} else {
convGradStudent.setStudentLoadType(StudentLoadType.UNGRAD);
}
processConversion(convGradStudent, students, summary, false);
processConversion(convGradStudent, students, summary, false, ongoingUpdate);
}
default -> log.debug("skip process");
}
}

private void processConversion(ConvGradStudent convGradStudent, List<Student> students, ConversionStudentSummaryDTO summary, boolean reload) {
private void processConversion(ConvGradStudent convGradStudent, List<Student> students, ConversionStudentSummaryDTO summary, boolean reload, boolean ongoingUpdate) {
students.forEach(st -> {
if (reload) {
restUtils.removeAllStudentRelatedData(UUID.fromString(st.getStudentID()), summary.getAccessToken());
}
GraduationStudentRecord gradStudent = processStudent(convGradStudent, st, summary);
GraduationStudentRecord gradStudent = processStudent(convGradStudent, st, ongoingUpdate, summary);
if (gradStudent != null) {
processDependencies(convGradStudent, gradStudent, st, summary, reload);
processDependencies(convGradStudent, gradStudent, st, summary, reload, ongoingUpdate);
}

if (convGradStudent.getResult() == null) {
Expand All @@ -204,7 +204,7 @@ private void processConversion(ConvGradStudent convGradStudent, List<Student> st
});
}

private GraduationStudentRecord processStudent(ConvGradStudent convGradStudent, Student penStudent, ConversionStudentSummaryDTO summary) {
private GraduationStudentRecord processStudent(ConvGradStudent convGradStudent, Student penStudent, boolean ongoingUpdate, ConversionStudentSummaryDTO summary) {
UUID studentID = UUID.fromString(penStudent.getStudentID());
GraduationStudentRecord gradStudent = null;
try {
Expand All @@ -225,7 +225,7 @@ private GraduationStudentRecord processStudent(ConvGradStudent convGradStudent,
gradStudent.setUpdateDate(null);
gradStudent.setUpdateUser(null);
try {
gradStudent = restUtils.saveStudentGradStatus(penStudent.getStudentID(), gradStudent, summary.getAccessToken());
gradStudent = restUtils.saveStudentGradStatus(penStudent.getStudentID(), gradStudent, ongoingUpdate, summary.getAccessToken());
} catch (Exception e) {
log.error(EXCEPTION_MSG, e);
handleException(convGradStudent, summary, convGradStudent.getPen(), ConversionResultType.FAILURE, GRAD_STUDENT_API_ERROR_MSG + "saving a GraduationStudentRecord : " + e.getLocalizedMessage());
Expand All @@ -244,7 +244,7 @@ private GraduationStudentRecord processStudent(ConvGradStudent convGradStudent,
}
if (ConversionResultType.FAILURE != convGradStudent.getResult()) {
try {
gradStudent = restUtils.saveStudentGradStatus(penStudent.getStudentID(), gradStudent, summary.getAccessToken());
gradStudent = restUtils.saveStudentGradStatus(penStudent.getStudentID(), gradStudent, ongoingUpdate, summary.getAccessToken());
} catch (Exception e) {
log.error(EXCEPTION_MSG, e);
handleException(convGradStudent, summary, convGradStudent.getPen(), ConversionResultType.FAILURE, GRAD_STUDENT_API_ERROR_MSG + "saving a GraduationStudentRecord : " + e.getLocalizedMessage());
Expand All @@ -264,7 +264,7 @@ private void processDependencies(ConvGradStudent convGradStudent,
GraduationStudentRecord gradStudent,
Student penStudent,
ConversionStudentSummaryDTO summary,
boolean reload) {
boolean reload, boolean ongoingUpdate) {
ConversionResultType result;

// process dependencies
Expand All @@ -291,7 +291,7 @@ private void processDependencies(ConvGradStudent convGradStudent,
log.error("Json Parsing Error for StudentGradData: " + jpe.getLocalizedMessage());
}
try {
restUtils.saveStudentGradStatus(penStudent.getStudentID(), gradStudent, summary.getAccessToken());
restUtils.saveStudentGradStatus(penStudent.getStudentID(), gradStudent, ongoingUpdate, summary.getAccessToken());
} catch (Exception e) {
handleException(convGradStudent, summary, convGradStudent.getPen(), ConversionResultType.FAILURE, GRAD_STUDENT_API_ERROR_MSG + "updating a GraduationStudentRecord with clob data : " + e.getLocalizedMessage());
}
Expand Down Expand Up @@ -1179,28 +1179,28 @@ private void removeAndReCreateOptionalPrograms(StudentGradDTO gradStudent, Strin
List<String> optionalProgramCodes = new ArrayList<>();

studentOptionalPrograms.forEach(op -> {
log.info(" => [{}] optional program will be removed if exist.", op.getOptionalProgramCode());
log.info(" => [{}] optional program will be removed if exist for {}.", op.getOptionalProgramCode(), gradStudent.getProgram());
removeStudentOptionalProgram(op.getOptionalProgramID(), gradStudent, accessToken);
if (isOptionalProgramRecreationRequired(op.getOptionalProgramCode())) {
if (isOptionalProgramRecreationRequired(op.getOptionalProgramCode(), gradStudent.getNewProgram())) {
optionalProgramCodes.add(op.getOptionalProgramCode());
}
});

// Recreate nonFI & nonDD optional programs
optionalProgramCodes.forEach(opc -> {
log.info(" => [{}] optional program will be re-created.", opc);
log.info(" => [{}] optional program will be re-created for {}.", opc, gradStudent.getNewProgram());
addStudentOptionalProgram(opc, gradStudent, true, accessToken);
});
}
}

private void handleFIorDDOptionalProgram(StudentGradDTO gradStudent, String accessToken) {
if (gradStudent.isAddDualDogwood()) {
log.info(" => [DD] optional program will be added if not exist.");
log.info(" => [DD] optional program will be added if not exist for {}.", gradStudent.getNewProgram());
// new grad program has to be used
addStudentOptionalProgram("DD", gradStudent, true, accessToken);
} else if (gradStudent.isAddFrenchImmersion()) {
log.info(" => [FI] optional program will be added if not exist.");
log.info(" => [FI] optional program will be added if not exist for {}.", gradStudent.getNewProgram());
// new grad program has to be used
addStudentOptionalProgram("FI", gradStudent, true, accessToken);
}
Expand All @@ -1209,7 +1209,6 @@ private void handleFIorDDOptionalProgram(StudentGradDTO gradStudent, String acce
public void removeStudentOptionalProgram(String optionalProgramCode, StudentGradDTO gradStudent, String accessToken) {
OptionalProgram optionalProgram = restUtils.getOptionalProgram(gradStudent.getProgram(), optionalProgramCode, accessToken);
if (optionalProgram != null) {
log.info(" => removed optional program code : {}", optionalProgramCode);
removeStudentOptionalProgram(optionalProgram.getOptionalProgramID(), gradStudent, accessToken);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ConvGradStudent process(String pen) throws Exception {
return null;
}
// convert
responseStudent = studentProcess.convertStudent(students.get(0), summaryDTO, StringUtils.equalsIgnoreCase(reload, "Y"));
responseStudent = studentProcess.convertStudent(students.get(0), summaryDTO, StringUtils.equalsIgnoreCase(reload, "Y"), false);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public <T extends Object> void processEvent(T request, Event event) {
ConversionStudentSummaryDTO summary = new ConversionStudentSummaryDTO();
summary.setAccessToken(accessToken);
try {
studentProcess.convertStudent(convStudent, summary, false);
studentProcess.convertStudent(convStudent, summary, false, true);
} catch (Exception e) {
ConversionAlert error = new ConversionAlert();
error.setItem(convStudent.getPen());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class StudentBaseService {
// Optional Program Codes
private static final List<String> OPTIONAL_PROGRAM_CODES = Arrays.asList("AD", "BC", "BD");
private static final List<String> OPTIONAL_PROGRAM_CODES_FOR_RECREATION = Arrays.asList("AD", "BC", "BD", "CP");
private static final List<String> OPTIONAL_PROGRAM_CODES_FOR_SCCP_RECREATION = Arrays.asList("FR", "CP");

protected void handleException(ConvGradStudent convGradStudent, ConversionStudentSummaryDTO summary, String pen, ConversionResultType type, String reason) {
ConversionAlert error = new ConversionAlert();
Expand Down Expand Up @@ -144,8 +145,8 @@ public boolean isOptionalProgramCode(String code) {
return OPTIONAL_PROGRAM_CODES.contains(code);
}

public boolean isOptionalProgramRecreationRequired(String code) {
return OPTIONAL_PROGRAM_CODES_FOR_RECREATION.contains(code);
public boolean isOptionalProgramRecreationRequired(String code, String program) {
return "SCCP".equalsIgnoreCase(program)? OPTIONAL_PROGRAM_CODES_FOR_SCCP_RECREATION.contains(code) : OPTIONAL_PROGRAM_CODES_FOR_RECREATION.contains(code);
}

// GRAD2-2103: applied to 2023 & 2018 programs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public <T extends Object> void processEvent(T request, Event event) {
public void processFrenchImmersion(TraxFrenchImmersionUpdateDTO frenchImmersionUpdate, StudentGradDTO currentStudent, String accessToken) {
log.info(" Process French Immersion : studentID = {}", currentStudent.getStudentID());
if (studentProcess.hasAnyFrenchImmersionCourse(currentStudent.getProgram(), frenchImmersionUpdate.getPen(), accessToken)) {
log.info(" => create FI optional program");
log.info(" => [FI] optional program will be added if not exist for {}.", currentStudent.getProgram());
studentProcess.addStudentOptionalProgram("FI", currentStudent, false, accessToken);
studentProcess.triggerGraduationBatchRun(FI10ADD, currentStudent.getStudentID(), frenchImmersionUpdate.getPen(), "Y", "Y", accessToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,30 @@ public void processOptionalAndCareerPrograms(TraxXProgramDTO xprogram, StudentGr

currentStudent.getRemovedProgramCodes().forEach(p -> {
if (isOptionalProgramCode(p)) {
log.info(" => removed optional program code : {}", p);
log.info(" => [{}] optional program will be removed if exist for {}.", p, currentStudent.getProgram());
studentProcess.removeStudentOptionalProgram(p, currentStudent, accessToken);
} else {
log.info(" => removed career program code : {}", p);
log.info(" => [{}] career program will be removed if exist for {}.", p, currentStudent.getProgram());
studentProcess.removeStudentCareerProgram(p, currentStudent, accessToken);
}
});

currentStudent.getAddedProgramCodes().forEach(p -> {
if (isOptionalProgramCode(p)) {
log.info(" => new optional program code : {}", p);
log.info(" => [{}] optional program will be added if not exist for {}.", p, currentStudent.getProgram());
studentProcess.addStudentOptionalProgram(p, currentStudent, false, accessToken);
} else {
log.info(" => new career program code : {}", p);
log.info(" => [{}] career program will be added if not exist for {}.", p, currentStudent.getProgram());
studentProcess.addStudentCareerProgram(p, currentStudent.getStudentID(), accessToken);
}
});

// No Career Program? then remove CP optional program
if (studentProcess.existsCareerProgram(currentStudent.getStudentID(), accessToken)) {
log.info(" => [CP] optional program will be added if not exist.");
log.info(" => [CP] optional program will be added if not exist for {}.", currentStudent.getProgram());
studentProcess.addStudentOptionalProgram("CP", currentStudent, false, accessToken);
} else {
log.info(" => [CP] optional program will be removed if exist.");
log.info(" => [CP] optional program will be removed if exist for {}.", currentStudent.getProgram());
studentProcess.removeStudentOptionalProgram("CP", currentStudent, accessToken);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,10 @@ public GraduationStudentRecord getStudentGradStatus(String studentID, String acc

// Save GraduationStudentRecord - POST /student/conv/studentid/{id}
@Retry(name = "rt-saveStudentGradStatus", fallbackMethod = "rtSaveStudentGradStatusFallback")
public GraduationStudentRecord saveStudentGradStatus(String studentID, GraduationStudentRecord toBeSaved, String accessToken) {
public GraduationStudentRecord saveStudentGradStatus(String studentID, GraduationStudentRecord toBeSaved, boolean ongoingUpdate, String accessToken) {
return webClient.post()
.uri(String.format(constants.getSaveGraduationStudentRecord(),studentID),
uri -> uri.queryParam("ongoingUpdate", false)
uri -> uri.queryParam("ongoingUpdate", ongoingUpdate)
.build())
.headers(h -> {
h.setBearerAuth(accessToken);
Expand Down
Loading

0 comments on commit fd06516

Please sign in to comment.