use of ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchResultDataDecorator method populateForUserMatchedStatus.
private void populateForUserMatchedStatus(Map<String, Student> studentMap, List<SchoolMinListItem> differencesList, PenRequestBatchStudentEntity penRequestBatchStudent) {
if (studentMap.get(penRequestBatchStudent.getStudentID().toString()) == null) {
log.error("Error attempting to create report data. Students list should not be null for USR_MATCHED status.");
return;
}
val matchedStudent = studentMap.get(penRequestBatchStudent.getStudentID().toString());
val item = new SchoolMinListItem();
item.setMin(listItemMapper.toListItem(matchedStudent));
item.setSchool(listItemMapper.toDiffListItem(penRequestBatchStudent));
differencesList.add(item);
}
use of ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchResultDataDecorator method populateForSystemMatchedStatus.
private void populateForSystemMatchedStatus(List<ListItem> exactMatchList, List<SchoolMinListItem> differencesList, Map<String, Student> studentMap, PenRequestBatchStudentEntity penRequestBatchStudent) {
val student = studentMap.get(penRequestBatchStudent.getStudentID().toString());
if (PenRegBatchHelper.exactMatch(PenRequestBatchStudentMapper.mapper.toStructure(penRequestBatchStudent), student)) {
exactMatchList.add(listItemMapper.toListItem(penRequestBatchStudent));
} else {
val item = new SchoolMinListItem();
item.setMin(listItemMapper.toListItem(student));
item.setSchool(listItemMapper.toDiffListItem(penRequestBatchStudent));
differencesList.add(item);
}
}
use of ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent in project EDUC-PEN-REG-BATCH-API by bcgov.
the class BaseUserActionsOrchestrator method updatePenRequestBatchStudent.
/**
* Update PEN Request Batch record and PRB Student record.
*
* @param event the event
* @param saga the saga
* @param t the pen request batch student saga data
* @throws JsonProcessingException the json processing exception
*/
protected void updatePenRequestBatchStudent(final Event event, final Saga saga, final T t) throws JsonProcessingException {
final PenRequestBatchStudent prbStudent = this.createPRBStudent(event, t);
saga.setSagaState(UPDATE_PEN_REQUEST_BATCH_STUDENT.toString());
final SagaEvent eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload());
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);
final Event nextEvent = Event.builder().sagaId(saga.getSagaId()).eventType(UPDATE_PEN_REQUEST_BATCH_STUDENT).replyTo(this.getTopicToSubscribe()).eventPayload(JsonUtil.getJsonStringFromObject(prbStudent)).build();
this.postMessageToTopic(PEN_REQUEST_BATCH_API_TOPIC.toString(), nextEvent);
log.info("message sent to PEN_REQUEST_BATCH_API_TOPIC for UPDATE_PEN_REQUEST_BATCH_STUDENT Event. :: {}", saga.getSagaId());
}
use of ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenReqBatchNewPenOrchestrator method updatePenRequestBatchStudent.
/**
* Update PEN Request Batch record and PRB Student record.
*
* @param event the event
* @param saga the saga
* @param penRequestBatchUserActionsSagaData the pen request batch student saga data
* @throws JsonProcessingException the json processing exception
*/
@Override
protected void updatePenRequestBatchStudent(final Event event, final Saga saga, final PenRequestBatchUserActionsSagaData penRequestBatchUserActionsSagaData) throws JsonProcessingException {
this.updateSagaData(event, penRequestBatchUserActionsSagaData);
saga.setSagaState(UPDATE_PEN_REQUEST_BATCH_STUDENT.toString());
saga.setPayload(JsonUtil.getJsonStringFromObject(penRequestBatchUserActionsSagaData));
final SagaEvent eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload());
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);
if (penRequestBatchUserActionsSagaData.getStudentID() == null) {
log.info("studentID in saga data is null for batch student id :: {} and saga id :: {}, setting it from event states table", penRequestBatchUserActionsSagaData.getPenRequestBatchStudentID(), saga.getSagaId());
val sagaEventOptional = this.getSagaService().findSagaEvent(saga, CREATE_STUDENT.toString(), 3);
if (sagaEventOptional.isPresent()) {
val sagaEvent = sagaEventOptional.get();
if (STUDENT_CREATED.toString().equals(sagaEvent.getSagaEventOutcome())) {
final Student student = JsonUtil.getJsonObjectFromString(Student.class, sagaEvent.getSagaEventResponse());
penRequestBatchUserActionsSagaData.setStudentID(student.getStudentID());
} else if (STUDENT_ALREADY_EXIST.toString().equals(sagaEvent.getSagaEventOutcome())) {
penRequestBatchUserActionsSagaData.setStudentID(sagaEvent.getSagaEventResponse());
} else {
throw new PenRegAPIRuntimeException("CREATE_STUDENT event with outcome not found in event states table for saga id :: " + saga.getSagaId());
}
} else {
throw new PenRegAPIRuntimeException("CREATE_STUDENT event not found in event states table for saga id :: " + saga.getSagaId());
}
}
final PenRequestBatchStudent prbStudent = this.createPRBStudent(event, penRequestBatchUserActionsSagaData);
final Event nextEvent = Event.builder().sagaId(saga.getSagaId()).eventType(UPDATE_PEN_REQUEST_BATCH_STUDENT).replyTo(this.getTopicToSubscribe()).eventPayload(JsonUtil.getJsonStringFromObject(prbStudent)).build();
this.postMessageToTopic(PEN_REQUEST_BATCH_API_TOPIC.toString(), nextEvent);
log.info("message sent to PEN_REQUEST_BATCH_API_TOPIC for UPDATE_PEN_REQUEST_BATCH_STUDENT Event. :: {}", saga.getSagaId());
}
use of ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent in project EDUC-PEN-REG-BATCH-API by bcgov.
the class ResponseFileGeneratorService method getIDSBlob.
/**
* Create an IDS file for a pen request batch entity
*
* @param penRequestBatchEntity the pen request batch entity
* @return the pen web blob entity
*/
public PENWebBlobEntity getIDSBlob(final PenRequestBatchEntity penRequestBatchEntity, final List<PenRequestBatchStudent> penRequestBatchStudentEntities, final List<Student> students) {
Map<String, Student> studentsMap = students.stream().collect(Collectors.toMap(Student::getStudentID, student -> student));
final List<PenRequestBatchStudent> filteredStudents = penRequestBatchStudentEntities.stream().filter(x -> (x.getPenRequestBatchStudentStatusCode().equals(PenRequestBatchStudentStatusCodes.SYS_NEW_PEN.getCode()) || x.getPenRequestBatchStudentStatusCode().equals(PenRequestBatchStudentStatusCodes.USR_NEW_PEN.getCode()) || x.getPenRequestBatchStudentStatusCode().equals(PenRequestBatchStudentStatusCodes.SYS_MATCHED.getCode()) || x.getPenRequestBatchStudentStatusCode().equals(PenRequestBatchStudentStatusCodes.USR_MATCHED.getCode())) && x.getLocalID() != null).collect(Collectors.toList());
byte[] bFile;
if (!filteredStudents.isEmpty()) {
final StringBuilder idsFile = new StringBuilder();
for (final PenRequestBatchStudent entity : filteredStudents) {
final var student = studentsMap.get(entity.getStudentID());
if (student != null) {
idsFile.append("E03").append(entity.getMincode()).append(String.format("%-12s", entity.getLocalID())).append(student.getPen()).append(" ").append(String.format("%-25s", student.getLegalLastName())).append("\r\n");
} else {
log.error("StudentId was not found. This should not have happened.");
}
}
bFile = idsFile.toString().getBytes();
} else {
bFile = "No NEW PENS have been assigned by this PEN request".getBytes();
}
return PENWebBlobEntity.builder().mincode(penRequestBatchEntity.getMincode()).sourceApplication(getSourceApplication(penRequestBatchEntity.getSourceApplication())).fileName(penRequestBatchEntity.getMincode() + ".IDS").fileType("IDS").fileContents(bFile).insertDateTime(LocalDateTime.now()).submissionNumber(penRequestBatchEntity.getSubmissionNumber()).build();
}
Aggregations