Search in sources :

Example 41 with Student

use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenRequestBatchRepostReportsOrchestrator method saveReportsWithoutPDF.

private void saveReportsWithoutPDF(Event event, Saga saga, PenRequestBatchRepostReportsFilesSagaData penRequestBatchRepostReportsFilesSagaData) throws IOException, TimeoutException, InterruptedException {
    SagaEvent eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload());
    saga.setSagaState(SAVE_REPORTS.toString());
    List<Student> students = obMapper.readValue(event.getEventPayload(), new TypeReference<>() {
    });
    penRequestBatchRepostReportsFilesSagaData.setStudents(event, students);
    // save the updated payload to DB...
    saga.setPayload(JsonUtil.getJsonStringFromObject(penRequestBatchRepostReportsFilesSagaData));
    this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);
    this.getResponseFileGeneratorService().saveReports(mapper.toModel(penRequestBatchRepostReportsFilesSagaData.getPenRequestBatch()), penRequestBatchRepostReportsFilesSagaData.getPenRequestBatchStudents(), penRequestBatchRepostReportsFilesSagaData.getStudents(), reportMapper.toReportData(penRequestBatchRepostReportsFilesSagaData));
    val nextEvent = Event.builder().sagaId(saga.getSagaId()).eventType(SAVE_REPORTS).eventOutcome(REPORTS_SAVED).build();
    this.handleEvent(nextEvent);
}
Also used : lombok.val(lombok.val) Student(ca.bc.gov.educ.penreg.api.struct.Student) SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent)

Example 42 with Student

use of ca.bc.gov.educ.penreg.api.struct.Student 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.");
}
Also used : EventType(ca.bc.gov.educ.penreg.api.constants.EventType) LocalDateTime(java.time.LocalDateTime) PenRequestBatchStudent(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) StringUtils(org.apache.commons.lang3.StringUtils) PenRequestValidationIssue(ca.bc.gov.educ.penreg.api.struct.PenRequestValidationIssue) REQ_MATCH(ca.bc.gov.educ.penreg.api.constants.StudentHistoryActivityCode.REQ_MATCH) RestUtils(ca.bc.gov.educ.penreg.api.rest.RestUtils) SagaTopicsEnum(ca.bc.gov.educ.penreg.api.constants.SagaTopicsEnum) SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent) USR_MATCHED(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes.USR_MATCHED) PenRequestBatchUserActionsSagaData(ca.bc.gov.educ.penreg.api.struct.PenRequestBatchUserActionsSagaData) lombok.val(lombok.val) PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA(ca.bc.gov.educ.penreg.api.constants.SagaEnum.PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA) SagaService(ca.bc.gov.educ.penreg.api.service.SagaService) EventOutcome(ca.bc.gov.educ.penreg.api.constants.EventOutcome) IN_PROGRESS(ca.bc.gov.educ.penreg.api.constants.SagaStatusEnum.IN_PROGRESS) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) Event(ca.bc.gov.educ.penreg.api.struct.Event) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) Student(ca.bc.gov.educ.penreg.api.struct.Student) TwinReasonCodes(ca.bc.gov.educ.penreg.api.constants.TwinReasonCodes) Saga(ca.bc.gov.educ.penreg.api.model.v1.Saga) CollectionUtils(org.springframework.util.CollectionUtils) PossibleMatch(ca.bc.gov.educ.penreg.api.struct.v1.PossibleMatch) MessagePublisher(ca.bc.gov.educ.penreg.api.messaging.MessagePublisher) SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent) Event(ca.bc.gov.educ.penreg.api.struct.Event) SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent)

Example 43 with Student

use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenRequestBatchReportDataDecorator method toReportData.

/**
 * To pen request batch student entity pen request batch student entity.
 *
 * @param data the saga data
 * @return the pen request batch report data entity
 */
