Search in sources :

Example 1 with PenRequestBatchStudent

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);
}
Also used : lombok.val(lombok.val) SchoolMinListItem(ca.bc.gov.educ.penreg.api.struct.v1.external.SchoolMinListItem)

Example 2 with PenRequestBatchStudent

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);
    }
}
Also used : lombok.val(lombok.val) SchoolMinListItem(ca.bc.gov.educ.penreg.api.struct.v1.external.SchoolMinListItem)

Example 3 with PenRequestBatchStudent

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());
}
Also used : SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent) Event(ca.bc.gov.educ.penreg.api.struct.Event) PenRequestBatchStudent(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent) SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent)

Example 4 with PenRequestBatchStudent

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());
}
Also used : lombok.val(lombok.val) PenRegAPIRuntimeException(ca.bc.gov.educ.penreg.api.exception.PenRegAPIRuntimeException) SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent) Event(ca.bc.gov.educ.penreg.api.struct.Event) PenRequestBatchStudent(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent) Student(ca.bc.gov.educ.penreg.api.struct.Student) PenRequestBatchStudent(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent) SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent)

Example 5 with PenRequestBatchStudent

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();
}
Also used : PenRequestBatchReportData(ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.PenRequestBatchReportData) SpringTemplateEngine(org.thymeleaf.spring5.SpringTemplateEngine) java.util(java.util) Getter(lombok.Getter) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchStudentRepository(ca.bc.gov.educ.penreg.api.repository.PenRequestBatchStudentRepository) PenRequestBatchStudent(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent) StringUtils(org.apache.commons.lang3.StringUtils) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) PENWebBlobEntity(ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) SchoolGroupCodes(ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes) RestUtils(ca.bc.gov.educ.penreg.api.rest.RestUtils) PenCoordinator(ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator) PenRequestBatchStudentStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Slf4j(lombok.extern.slf4j.Slf4j) Student(ca.bc.gov.educ.penreg.api.struct.Student) DateTimeFormatter(java.time.format.DateTimeFormatter) PenWebBlobRepository(ca.bc.gov.educ.penreg.api.repository.PenWebBlobRepository) PenRegAPIRuntimeException(ca.bc.gov.educ.penreg.api.exception.PenRegAPIRuntimeException) Context(org.thymeleaf.context.Context) Transactional(org.springframework.transaction.annotation.Transactional) PRIVATE(lombok.AccessLevel.PRIVATE) PenRequestBatchStudent(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent) Student(ca.bc.gov.educ.penreg.api.struct.Student) PenRequestBatchStudent(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent)

Aggregations

Student (ca.bc.gov.educ.penreg.api.struct.Student)10 PenRequestBatchStudent (ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent)10 lombok.val (lombok.val)5 Test (org.junit.Test)5 PenRequestBatchStudentStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes)3 PenRegAPIRuntimeException (ca.bc.gov.educ.penreg.api.exception.PenRegAPIRuntimeException)3 PenRequestBatchEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity)3 SchoolMinListItem (ca.bc.gov.educ.penreg.api.struct.v1.external.SchoolMinListItem)3 Collectors (java.util.stream.Collectors)3 Slf4j (lombok.extern.slf4j.Slf4j)3 SchoolGroupCodes (ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes)2 PENWebBlobEntity (ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity)2 SagaEvent (ca.bc.gov.educ.penreg.api.model.v1.SagaEvent)2 PenRequestBatchStudentRepository (ca.bc.gov.educ.penreg.api.repository.PenRequestBatchStudentRepository)2 PenWebBlobRepository (ca.bc.gov.educ.penreg.api.repository.PenWebBlobRepository)2 RestUtils (ca.bc.gov.educ.penreg.api.rest.RestUtils)2 Event (ca.bc.gov.educ.penreg.api.struct.Event)2 PenCoordinator (ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator)2 PenRequestBatchReportData (ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.PenRequestBatchReportData)2 StandardCharsets (java.nio.charset.StandardCharsets)2