diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessor.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessor.java index 37f5b402..d79f2860 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessor.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessor.java @@ -219,7 +219,7 @@ private void processFileUnProcessableException(@NonNull final String guid, @NonN val notifySchoolForFileFormatErrorsOptional = this.notifySchoolForFileFormatErrors(guid, penWebBlobEntity, fileUnProcessableException); final PenRequestBatchEntity entity = mapper.toPenReqBatchEntityForBusinessException(penWebBlobEntity, fileUnProcessableException.getReason(), fileUnProcessableException.getPenRequestBatchStatusCode(), batchFile, persistStudentRecords(fileUnProcessableException.getFileError())); // batch file can be processed further and persisted. final Optional school = this.restUtils.getSchoolByMincode(penWebBlobEntity.getMincode()); - school.ifPresent(value -> entity.setSchoolName(value.getSchoolName())); + school.ifPresent(value -> entity.setSchoolName(value.getDisplayNameNoSpecialChars())); //TODO should this be no special characters? //wait here if notification was sent, if there was any error this file will be picked up again as it wont be persisted. if (notifySchoolForFileFormatErrorsOptional.isPresent()) { final boolean isNotified = this.waitForNotificationToCompleteIfPresent(guid, notifySchoolForFileFormatErrorsOptional.get()); @@ -271,10 +271,10 @@ private Optional> notifySchoolForFileFormatErrors(fin Optional> isSchoolNotifiedFutureOptional = Optional.empty(); if (this.isNotificationToSchoolRequired(fileUnProcessableException)) { log.info("notification to school is required :: {}", guid); - val coordinatorEmailOptional = this.penCoordinatorService.getPenCoordinatorEmailByMinCode(penWebBlobEntity.getMincode()); - if (coordinatorEmailOptional.isPresent()) { - log.info("pen coordinator email found :: {}, for guid :: {}", coordinatorEmailOptional.get(), guid); - isSchoolNotifiedFutureOptional = Optional.ofNullable(this.notificationService.notifySchoolForLoadFailed(guid, penWebBlobEntity.getFileName(), penWebBlobEntity.getSubmissionNumber(), fileUnProcessableException.getReason(), coordinatorEmailOptional.get())); + val coordinatorEmailOptional = this.penCoordinatorService.getStudentRegistrationContactEmailsByMincode(penWebBlobEntity.getMincode()); + if (!coordinatorEmailOptional.isEmpty()) { + log.info("pen coordinator email found :: {}, for guid :: {}", coordinatorEmailOptional.stream().toList(), guid); + isSchoolNotifiedFutureOptional = Optional.ofNullable(this.notificationService.notifySchoolForLoadFailed(guid, penWebBlobEntity.getFileName(), penWebBlobEntity.getSubmissionNumber(), fileUnProcessableException.getReason(), coordinatorEmailOptional.stream().toString())); } } return isSchoolNotifiedFutureOptional; @@ -310,7 +310,7 @@ private void processLoadedRecordsInBatchFile(@NonNull final String guid, @NonNul log.info("going to persist data for batch :: {}", guid); final PenRequestBatchEntity entity = mapper.toPenReqBatchEntityLoaded(penWebBlobEntity, batchFile); // batch file can be processed further and persisted. final Optional school = this.restUtils.getSchoolByMincode(penWebBlobEntity.getMincode()); - school.ifPresent(value -> entity.setSchoolName(value.getSchoolName())); + school.ifPresent(value -> entity.setSchoolName(value.getDisplayNameNoSpecialChars())); //TODO check if we need to make sure to have a safe display name for (final var student : batchFile.getStudentDetails()) { // set the object so that PK/FK relationship will be auto established by hibernate. final var penRequestBatchStudentEntity = mapper.toPenRequestBatchStudentEntity(student, entity); penRequestBatchStudentEntity.setRecordNumber(counter++); diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/batch/validator/PenRequestBatchFileValidator.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/batch/validator/PenRequestBatchFileValidator.java index b6e0a048..91e2a5d7 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/batch/validator/PenRequestBatchFileValidator.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/batch/validator/PenRequestBatchFileValidator.java @@ -162,8 +162,8 @@ public void validateMincode(final String guid, final String mincode) throws File if (school.isEmpty()) { throw new FileUnProcessableException(INVALID_MINCODE_HEADER, guid, PenRequestBatchStatusCodes.LOAD_FAIL); } - final String openedDate = school.get().getDateOpened(); - final String closedDate = school.get().getDateClosed(); + final String openedDate = school.get().getOpenedDate(); + final String closedDate = school.get().getClosedDate(); if (openedDate == null || LocalDate.parse(openedDate, DateTimeFormatter.ISO_LOCAL_DATE_TIME).isAfter(LocalDate.now()) || (closedDate != null && LocalDate.parse(closedDate, DateTimeFormatter.ISO_LOCAL_DATE_TIME).isBefore(LocalDate.now()))) { throw new FileUnProcessableException(INVALID_MINCODE_SCHOOL_CLOSED, guid, PenRequestBatchStatusCodes.LOAD_FAIL); } diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/mappers/v1/PenRequestBatchReportDataDecorator.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/mappers/v1/PenRequestBatchReportDataDecorator.java index f6780b46..68527f18 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/mappers/v1/PenRequestBatchReportDataDecorator.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/mappers/v1/PenRequestBatchReportDataDecorator.java @@ -1,11 +1,9 @@ package ca.bc.gov.educ.penreg.api.mappers.v1; import ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes; -import ca.bc.gov.educ.penreg.api.constants.StudentDemogCode; import ca.bc.gov.educ.penreg.api.helpers.PenRegBatchHelper; -import ca.bc.gov.educ.penreg.api.struct.Student; +import ca.bc.gov.educ.penreg.api.struct.*; import ca.bc.gov.educ.penreg.api.struct.v1.BasePenRequestBatchReturnFilesSagaData; -import ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator; import ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent; import ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.PenRequestBatchReportData; import ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.ReportListItem; @@ -83,7 +81,7 @@ public PenRequestBatchReportData toReportData(final BasePenRequestBatchReturnFil 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.setReviewer(this.setReviewer(data.getStudentRegistrationContacts())); //TODO figure out what to do here if we have more than 1 reviewer } @@ -147,8 +145,8 @@ private void addToSysMatchOrDiffList(final List sysMatchedList, } - private String setReviewer(final PenCoordinator penCoordinator) { - return (penCoordinator != null && StringUtils.isNotBlank(penCoordinator.getPenCoordinatorName())) ? penCoordinator.getPenCoordinatorName() : "School PEN Coordinator"; + private String setReviewer(final List studentRegistrationContacts) { //TODO check for potential bug last name could be blank? + return (!studentRegistrationContacts.isEmpty() && StringUtils.isNotBlank(studentRegistrationContacts.get(0).getFirstName() + " " + studentRegistrationContacts.get(0).getLastName())) ? studentRegistrationContacts.get(0).getFirstName() + " " + studentRegistrationContacts.get(0).getLastName() : "School PEN Coordinator"; } private Map setStudents(final List students) { diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/mappers/v1/PenRequestBatchReportDataMapper.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/mappers/v1/PenRequestBatchReportDataMapper.java index 1e179183..5f0350f0 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/mappers/v1/PenRequestBatchReportDataMapper.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/mappers/v1/PenRequestBatchReportDataMapper.java @@ -22,7 +22,6 @@ public interface PenRequestBatchReportDataMapper { @Mapping(target = "penCordinatorEmail", source = "fromEmail") @Mapping(target = "mincode", expression = "java(data.getPenRequestBatch() == null || data.getPenRequestBatch().getMincode() == null || data.getPenRequestBatch().getMincode().isEmpty() || data.getPenRequestBatch().getMincode().length()<3 ? \"\" : data.getPenRequestBatch().getMincode().substring(0, 3) + \" \" + data.getPenRequestBatch().getMincode().substring(3))") @Mapping(target = "submissionNumber", source = "data.penRequestBatch.submissionNumber") - @Mapping(target = "reviewer", source = "data.penCoordinator.penCoordinatorName") @Mapping(target = "processDate", ignore = true) @Mapping(target = "processTime", ignore = true) @Mapping(target = "reportDate", ignore = true) diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/orchestrator/BaseReturnFilesOrchestrator.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/orchestrator/BaseReturnFilesOrchestrator.java index ab1f0389..44752528 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/orchestrator/BaseReturnFilesOrchestrator.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/orchestrator/BaseReturnFilesOrchestrator.java @@ -14,23 +14,19 @@ import ca.bc.gov.educ.penreg.api.properties.PenCoordinatorProperties; import ca.bc.gov.educ.penreg.api.rest.RestUtils; import ca.bc.gov.educ.penreg.api.service.*; -import ca.bc.gov.educ.penreg.api.struct.Event; -import ca.bc.gov.educ.penreg.api.struct.Student; +import ca.bc.gov.educ.penreg.api.struct.*; import ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudentValidationIssueTypeCode; import ca.bc.gov.educ.penreg.api.struct.v1.*; import ca.bc.gov.educ.penreg.api.util.JsonUtil; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.*; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import lombok.val; import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; @@ -110,7 +106,8 @@ protected void gatherReportData(final Event event, final Saga saga, final BasePe final List studentRequests = penRequestBatch.get().getPenRequestBatchStudentEntities().stream().map(studentMapper::toStructure).collect(Collectors.toList()); penRequestBatchReturnFilesSagaData.setPenRequestBatchStudents(studentRequests); penRequestBatchReturnFilesSagaData.setPenRequestBatch(mapper.toStructure(penRequestBatch.get())); - penRequestBatchReturnFilesSagaData.setPenCoordinator(this.getPenCoordinator(penRequestBatch.get())); +// penRequestBatchReturnFilesSagaData.setPenCoordinator(this.getPenCoordinator(penRequestBatch.get())); + penRequestBatchReturnFilesSagaData.setStudentRegistrationContacts(this.getPenCoordinator(penRequestBatch.get())); penRequestBatchReturnFilesSagaData.setFromEmail(this.penCoordinatorProperties.getFromEmail()); penRequestBatchReturnFilesSagaData.setTelephone(this.penCoordinatorProperties.getTelephone()); penRequestBatchReturnFilesSagaData.setFacsimile(this.penCoordinatorProperties.getFacsimile()); @@ -232,10 +229,10 @@ protected void sendArchivedEmail(final Event event, final Saga saga, final BaseP //set toEmail and email type depending on whether a penCoordinator exists for the mincode if (eventType.equals(NOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_NO_SCHOOL_CONTACT)) { nextEvent.setEventType(NOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_NO_SCHOOL_CONTACT); - penRequestBatchArchivedEmailEvent.setToEmail(this.getPenCoordinatorProperties().getFromEmail()); + penRequestBatchArchivedEmailEvent.setToEmail(new ArrayList<>(List.of(this.getPenCoordinatorProperties().getFromEmail()))); } else { nextEvent.setEventType(NOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT); - penRequestBatchArchivedEmailEvent.setToEmail(penRequestBatchReturnFilesSagaData.getPenCoordinator().getPenCoordinatorEmail()); + penRequestBatchArchivedEmailEvent.setToEmail(penRequestBatchReturnFilesSagaData.getStudentRegistrationContacts().stream().map(SchoolContact::getEmail).toList()); } nextEvent.setEventPayload(JsonUtil.getJsonStringFromObject(penRequestBatchArchivedEmailEvent)); @@ -261,9 +258,7 @@ protected boolean hasPenCoordinatorEmail(final BasePenRequestBatchReturnFilesSag } protected boolean hasNoPenCoordinatorEmail(final BasePenRequestBatchReturnFilesSagaData penRequestBatchReturnFilesSagaData) { - return penRequestBatchReturnFilesSagaData.getPenCoordinator() == null || - penRequestBatchReturnFilesSagaData.getPenCoordinator().getPenCoordinatorEmail() == null || - penRequestBatchReturnFilesSagaData.getPenCoordinator().getPenCoordinatorEmail().isEmpty(); + return penRequestBatchReturnFilesSagaData.getStudentRegistrationContacts().isEmpty(); } protected boolean isSupportingPDFGeneration(final BasePenRequestBatchReturnFilesSagaData penRequestBatchReturnFilesSagaData) { @@ -288,12 +283,14 @@ protected void sendHasCoordinatorEmail(final Event event, final Saga saga, final this.sendArchivedEmail(event, saga, penRequestBatchReturnFilesSagaData, NOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT); } - protected PenCoordinator getPenCoordinator(final PenRequestBatchEntity penRequestBatchEntity) { + protected List getPenCoordinator(final PenRequestBatchEntity penRequestBatchEntity) { try { - final var penCoordinatorOptional = this.getPenCoordinatorService().getPenCoordinatorByMinCode(penRequestBatchEntity.getMincode()); - return penCoordinatorOptional.orElse(null); +// TODO refactor name to getStudentRegistrationContacts + final var penCoordinatorOptional = this.getPenCoordinatorService().getStudentRegistrationContactsByMincode(penRequestBatchEntity.getMincode()); + + return penCoordinatorOptional; } catch (final NullPointerException e) { - log.error("Error while trying to get get pen coordinator. The pen coordinator map is null", e); + log.error("Error while trying to get get pen coordinator. The pen coordinator map is null", e); //TODO check if we still need to check this map return null; } } diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java index 068ecf67..a42fcab3 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java @@ -400,7 +400,7 @@ public Optional getPenCoordinator(final String mincode) { public List getStudentRegistrationContactList(final String mincode) { try { - var school = schoolMap.get(mincode); + var school = schoolMap.get(mincode); //TODO investigate if this is correct should we throw an exception? if(school == null){ return new ArrayList<>(); } diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/service/ResponseFileGeneratorService.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/service/ResponseFileGeneratorService.java index e7b5babe..b67d041a 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/service/ResponseFileGeneratorService.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/service/ResponseFileGeneratorService.java @@ -8,7 +8,7 @@ import ca.bc.gov.educ.penreg.api.repository.PenRequestBatchStudentRepository; import ca.bc.gov.educ.penreg.api.repository.PenWebBlobRepository; import ca.bc.gov.educ.penreg.api.rest.RestUtils; -import ca.bc.gov.educ.penreg.api.struct.Student; +import ca.bc.gov.educ.penreg.api.struct.*; import ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator; import ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent; import ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.PenRequestBatchReportData; @@ -76,7 +76,7 @@ public class ResponseFileGeneratorService { @Autowired public ResponseFileGeneratorService(final StudentRegistrationContactService penCoordinatorService, final PenWebBlobRepository penWebBlobRepository, final PenRequestBatchStudentRepository penRequestBatchStudentRepository, final RestUtils restUtils, final SpringTemplateEngine templateEngine) { - this.penCoordinatorService = penCoordinatorService; + this.penCoordinatorService = penCoordinatorService; //TODO change this to StudentRegistrationContactService this.penWebBlobRepository = penWebBlobRepository; this.penRequestBatchStudentRepository = penRequestBatchStudentRepository; this.restUtils = restUtils; @@ -140,7 +140,7 @@ public PENWebBlobEntity getIDSBlob(final PenRequestBatchEntity penRequestBatchEn public PENWebBlobEntity getTxtBlob(final PenRequestBatchEntity penRequestBatchEntity, final List penRequestBatchStudentEntities) { final List filteredStudents = penRequestBatchStudentEntities.stream().filter(x -> - (x.getPenRequestBatchStudentStatusCode().equals(PenRequestBatchStudentStatusCodes.ERROR.getCode()))).collect(Collectors.toList()); + (x.getPenRequestBatchStudentStatusCode().equals(PenRequestBatchStudentStatusCodes.ERROR.getCode()))).toList(); byte[] bFile; @@ -258,15 +258,17 @@ private void saveReports(final List reports, PenRequestBatchEn private String createHeader(final PenRequestBatchEntity penRequestBatchEntity, String applicationCode) { final StringBuilder header = new StringBuilder(); // retrieved from PEN_COORDINATOR table - Optional penCoordinator = this.getPenCoordinatorService().getPenCoordinatorByMinCode(penRequestBatchEntity.getMincode()); + List penCoordinator = this.getPenCoordinatorService().getStudentRegistrationContactsByMincode(penRequestBatchEntity.getMincode()); + //TODO check how this header can accept multiple registration contacts? header.append("FFI") .append(String.format("%-8.8s", print(penRequestBatchEntity.getMincode()))) .append(String.format("%-40.40s", print(penRequestBatchEntity.getSchoolName()))) .append(String.format("%-8.8s", penRequestBatchEntity.getProcessDate().format(DateTimeFormatter.ofPattern("yyyyMMdd")))) - .append(String.format("%-100.100s", print(penCoordinator.isPresent()? penCoordinator.get().getPenCoordinatorEmail() : ""))) - .append(String.format("%-10.10s", print(penCoordinator.map(coordinator -> coordinator.getPenCoordinatorFax().replaceAll("[^0-9]+", "")).orElse("")))) - .append(String.format("%-40.40s", print(penCoordinator.isPresent()? penCoordinator.get().getPenCoordinatorName() : ""))) + .append(String.format("%-100.100s", print(!penCoordinator.isEmpty() ? penCoordinator.get(0).getEmail() : ""))) +// .append(String.format("%-10.10s", print(penCoordinator.map(coordinator -> coordinator.getPenCoordinatorFax().replaceAll("[^0-9]+", "")).orElse("")))) //TODO SchoolContact doesn't have a FAX number + .append(String.format("%-10.10s", print(!penCoordinator.isEmpty() ? penCoordinator.get(0).getPhoneNumber() : ""))) //TODO SchoolContact doesn't have a FAX number + .append(String.format("%-40.40s", print(!penCoordinator.isEmpty()? penCoordinator.get(0).getFirstName() : ""))) .append(" ") .append(String.format("%-4.4s", print(applicationCode))) .append("\n"); @@ -310,13 +312,16 @@ private String createBody(final PenRequestBatchStudent penRequestBatchStudentEnt return body.toString(); } - private String getApplicationCode(String mincode) { + private String getApplicationCode(String mincode) { //TODO How are we going to handle schools that have been moved. We cache the schools. var applicationCode = "PEN"; var school = this.restUtils.getSchoolByMincode(mincode). orElseThrow(() -> new PenRegAPIRuntimeException("Cannot find the school data by mincode :: " + mincode)); - if(school.getDistNo().equals("104")) { + + String districtNumber = school.getMincode().substring(0,3); + + if(districtNumber.equals("104")) { applicationCode = "MISC"; - } else if(school.getDistNo().equals("102") && school.getSchlNo().equals("00030")) { + } else if(districtNumber.equals("102") && school.getSchoolNumber().equals("00030")) { applicationCode = "SFAS"; } else if(school.getFacilityTypeCode().equals("12")) { applicationCode = "SS"; diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/service/StudentRegistrationContactService.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/service/StudentRegistrationContactService.java index 0d83d014..d93b009e 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/service/StudentRegistrationContactService.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/service/StudentRegistrationContactService.java @@ -21,7 +21,8 @@ public StudentRegistrationContactService(final RestUtils restUtils) { } public List getStudentRegistrationContactsByMincode(final String mincode) { - if (StringUtils.length(mincode) != 8 || !StringUtils.isNumeric(mincode)) { + if (StringUtils.length(mincode) != 8 || !StringUtils.isNumeric(mincode)) { //TODO why does this need to check? I guess mincode could be wrong? + log.info("getStudentREgistrationContacsByMincode :: mincode is invalid {} returning empty array list", mincode); return new ArrayList<>(); } @@ -29,8 +30,9 @@ public List getStudentRegistrationContactsByMincode(final String } public List getStudentRegistrationContactEmailsByMincode(final String mincode) { - log.debug("getting pen coordinator email for mincode :: {}", mincode); + log.debug("getting pen coordinator email for mincode :: {}", mincode); //TODO why does this need to check? I guess mincode could be wrong? if (StringUtils.length(mincode) != 8 || !StringUtils.isNumeric(mincode)) { + log.info("getStudentRegistrationContactEmailsByMincode :: mincode is invalid {} returning empty array list", mincode); return new ArrayList<>(); } var contacts = this.restUtils.getStudentRegistrationContactList(mincode); diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/struct/SchoolContact.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/struct/SchoolContact.java index 1ac59318..28de843c 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/struct/SchoolContact.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/struct/SchoolContact.java @@ -1,12 +1,15 @@ package ca.bc.gov.educ.penreg.api.struct; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Data; +import lombok.*; import javax.validation.constraints.*; import java.io.Serializable; @Data +@Builder +@AllArgsConstructor +@NoArgsConstructor @JsonIgnoreProperties(ignoreUnknown = true) public class SchoolContact implements Serializable { /** diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/struct/v1/BasePenRequestBatchReturnFilesSagaData.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/struct/v1/BasePenRequestBatchReturnFilesSagaData.java index 5257219d..1cdb1d90 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/struct/v1/BasePenRequestBatchReturnFilesSagaData.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/struct/v1/BasePenRequestBatchReturnFilesSagaData.java @@ -1,15 +1,12 @@ package ca.bc.gov.educ.penreg.api.struct.v1; -import ca.bc.gov.educ.penreg.api.struct.Event; -import ca.bc.gov.educ.penreg.api.struct.Student; +import ca.bc.gov.educ.penreg.api.struct.*; +import java.util.*; import lombok.*; import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Map; -import java.util.UUID; @Data @SuperBuilder @@ -45,7 +42,16 @@ public void setStudents(Event event, List students) { this.students = students; } Map penRequestBatchStudentValidationIssues; - PenCoordinator penCoordinator; +// PenCoordinator penCoordinator; //TODO change this to a list of SchoolContact + List studentRegistrationContacts; + + //What is happening here + public List getStudentRegistrationContacts() { + if (this.studentRegistrationContacts == null) { + return new ArrayList<>(); + } + return this.studentRegistrationContacts; + } String fromEmail; String telephone; diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/struct/v1/PenRequestBatchArchivedEmailEvent.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/struct/v1/PenRequestBatchArchivedEmailEvent.java index ed35f948..c2c8fd63 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/struct/v1/PenRequestBatchArchivedEmailEvent.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/struct/v1/PenRequestBatchArchivedEmailEvent.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.penreg.api.struct.v1; +import java.util.*; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -11,7 +12,7 @@ @NoArgsConstructor public class PenRequestBatchArchivedEmailEvent { String fromEmail; - String toEmail; + List toEmail; String submissionNumber; String schoolName; String mincode; diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessorTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessorTest.java index 217b31fe..0430adb3 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessorTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessorTest.java @@ -3,7 +3,6 @@ import ca.bc.gov.educ.penreg.api.BasePenRegAPITest; import ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator; import ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes; -import ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes; import ca.bc.gov.educ.penreg.api.messaging.MessagePublisher; import ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity; import ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity; @@ -14,7 +13,6 @@ import ca.bc.gov.educ.penreg.api.rest.RestUtils; import ca.bc.gov.educ.penreg.api.struct.School; import ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator; -import ca.bc.gov.educ.penreg.api.struct.v1.SchoolGroupCode; import ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils; import ca.bc.gov.educ.penreg.api.util.JsonUtil; import com.github.javafaker.Faker; @@ -696,7 +694,7 @@ public void testProcessPenRegBatchFileFromTSW_GivenmincodeInvalid_ShouldCreateRe @Transactional public void testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolCloseDate_ShouldCreateRecordLOADFAILInDB() throws IOException { final School school = this.createMockSchool(); - school.setDateClosed("1996-09-01T00:00:00"); + school.setClosedDate("1996-09-01T00:00:00"); when(this.restUtils.getSchoolByMincode(anyString())).thenReturn(Optional.of(school)); final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_5_K12_OK.txt")).getFile()); final byte[] bFile = Files.readAllBytes(file.toPath()); @@ -724,7 +722,7 @@ public void testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolCloseDate @Transactional public void testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolOpenDate_ShouldCreateRecordLOADFAILInDB() throws IOException { final School school = this.createMockSchool(); - school.setDateOpened("2024-09-01T00:00:00"); + school.setOpenedDate("2024-09-01T00:00:00"); when(this.restUtils.getSchoolByMincode(anyString())).thenReturn(Optional.of(school)); final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_5_K12_OK.txt")).getFile()); final byte[] bFile = Files.readAllBytes(file.toPath()); @@ -752,7 +750,7 @@ public void testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolOpenDate_ @Transactional public void testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolOpenDateFormat_ShouldCreateRecordLOADFAILInDB() throws IOException { final School school = this.createMockSchool(); - school.setDateOpened("88888888"); + school.setOpenedDate("88888888"); when(this.restUtils.getSchoolByMincode(anyString())).thenReturn(Optional.of(school)); final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_5_K12_OK.txt")).getFile()); final byte[] bFile = Files.readAllBytes(file.toPath()); @@ -778,9 +776,9 @@ public void testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolOpenDateF private School createMockSchool() { final School school = new School(); - school.setSchoolName("Marco's school"); + school.setDisplayNameNoSpecialChars("Marco's school"); school.setMincode("66510518"); - school.setDateOpened("1964-09-01T00:00:00"); + school.setOpenedDate("1964-09-01T00:00:00"); return school; } diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/schedulers/PenRegBatchSchedulerTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/schedulers/PenRegBatchSchedulerTest.java index a5dcab70..01f15953 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/schedulers/PenRegBatchSchedulerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/schedulers/PenRegBatchSchedulerTest.java @@ -192,9 +192,9 @@ private void waitForAsyncToFinish() throws InterruptedException { private School createMockSchool() { final School school = new School(); - school.setSchoolName("Marco's school"); + school.setDisplayNameNoSpecialChars("Marco's school"); school.setMincode("66510518"); - school.setDateOpened("1953-09-01T00:00:00"); + school.setOpenedDate("1953-09-01T00:00:00"); return school; } diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/service/PenRequestBatchFileServiceTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/service/PenRequestBatchFileServiceTest.java index fb88f8b0..e82c0898 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/service/PenRequestBatchFileServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/service/PenRequestBatchFileServiceTest.java @@ -107,9 +107,9 @@ public void testFilterDuplicatesAndRepeatRequests_givenSFASFileAndRepeats_should private School createMockSchool() { final School school = new School(); - school.setSchoolName("Marco's school"); + school.setDisplayNameNoSpecialChars("Marco's school"); school.setMincode("66510518"); - school.setDateOpened("1964-09-01T00:00:00"); + school.setOpenedDate("1964-09-01T00:00:00"); return school; } } diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/mapper/v1/PenRequestBatchReportDataMapperTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/mapper/v1/PenRequestBatchReportDataMapperTest.java index 7c3d384a..7eeee130 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/mapper/v1/PenRequestBatchReportDataMapperTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/mapper/v1/PenRequestBatchReportDataMapperTest.java @@ -5,19 +5,16 @@ import ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchReportDataMapper; import ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchStudentMapper; import ca.bc.gov.educ.penreg.api.repository.PenRequestBatchRepository; -import ca.bc.gov.educ.penreg.api.struct.Student; -import ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator; +import ca.bc.gov.educ.penreg.api.struct.*; import ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchArchiveAndReturnSagaData; import ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.PenRequestBatchReportData; import ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils; +import java.util.*; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; @@ -46,7 +43,7 @@ public void testToReportUserMatchedListItem_GivenAllValues_ShouldMapSuccessfully .telephone("5555555555") .fromEmail("test@abc.com") .mailingAddress("mailing address") - .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("test@email.com").penCoordinatorName("Joe Blow").build()) + .studentRegistrationContacts(Collections.singletonList(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build())) .schoolName("Cataline") .penRequestBatch(mapper.toStructure(batchEntities.get(0))) .penRequestBatchStudents(batchEntities.get(0).getPenRequestBatchStudentEntities().stream().map(studentMapper::toStructure).collect(Collectors.toList())) @@ -107,7 +104,7 @@ public void testToReportUserMatchedListItem_GivenBadDOB_ShouldMapSuccessfully() .telephone("5555555555") .fromEmail("test@abc.com") .mailingAddress("mailing address") - .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("test@email.com").penCoordinatorName("Joe Blow").build()) + .studentRegistrationContacts(Collections.singletonList(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build())) .schoolName("Cataline") .penRequestBatch(mapper.toStructure(batchEntities.get(0))) .penRequestBatchStudents(batchEntities.get(0).getPenRequestBatchStudentEntities().stream().map(studentMapper::toStructure).collect(Collectors.toList())) @@ -133,7 +130,7 @@ public void testToReportUserMatchedListItem_GivenNullStudent_ShouldNotThrowError .fromEmail("test@abc.com") .mailingAddress("mailing address") .students(students) - .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("test@email.com").penCoordinatorName("Joe Blow").build()) + .studentRegistrationContacts(Collections.singletonList(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build())) .schoolName("Cataline") .penRequestBatch(mapper.toStructure(batchEntities.get(0))) .penRequestBatchStudents(batchEntities.get(0).getPenRequestBatchStudentEntities().stream().map(studentMapper::toStructure).collect(Collectors.toList())) diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/orchestrator/PenRequestBatchArchiveAndReturnOrchestratorTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/orchestrator/PenRequestBatchArchiveAndReturnOrchestratorTest.java index 6e860d9b..2ab7b6ce 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/orchestrator/PenRequestBatchArchiveAndReturnOrchestratorTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/orchestrator/PenRequestBatchArchiveAndReturnOrchestratorTest.java @@ -13,8 +13,7 @@ import ca.bc.gov.educ.penreg.api.rest.RestUtils; import ca.bc.gov.educ.penreg.api.service.PenRequestBatchService; import ca.bc.gov.educ.penreg.api.service.SagaService; -import ca.bc.gov.educ.penreg.api.struct.Event; -import ca.bc.gov.educ.penreg.api.struct.Student; +import ca.bc.gov.educ.penreg.api.struct.*; import ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator; import ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchArchiveAndReturnSagaData; import ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudentValidationIssueFieldCode; @@ -23,6 +22,7 @@ import ca.bc.gov.educ.penreg.api.util.JsonUtil; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.*; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -33,10 +33,6 @@ import java.io.File; import java.io.IOException; -import java.util.Base64; -import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; @@ -309,15 +305,13 @@ public class PenRequestBatchArchiveAndReturnOrchestratorTest extends BaseOrchest " \"0a611b42-7a40-1860-817a-445d42dc007b\": \"Field value is on the list of blocked names, that are either flagged as an error or warning\",\n" + " \"0a611b42-7a40-1860-817a-445d42dc0076\": \"Field value is on the list of blocked names, that are either flagged as an error or warning\"\n" + " },\n" + - " \"penCoordinator\": {\n" + - " \"districtNumber\": 103,\n" + - " \"schoolNumber\": 96672,\n" + - " \"mincode\": \"10396672\",\n" + - " \"penCoordinatorName\": \"Aditya Sharma\",\n" + - " \"penCoordinatorEmail\": \"aditya.sharma@gov.bc.ca\",\n" + - " \"penCoordinatorFax\": \"6046756911\",\n" + - " \"sendPenResultsVia\": \"E\"\n" + - " },\n" + + " \"studentRegistrationContacts\": [\n" + + " {\n" + + " \"firstName\": \"Aditya Sharma\",\n" + + " \"email\": \"aditya.sharma@gov.bc.ca\",\n" + + " \"phoneNumber\": \"6046756911\"\n" + + " }\n" + + " ],\n" + " \"fromEmail\": \"aditya.sharma@gov.bc.ca\",\n" + " \"telephone\": \"(250)356-8020\",\n" + " \"facsimile\": \"(250)953-0450\",\n" + @@ -352,7 +346,8 @@ public void setUp() throws Exception { @Test public void testHandleEvent_givenBatchInSagaDataExistsAndErrorStudent_shouldArchivePenRequestBatchAndBeMarkedSTUDENTS_FOUND() throws IOException, InterruptedException, TimeoutException { - when(this.restUtils.getPenCoordinator(anyString())).thenReturn(Optional.of(PenCoordinator.builder().penCoordinatorEmail("test@test.com").penCoordinatorName("Joe Blow").build())); + when(this.restUtils.getStudentRegistrationContactList(anyString())).thenReturn( + Collections.singletonList(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build())); final String errorDescription = "Invalid chars"; when(this.restUtils.getPenRequestBatchStudentValidationIssueTypeCodeInfoByIssueTypeCode(anyString())). thenReturn(Optional.of(PenRequestBatchStudentValidationIssueTypeCode.builder().code(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentValidationIssueTypeCode.INV_CHARS.getCode()) @@ -385,8 +380,9 @@ public void testHandleEvent_givenBatchInSagaDataExistsAndErrorStudent_shouldArch assertThat(payload.getFromEmail()).isNotEmpty(); assertThat(payload.getTelephone()).isNotEmpty(); assertThat(payload.getMailingAddress()).isNotEmpty(); - assertThat(payload.getPenCoordinator().getPenCoordinatorEmail()).isNotEmpty(); - assertThat(payload.getPenCoordinator().getPenCoordinatorName()).isNotEmpty(); + assertThat(payload.getStudentRegistrationContacts()).hasSize(1); //TODO tighten this up to also include the names? + assertThat(payload.getStudentRegistrationContacts().get(0).getEmail()).isEqualTo("pen@email.com"); + assertThat(payload.getStudentRegistrationContacts().get(0).getFirstName()).isEqualTo("Joe"); assertThat(payload.getPenRequestBatchStudents()).isNotEmpty(); assertThat(payload.getPenRequestBatch()).isNotNull(); assertThat(payload.getPenRequestBatchStudentValidationIssues()).containsValue(errorFieldDescription + " - " + errorDescription); @@ -418,8 +414,9 @@ public void testHandleEvent_givenBatchInSagaDataExistsAndUsrMtchStudent_shouldAr assertThat(payload.getFromEmail()).isNotEmpty(); assertThat(payload.getTelephone()).isNotEmpty(); assertThat(payload.getMailingAddress()).isNotEmpty(); - assertThat(payload.getPenCoordinator().getPenCoordinatorEmail()).isNotEmpty(); - assertThat(payload.getPenCoordinator().getPenCoordinatorName()).isNotEmpty(); + assertThat(payload.getStudentRegistrationContacts()).isNotEmpty(); +// assertThat(payload.getPenCoordinator().getPenCoordinatorEmail()).isNotEmpty(); +// assertThat(payload.getPenCoordinator().getPenCoordinatorName()).isNotEmpty(); assertThat(payload.getPenRequestBatchStudents()).isNotEmpty(); assertThat(payload.getPenRequestBatch()).isNotNull(); } @@ -448,8 +445,9 @@ public void testHandleEvent_givenBatchInSagaDataExistsAndSysNewPenStudent_should assertThat(payload.getFromEmail()).isNotEmpty(); assertThat(payload.getTelephone()).isNotEmpty(); assertThat(payload.getMailingAddress()).isNotEmpty(); - assertThat(payload.getPenCoordinator().getPenCoordinatorEmail()).isNotEmpty(); - assertThat(payload.getPenCoordinator().getPenCoordinatorName()).isNotEmpty(); + assertThat(payload.getStudentRegistrationContacts()).isNotEmpty(); +// assertThat(payload.getPenCoordinator().getPenCoordinatorEmail()).isNotEmpty(); +// assertThat(payload.getPenCoordinator().getPenCoordinatorName()).isNotEmpty(); assertThat(payload.getPenRequestBatchStudents()).isNotEmpty(); assertThat(payload.getPenRequestBatch()).isNotNull(); } @@ -461,7 +459,7 @@ public void testHandleEvent_givenSTUDENTS_FOUNDEventAndCorrectSagaAndEventData_s final PenRequestBatchArchiveAndReturnSagaData payload = PenRequestBatchArchiveAndReturnSagaData.builder() .penRequestBatch(this.batchMapper.toStructure(penRequestBatchEntity)) .penRequestBatchStudents(penRequestBatchEntity.getPenRequestBatchStudentEntities().stream().map(this.batchStudentMapper::toStructure).collect(Collectors.toList())) - .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) +// .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) .mailingAddress("123 st") .fromEmail("test@email.com") .facsimile("5555555555") @@ -497,7 +495,7 @@ public void testSaveReportsWithoutPDF_givenEventAndSagaDataHasPenCoordinatorEmai PenRequestBatchArchiveAndReturnSagaData payload = PenRequestBatchArchiveAndReturnSagaData.builder() .penRequestBatch(batchMapper.toStructure(penRequestBatchEntity)) .penRequestBatchStudents(penRequestBatchEntity.getPenRequestBatchStudentEntities().stream().map(batchStudentMapper::toStructure).collect(Collectors.toList())) - .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) + .studentRegistrationContacts(Collections.singletonList(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build())) .mailingAddress("123 st") .fromEmail("test@email.com") .facsimile("5555555555") @@ -541,7 +539,7 @@ public void testGeneratePDFReport_givenEventAndSagaDataHasPenCoordinatorEmail_an PenRequestBatchArchiveAndReturnSagaData payload = PenRequestBatchArchiveAndReturnSagaData.builder() .penRequestBatch(batchMapper.toStructure(penRequestBatchEntity)) .penRequestBatchStudents(penRequestBatchEntity.getPenRequestBatchStudentEntities().stream().map(batchStudentMapper::toStructure).collect(Collectors.toList())) - .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) +// .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) .mailingAddress("123 st") .fromEmail("test@email.com") .facsimile("5555555555") @@ -579,7 +577,7 @@ public void testSendHasCoordinatorEmail_givenEventAndSagaDataHasPenCoordinatorEm PenRequestBatchArchiveAndReturnSagaData payload = PenRequestBatchArchiveAndReturnSagaData.builder() .penRequestBatch(batchMapper.toStructure(penRequestBatchEntity)) .penRequestBatchStudents(penRequestBatchEntity.getPenRequestBatchStudentEntities().stream().map(batchStudentMapper::toStructure).collect(Collectors.toList())) - .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) + .studentRegistrationContacts(Collections.singletonList(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build())) .mailingAddress("123 st") .fromEmail("test@email.com") .facsimile("5555555555") diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/orchestrator/PenRequestBatchRepostReportsOrchestratorTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/orchestrator/PenRequestBatchRepostReportsOrchestratorTest.java index c7d7349b..ffe26e18 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/orchestrator/PenRequestBatchRepostReportsOrchestratorTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/orchestrator/PenRequestBatchRepostReportsOrchestratorTest.java @@ -15,14 +15,13 @@ import ca.bc.gov.educ.penreg.api.rest.RestUtils; import ca.bc.gov.educ.penreg.api.service.PenRequestBatchService; import ca.bc.gov.educ.penreg.api.service.SagaService; -import ca.bc.gov.educ.penreg.api.struct.Event; -import ca.bc.gov.educ.penreg.api.struct.Student; -import ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator; +import ca.bc.gov.educ.penreg.api.struct.*; import ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchArchiveAndReturnSagaData; import ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils; import ca.bc.gov.educ.penreg.api.util.JsonUtil; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.*; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -33,10 +32,6 @@ import java.io.File; import java.io.IOException; -import java.util.Base64; -import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; @@ -116,10 +111,15 @@ public void setUp() throws Exception { @Test public void testHandleEvent_givenSTUDENTS_FOUNDEventAndCorrectSagaAndEventData_shouldBeMarkedGENERATE_PEN_REQUEST_BATCH_REPORTS() throws IOException, InterruptedException, TimeoutException { final PenRequestBatchEntity penRequestBatchEntity = penRequestBatchTestUtils.createBatchEntity("19337120", "12345679", PenRequestBatchStudentStatusCodes.SYS_NEW_PEN.getCode(), TEST_PEN); + + List studentRegistrationContacts = new ArrayList<>(); + studentRegistrationContacts.add(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build()); + final PenRequestBatchArchiveAndReturnSagaData payload = PenRequestBatchArchiveAndReturnSagaData.builder() .penRequestBatch(this.batchMapper.toStructure(penRequestBatchEntity)) .penRequestBatchStudents(penRequestBatchEntity.getPenRequestBatchStudentEntities().stream().map(this.batchStudentMapper::toStructure).collect(Collectors.toList())) - .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) +// .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) + .studentRegistrationContacts(studentRegistrationContacts) .mailingAddress("123 st") .fromEmail("test@email.com") .facsimile("5555555555") @@ -152,10 +152,14 @@ public void testHandleEvent_givenSTUDENTS_FOUNDEventAndCorrectSagaAndEventData_s public void testHandleEvent_givenSTUDENTS_FOUNDEventAndCorrectSagaAndEventData_and_SfasBatchFile_shouldBeMarkedNOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT() throws IOException, InterruptedException, TimeoutException { final var invocations = mockingDetails(this.messagePublisher).getInvocations().size(); final PenRequestBatchEntity penRequestBatchEntity = penRequestBatchTestUtils.createBatchEntity("10200030", "12345679", PenRequestBatchStudentStatusCodes.SYS_NEW_PEN.getCode(), TEST_PEN); + + List studentRegistrationContacts = new ArrayList<>(); + studentRegistrationContacts.add(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build()); + final PenRequestBatchArchiveAndReturnSagaData payload = PenRequestBatchArchiveAndReturnSagaData.builder() .penRequestBatch(this.batchMapper.toStructure(penRequestBatchEntity)) .penRequestBatchStudents(penRequestBatchEntity.getPenRequestBatchStudentEntities().stream().map(this.batchStudentMapper::toStructure).collect(Collectors.toList())) - .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) + .studentRegistrationContacts(studentRegistrationContacts) .mailingAddress("123 st") .fromEmail("test@email.com") .facsimile("5555555555") @@ -199,7 +203,8 @@ public void testSendHasCoordinatorEmail_givenEventAndSagaDataHasPenCoordinatorEm PenRequestBatchArchiveAndReturnSagaData payload = PenRequestBatchArchiveAndReturnSagaData.builder() .penRequestBatch(batchMapper.toStructure(penRequestBatchEntity)) .penRequestBatchStudents(penRequestBatchEntity.getPenRequestBatchStudentEntities().stream().map(batchStudentMapper::toStructure).collect(Collectors.toList())) - .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) +// .studentRegistrationContacts(Collections.singletonList(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build())) //TODO figure out what to do with the header file we are just taking the first email. + .studentRegistrationContacts(Arrays.asList(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build(), SchoolContact.builder().email("pen@email2.com").firstName("Joe2").lastName("Blow2").build())) .mailingAddress("123 st") .fromEmail("test@email.com") .facsimile("5555555555") @@ -241,7 +246,7 @@ public void testSendHasCoordinatorEmail_givenEventAndSagaDataHasPenCoordinatorEm PenRequestBatchArchiveAndReturnSagaData payload = PenRequestBatchArchiveAndReturnSagaData.builder() .penRequestBatch(batchMapper.toStructure(penRequestBatchEntity)) .penRequestBatchStudents(penRequestBatchEntity.getPenRequestBatchStudentEntities().stream().map(batchStudentMapper::toStructure).collect(Collectors.toList())) - .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) + .studentRegistrationContacts(Collections.singletonList(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build())) .mailingAddress("123 st") .fromEmail("test@email.com") .facsimile("5555555555") diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java index cf6deae0..cbe0fcef 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java @@ -68,7 +68,8 @@ public class RestUtilsTest { @Before public void setUp() throws Exception { when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(this.applicationProperties.getSchoolApiURL())).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(this.applicationProperties.getSchoolApiURL())).thenReturn(this.requestHeadersMock); //TODO we don't need this anymore + when(this.requestHeadersUriMock.uri(this.applicationProperties.getInstituteApiUrl() + "/school")).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.header(any(), any())).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToFlux(School.class)).thenReturn(Flux.just(createSchoolArray())); @@ -85,7 +86,7 @@ public void setUp() throws Exception { private School[] createSchoolArray() { School[] schools = new School[1]; - schools[0] = School.builder().mincode("10200001").distNo("102").schlNo("00001").build(); + schools[0] = School.builder().mincode("10200001").schoolNumber("00001").build(); return schools; } diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/service/PenCoordinatorServiceTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/service/PenCoordinatorServiceTest.java index f06b601c..7bd6c5ff 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/service/PenCoordinatorServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/service/PenCoordinatorServiceTest.java @@ -2,10 +2,10 @@ import ca.bc.gov.educ.penreg.api.BasePenRegAPITest; import ca.bc.gov.educ.penreg.api.rest.RestUtils; +import ca.bc.gov.educ.penreg.api.struct.*; import ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.val; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -16,9 +16,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Function; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; @@ -28,6 +26,7 @@ public class PenCoordinatorServiceTest extends BasePenRegAPITest { private final Map penCoordinatorMap = new ConcurrentHashMap<>(); + private final Map> studentRegistrationContactMap = new ConcurrentHashMap<>(); @Autowired StudentRegistrationContactService service; @@ -38,29 +37,35 @@ public class PenCoordinatorServiceTest extends BasePenRegAPITest { @Before public void setup() throws IOException { Mockito.reset(restUtils); - final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("mock-pen-coordinator.json")).getFile()); - final List structs = new ObjectMapper().readValue(file, new TypeReference<>() { - }); - penCoordinatorMap.putAll(structs.stream().collect(Collectors.toConcurrentMap(key -> String.valueOf(key.getDistrictNumber()).concat(String.valueOf(key.getSchoolNumber())), Function.identity()))); + final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("mock-student-registration-contact.json")).getFile()); + final List structs = new ObjectMapper().readValue(file, new TypeReference<>() {}); + studentRegistrationContactMap.putAll(structs.stream().collect(Collectors.groupingBy(contact -> contact.getSchoolId()))); } @Test - public void testGetPenCoordinator_givenDifferentInputs_shouldProduceOutput() { - String mincode = "123546789"; - when(this.restUtils.getPenCoordinator(mincode)).thenReturn(Optional.ofNullable(penCoordinatorMap.get(mincode))); - val data = this.service.getPenCoordinatorByMinCode("123546789"); + public void testGetStudentRegistrationContactList_givenDifferentInputs_shouldProduceOutput() { + String mincodeNotExist = "123546789"; + when(this.restUtils.getStudentRegistrationContactList(mincodeNotExist)).thenReturn(studentRegistrationContactMap.get(mincodeNotExist)); + var data = this.service.getStudentRegistrationContactsByMincode(mincodeNotExist); assertThat(data).isEmpty(); - when(this.restUtils.getPenCoordinator("19337120")).thenReturn(Optional.ofNullable(penCoordinatorMap.get("19337120"))); - val dataOptional = this.service.getPenCoordinatorByMinCode("19337120"); - assertThat(dataOptional).isPresent(); + + String mindcodeExists = "12345678"; + when(this.restUtils.getStudentRegistrationContactList(mindcodeExists)).thenReturn(studentRegistrationContactMap.get(mindcodeExists)); + var dataList = this.service.getStudentRegistrationContactEmailsByMincode(mindcodeExists); + assertThat(dataList).hasSize(2); } @Test - public void testGetPenCoordinatorEmail_givenDifferentInputs_shouldProduceOutput() { - when(this.restUtils.getPenCoordinator("19337120")).thenReturn(Optional.ofNullable(penCoordinatorMap.get("19337120"))); - val dataOptional = this.service.getPenCoordinatorEmailByMinCode("19337120"); - assertThat(dataOptional).isPresent(); - assertThat(dataOptional.get()).isEqualTo("jhamberston0@va.gov"); - } + public void testGetStudentRegistrationContactEmailsByMincode_givenDifferentInputs_shouldProduceOutput() { + String mincodeExists = "11111111"; + when(this.restUtils.getStudentRegistrationContactList(mincodeExists)).thenReturn(studentRegistrationContactMap.get(mincodeExists)); + var dataList = this.service.getStudentRegistrationContactEmailsByMincode(mincodeExists); + assertThat(dataList).hasSize(1); + assertThat(dataList.get(0)).isEqualTo("fake@gmail.com"); + String mincodeNotExist = "123546789"; + when(this.restUtils.getStudentRegistrationContactList(mincodeNotExist)).thenReturn(studentRegistrationContactMap.get(mincodeNotExist)); + var dataList2 = this.service.getStudentRegistrationContactEmailsByMincode(mincodeNotExist); + assertThat(dataList2).hasSize(0); + } } diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/service/ResponseFileGeneratorServiceTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/service/ResponseFileGeneratorServiceTest.java index 0d6fa086..2afba8fd 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/service/ResponseFileGeneratorServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/service/ResponseFileGeneratorServiceTest.java @@ -8,11 +8,12 @@ import ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity; import ca.bc.gov.educ.penreg.api.repository.PenRequestBatchRepository; import ca.bc.gov.educ.penreg.api.rest.RestUtils; -import ca.bc.gov.educ.penreg.api.struct.School; +import ca.bc.gov.educ.penreg.api.struct.*; import ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator; import ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchRepostReportsFilesSagaData; import ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.PenRequestBatchReportData; import ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils; +import java.util.*; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -21,9 +22,6 @@ import javax.transaction.Transactional; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Base64; -import java.util.List; -import java.util.Optional; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; @@ -252,6 +250,10 @@ public void testCreateParFile_givenPdfFileData_shouldParFilePenWebBlob() throws private PenRequestBatchReportData getPenRequestBatchReportData(PenRequestBatchEntity batch) { var issues = batch.getPenRequestBatchStudentEntities().stream().filter(student -> student.getPenRequestBatchStudentStatusCode().equals(PenRequestBatchStudentStatusCodes.ERROR.getCode())) .collect(Collectors.toMap(student -> student.getPenRequestBatchStudentID().toString(), student -> "error issue message")); + + List studentRegistrationContacts = new ArrayList<>(); + studentRegistrationContacts.add(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build()); + var sagaData = PenRequestBatchRepostReportsFilesSagaData.builder() .penRequestBatchID(batch.getPenRequestBatchID()) .schoolName(batch.getSchoolName()) @@ -259,7 +261,8 @@ private PenRequestBatchReportData getPenRequestBatchReportData(PenRequestBatchEn .penRequestBatchStudents(batch.getPenRequestBatchStudentEntities().stream().map(batchStudentMapper::toStructure).collect(Collectors.toList())) .penRequestBatchStudentValidationIssues(issues) .students(PenRequestBatchTestUtils.createStudents(batch)) - .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) +// .penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()) + .studentRegistrationContacts(studentRegistrationContacts) .mailingAddress("123 st") .fromEmail("test@email.com") .facsimile("5555555555") @@ -270,12 +273,11 @@ private PenRequestBatchReportData getPenRequestBatchReportData(PenRequestBatchEn private School createMockSchool(String mincode, String facilityTypeCode) { final School school = new School(); - school.setSchoolName("Marco's school"); + school.setDisplayNameNoSpecialChars("Marco's school"); school.setMincode(mincode); - school.setDateOpened("1964-09-01T00:00:00"); - school.setDistNo(mincode.substring(0, 3)); - school.setSchlNo(mincode.substring(3)); + school.setOpenedDate("1964-09-01T00:00:00"); school.setFacilityTypeCode(facilityTypeCode); + school.setSchoolNumber(mincode.substring(3)); return school; } diff --git a/api/src/test/resources/application.properties b/api/src/test/resources/application.properties index ff710089..648e97e6 100644 --- a/api/src/test/resources/application.properties +++ b/api/src/test/resources/application.properties @@ -39,6 +39,7 @@ url.token=http://abcxyz.com url.api.student=http://abcxyz.com url.api.pen.services=http://abcxyz.com url.api.school=http://abcxyz.com +url.api.institute=http://abcxyz.com repeat.time.window=60 repeat.time.window.psi=366 repeat.time.window.k12=60 diff --git a/api/src/test/resources/mock-student-registration-contact.json b/api/src/test/resources/mock-student-registration-contact.json new file mode 100644 index 00000000..9ccf4226 --- /dev/null +++ b/api/src/test/resources/mock-student-registration-contact.json @@ -0,0 +1,28 @@ + + [ + { + "schoolId": "12345678", + "schoolContactTypeCode": "STUDREGIS", + "phoneNumber": "1112223333", + "email": "fake@gmail.com", + "firstName": "Joe", + "lastName": "Blow" + }, + { + "schoolId": "12345678", + "schoolContactTypeCode": "STUDREGIS", + "phoneNumber": "1112223333", + "email": "fake@gmail.com", + "firstName": "Joe2", + "lastName": "Blow2" + }, + { + "schoolId": "11111111", + "schoolContactTypeCode": "STUDREGIS", + "phoneNumber": "1112223333", + "email": "fake@gmail.com", + "firstName": "Joe3", + "lastName": "Blow3" + } + ] +