@Override
public PenRequestBatchReportData toReportData(final BasePenRequestBatchReturnFilesSagaData data) {
    final var reportData = this.delegate.toReportData(data);
    final List<ReportListItem> pendingList = new ArrayList<>();
    final List<ReportListItem> newPenList = new ArrayList<>();
    final List<ReportListItem> sysMatchedList = new ArrayList<>();
    final List<ReportUserMatchedListItem> diffList = new ArrayList<>();
    final List<ReportUserMatchedListItem> confirmedList = new ArrayList<>();
    if (data != null && !CollectionUtils.isEmpty(data.getPenRequestBatchStudents())) {
        final Map<String, Student> students = this.setStudents(data.getStudents());
        for (final PenRequestBatchStudent penRequestBatchStudent : data.getPenRequestBatchStudents()) {
            switch(Objects.requireNonNull(PenRequestBatchStudentStatusCodes.valueOfCode(penRequestBatchStudent.getPenRequestBatchStudentStatusCode()))) {
                case DUPLICATE:
                case ERROR:
                case REPEAT:
                case INFOREQ:
                case FIXABLE:
                    val issues = data.getPenRequestBatchStudentValidationIssues().get(penRequestBatchStudent.getPenRequestBatchStudentID());
                    val pendingItem = listItemMapper.toReportListItem(penRequestBatchStudent, issues);
                    if (!"Duplicate".equals(pendingItem.getPen())) {
                        pendingItem.setPen("Pending");
                    }
                    pendingList.add(pendingItem);
                    break;
                case SYS_NEW_PEN:
                case USR_NEW_PEN:
                    this.populateForNewPenStatus(newPenList, students, penRequestBatchStudent);
                    break;
                case SYS_MATCHED:
                    this.populateForSystemMatchedStatus(sysMatchedList, diffList, students, penRequestBatchStudent);
                    break;
                case USR_MATCHED:
                    this.populateForUserMatchedStatus(sysMatchedList, diffList, students, penRequestBatchStudent);
                    break;
                default:
                    log.error("Unexpected pen request batch student status code encountered while attempting generate report data :: " + penRequestBatchStudent.getPenRequestBatchStudentStatusCode());
                    break;
            }
        }
        val processDateTime = data.getPenRequestBatch() == null || data.getPenRequestBatch().getProcessDate() == null ? LocalDateTime.now() : LocalDateTime.parse(data.getPenRequestBatch().getProcessDate());
        reportData.setProcessDate(processDateTime.format(DateTimeFormatter.ofPattern("yyyy/MM/dd")));
        reportData.setProcessTime(processDateTime.format(DateTimeFormatter.ofPattern("HH:mm")));
        reportData.setReportDate(processDateTime.format(DateTimeFormatter.ofPattern("yyyy-MMM-dd")).toUpperCase().replace(".", ""));
        reportData.setReviewer(this.setReviewer(data.getPenCoordinator()));
    }
    reportData.setSysMatchedList(sysMatchedList);
    reportData.setPendingList(pendingList);
    reportData.setNewPenList(newPenList);
    reportData.setDiffList(diffList);
    reportData.setConfirmedList(confirmedList);
    return reportData;
}
Also used : lombok.val(lombok.val) ReportUserMatchedListItem(ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.ReportUserMatchedListItem) ReportListItem(ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.ReportListItem) 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)

Example 44 with Student

use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenRequestBatchResultDataDecorator method toResult.

