use of ca.bc.gov.educ.penreg.api.struct.PenRequestBatchUserActionsSagaData in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenReqBatchNewPenOrchestrator method addPossibleMatchesToStudent.
private void addPossibleMatchesToStudent(final Event event, final Saga saga, final PenRequestBatchUserActionsSagaData penRequestBatchUserActionsSagaData) throws JsonProcessingException {
final String studentID;
// this scenario might occur during replay when message could not reach batch api from student-api and batch api retried the same flow.
if (event.getEventOutcome() == STUDENT_ALREADY_EXIST) {
studentID = event.getEventPayload();
} else {
final Student student = JsonUtil.getJsonObjectFromString(Student.class, event.getEventPayload());
studentID = student.getStudentID();
}
penRequestBatchUserActionsSagaData.setStudentID(studentID);
final SagaEvent eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload());
// set current event as saga state.
saga.setSagaState(ADD_POSSIBLE_MATCH.toString());
// resave the updated saga data.
saga.setPayload(JsonUtil.getJsonStringFromObject(penRequestBatchUserActionsSagaData));
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);
final var possibleMatches = penRequestBatchUserActionsSagaData.getMatchedStudentIDList().stream().map(matchedStudentID -> PossibleMatch.builder().createUser(penRequestBatchUserActionsSagaData.getCreateUser()).updateUser(penRequestBatchUserActionsSagaData.getUpdateUser()).studentID(studentID).matchedStudentID(matchedStudentID).matchReasonCode(TwinReasonCodes.PENCREATE.getCode()).build()).collect(Collectors.toList());
final Event nextEvent = Event.builder().sagaId(saga.getSagaId()).eventType(ADD_POSSIBLE_MATCH).replyTo(this.getTopicToSubscribe()).eventPayload(JsonUtil.getJsonStringFromObject(possibleMatches)).build();
this.postMessageToTopic(PEN_MATCH_API_TOPIC.toString(), nextEvent);
log.info("message sent to PEN_MATCH_API_TOPIC for ADD_POSSIBLE_MATCH Event.");
}
use of ca.bc.gov.educ.penreg.api.struct.PenRequestBatchUserActionsSagaData in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenReqBatchUserMatchOrchestrator method updateGradeCodeAndGradeYear.
/**
* updated for https://gww.jira.educ.gov.bc.ca/browse/PEN-1348
* When district number is <b> NOT </b> 102, apply the following logic for grade code & grade year.
* If the student record grade is null, and the incoming batch grade is valid, take it and update the grade year
* Set the STUD_GRADE_YEAR to the current year (if after June 30) or the previous year (if before June 30)
*
* @param studentDataFromEventResponse the student from student api
* @param penRequestBatchUserActionsSagaData the pen request batch student data
*/
protected void updateGradeCodeAndGradeYear(final Student studentDataFromEventResponse, final PenRequestBatchUserActionsSagaData penRequestBatchUserActionsSagaData) {
final var gradeCodes = this.restUtils.getGradeCodes();
var batchGradeCode = penRequestBatchUserActionsSagaData.getGradeCode();
val isGradeCodeValid = StringUtils.isNotBlank(batchGradeCode) ? gradeCodes.stream().anyMatch(gradeCode1 -> LocalDateTime.now().isAfter(gradeCode1.getEffectiveDate()) && LocalDateTime.now().isBefore(gradeCode1.getExpiryDate()) && StringUtils.equalsIgnoreCase(batchGradeCode, gradeCode1.getGradeCode())) : false;
if (isGradeCodeValid && StringUtils.isBlank(studentDataFromEventResponse.getGradeCode())) {
studentDataFromEventResponse.setGradeCode(batchGradeCode);
val localDateTime = LocalDateTime.now();
if (localDateTime.getMonthValue() > 6) {
studentDataFromEventResponse.setGradeYear(String.valueOf(localDateTime.getYear()));
} else {
studentDataFromEventResponse.setGradeYear(String.valueOf(localDateTime.getYear() - 1));
}
}
}
use of ca.bc.gov.educ.penreg.api.struct.PenRequestBatchUserActionsSagaData in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenReqBatchUserMatchOrchestrator method addPossibleMatchToStudent.
/**
* this method expects that the twin ids provided in the payload here is already validated.
* Add twin records to student.
*
* @param event the event
* @param saga the saga
* @param penRequestBatchUserActionsSagaData the pen request batch user actions saga data
* @throws JsonProcessingException the json processing exception
*/
protected void addPossibleMatchToStudent(final Event event, final Saga saga, final PenRequestBatchUserActionsSagaData penRequestBatchUserActionsSagaData) throws JsonProcessingException {
final SagaEvent eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload());
// set current event as saga state.
saga.setSagaState(ADD_POSSIBLE_MATCH.toString());
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);
final var possibleMatches = penRequestBatchUserActionsSagaData.getMatchedStudentIDList().stream().map(matchedStudentID -> PossibleMatch.builder().createUser(penRequestBatchUserActionsSagaData.getCreateUser()).updateUser(penRequestBatchUserActionsSagaData.getUpdateUser()).studentID(penRequestBatchUserActionsSagaData.getStudentID()).matchedStudentID(matchedStudentID).matchReasonCode(TwinReasonCodes.PEN_MATCH.getCode()).build()).collect(Collectors.toList());
final Event nextEvent = Event.builder().sagaId(saga.getSagaId()).eventType(ADD_POSSIBLE_MATCH).replyTo(this.getTopicToSubscribe()).eventPayload(JsonUtil.getJsonStringFromObject(possibleMatches)).build();
this.postMessageToTopic(PEN_MATCH_API_TOPIC.toString(), nextEvent);
log.info("message sent to PEN_MATCH_API_TOPIC for ADD_POSSIBLE_MATCH Event.");
}
Aggregations