@Override
public PenRequestBatchSubmissionResult toResult(final PenRequestBatchEntity penRequestBatch, final Map<String, Student> studentMap) {
    final var requestBatchSubmissionResult = this.delegate.toResult(penRequestBatch, studentMap);
    final List<ListItem> pendingList = new ArrayList<>();
    final List<ListItem> newPenAssignedList = new ArrayList<>();
    final List<ListItem> exactMatchList = new ArrayList<>();
    final List<SchoolMinListItem> differencesList = new ArrayList<>();
    final List<SchoolMinListItem> confirmedList = new ArrayList<>();
    for (final PenRequestBatchStudentEntity penRequestBatchStudent : penRequestBatch.getPenRequestBatchStudentEntities()) {
        switch(Objects.requireNonNull(PenRequestBatchStudentStatusCodes.valueOfCode(penRequestBatchStudent.getPenRequestBatchStudentStatusCode()))) {
            case DUPLICATE:
            case ERROR:
            case REPEAT:
            case INFOREQ:
            case FIXABLE:
                val fixableItem = listItemMapper.toListItem(penRequestBatchStudent);
                fixableItem.setValidationIssues(penRequestBatchStudent.getPenRequestBatchStudentValidationIssueEntities().stream().filter(validationResult -> "ERROR".equals(validationResult.getPenRequestBatchValidationIssueSeverityCode())).map(PenRequestBatchStudentValidationIssueMapper.mapper::toStruct).collect(Collectors.toList()));
                pendingList.add(fixableItem);
                break;
            case SYS_NEW_PEN:
            case USR_NEW_PEN:
                populateForNewPenStatus(studentMap, newPenAssignedList, penRequestBatchStudent);
                break;
            case SYS_MATCHED:
                this.populateForSystemMatchedStatus(exactMatchList, differencesList, studentMap, penRequestBatchStudent);
                break;
            case USR_MATCHED:
                populateForUserMatchedStatus(studentMap, differencesList, penRequestBatchStudent);
                break;
            default:
                log.error("Unexpected pen request batch student error code encountered while attempting generate PenRequestBatchSubmissionResult data :: " + penRequestBatchStudent.getPenRequestBatchStudentStatusCode());
                break;
        }
    }
    requestBatchSubmissionResult.setPendingList(pendingList);
    requestBatchSubmissionResult.setConfirmedList(confirmedList);
    requestBatchSubmissionResult.setDifferencesList(differencesList);
    requestBatchSubmissionResult.setExactMatchList(exactMatchList);
    requestBatchSubmissionResult.setNewPenAssignedList(newPenAssignedList);
    return requestBatchSubmissionResult;
}
Also used : lombok.val(lombok.val) ListItem(ca.bc.gov.educ.penreg.api.struct.v1.external.ListItem) PenRequestBatchStudentStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes) PenRequestBatchStudentMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchStudentMapper) StudentDemogCode(ca.bc.gov.educ.penreg.api.constants.StudentDemogCode) lombok.val(lombok.val) PenRequestBatchStudentValidationIssueMapper(ca.bc.gov.educ.penreg.api.mappers.PenRequestBatchStudentValidationIssueMapper) SchoolMinListItem(ca.bc.gov.educ.penreg.api.struct.v1.external.SchoolMinListItem) Collectors(java.util.stream.Collectors) PenRegBatchHelper(ca.bc.gov.educ.penreg.api.helpers.PenRegBatchHelper) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Student(ca.bc.gov.educ.penreg.api.struct.Student) Map(java.util.Map) PenRequestBatchSubmissionResult(ca.bc.gov.educ.penreg.api.struct.v1.external.PenRequestBatchSubmissionResult) ArrayList(java.util.ArrayList) SchoolMinListItem(ca.bc.gov.educ.penreg.api.struct.v1.external.SchoolMinListItem) ListItem(ca.bc.gov.educ.penreg.api.struct.v1.external.ListItem) SchoolMinListItem(ca.bc.gov.educ.penreg.api.struct.v1.external.SchoolMinListItem) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity)

Aggregations

Student (ca.bc.gov.educ.penreg.api.struct.Student)44 Test (org.junit.Test)26 lombok.val (lombok.val)24 Event (ca.bc.gov.educ.penreg.api.struct.Event)17 PenRequestBatchStudent (ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent)16 LocalDateTime (java.time.LocalDateTime)14 Collectors (java.util.stream.Collectors)14 PenRequestBatchEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity)13 RestUtils (ca.bc.gov.educ.penreg.api.rest.RestUtils)13 JsonUtil (ca.bc.gov.educ.penreg.api.util.JsonUtil)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 BasePenRegAPITest (ca.bc.gov.educ.penreg.api.BasePenRegAPITest)12 PenRequestBatchStudentEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity)12 SagaEvent (ca.bc.gov.educ.penreg.api.model.v1.SagaEvent)12 SagaService (ca.bc.gov.educ.penreg.api.service.SagaService)12 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 EventOutcome (ca.bc.gov.educ.penreg.api.constants.EventOutcome)11 PenRequestBatchStudentStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes)11 PenMatchRecord (ca.bc.gov.educ.penreg.api.struct.PenMatchRecord)11 PenMatchResult (ca.bc.gov.educ.penreg.api.struct.PenMatchResult)11