Skip to content

Commit

Permalink
Merge pull request #306 from bcgov/feature/schoolDerek
Browse files Browse the repository at this point in the history
Upgrading to allow list of student registration contacts
  • Loading branch information
SoLetsDev committed Feb 22, 2024
2 parents 749edd7 + a3be92f commit 61f73e3
Show file tree
Hide file tree
Showing 37 changed files with 640 additions and 8,436 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<version>0.8.8</version>
</plugin>
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import ca.bc.gov.educ.penreg.api.properties.ApplicationProperties;
import ca.bc.gov.educ.penreg.api.rest.RestUtils;
import ca.bc.gov.educ.penreg.api.service.NotificationService;
import ca.bc.gov.educ.penreg.api.service.PenCoordinatorService;
import ca.bc.gov.educ.penreg.api.service.StudentRegistrationContactService;
import ca.bc.gov.educ.penreg.api.struct.School;
import com.google.common.base.Stopwatch;
import lombok.Getter;
Expand All @@ -36,7 +36,6 @@

import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -95,9 +94,9 @@ public class PenRegBatchProcessor {
*/
private final NotificationService notificationService;
/**
* The Pen coordinator service.
* The Student Registration Contact service.
*/
private final PenCoordinatorService penCoordinatorService;
private final StudentRegistrationContactService studentRegistrationContactService;

/**
* The Duplicate file check service map.
Expand All @@ -115,17 +114,17 @@ public class PenRegBatchProcessor {
* @param penRequestBatchFileService the pen request batch file service
* @param applicationProperties the application properties
* @param notificationService the notification service
* @param penCoordinatorService the pen coordinator service
* @param studentRegistrationContactService the student registration contact service
* @param duplicateFileCheckServiceList the duplicate file check service list
* @param penRequestBatchFileValidator the pen request batch file validator
*/
@Autowired
public PenRegBatchProcessor(final PenRegBatchStudentRecordsProcessor penRegBatchStudentRecordsProcessor, final PenRequestBatchFileService penRequestBatchFileService, final ApplicationProperties applicationProperties, final NotificationService notificationService, final PenCoordinatorService penCoordinatorService, final List<DuplicateFileCheckService> duplicateFileCheckServiceList, final PenRequestBatchFileValidator penRequestBatchFileValidator, final RestUtils restUtils) {
public PenRegBatchProcessor(final PenRegBatchStudentRecordsProcessor penRegBatchStudentRecordsProcessor, final PenRequestBatchFileService penRequestBatchFileService, final ApplicationProperties applicationProperties, final NotificationService notificationService, final StudentRegistrationContactService studentRegistrationContactService, final List<DuplicateFileCheckService> duplicateFileCheckServiceList, final PenRequestBatchFileValidator penRequestBatchFileValidator, final RestUtils restUtils) {
this.penRegBatchStudentRecordsProcessor = penRegBatchStudentRecordsProcessor;
this.penRequestBatchFileService = penRequestBatchFileService;
this.applicationProperties = applicationProperties;
this.notificationService = notificationService;
this.penCoordinatorService = penCoordinatorService;
this.studentRegistrationContactService = studentRegistrationContactService;
this.duplicateFileCheckServiceMap = duplicateFileCheckServiceList.stream().collect(Collectors.toMap(DuplicateFileCheckService::getSchoolGroupCode, Function.identity()));
this.penRequestBatchFileValidator = penRequestBatchFileValidator;
this.restUtils = restUtils;
Expand Down Expand Up @@ -220,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> school = this.restUtils.getSchoolByMincode(penWebBlobEntity.getMincode());
school.ifPresent(value -> entity.setSchoolName(value.getSchoolName()));
school.ifPresent(value -> entity.setSchoolName(value.getDisplayName()));
//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());
Expand Down Expand Up @@ -272,10 +271,10 @@ private Optional<CompletableFuture<Boolean>> notifySchoolForFileFormatErrors(fin
Optional<CompletableFuture<Boolean>> 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 studentRegistrationContactList = this.studentRegistrationContactService.getStudentRegistrationContactEmailsByMincode(penWebBlobEntity.getMincode());
if (!studentRegistrationContactList.isEmpty()) {
log.info("student registration school contact email(s) found :: {}, for guid :: {}", studentRegistrationContactList, guid);
isSchoolNotifiedFutureOptional = Optional.ofNullable(this.notificationService.notifySchoolForLoadFailed(guid, penWebBlobEntity.getFileName(), penWebBlobEntity.getSubmissionNumber(), fileUnProcessableException.getReason(), studentRegistrationContactList));
}
}
return isSchoolNotifiedFutureOptional;
Expand Down Expand Up @@ -311,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> school = this.restUtils.getSchoolByMincode(penWebBlobEntity.getMincode());
school.ifPresent(value -> entity.setSchoolName(value.getSchoolName()));
school.ifPresent(value -> entity.setSchoolName(value.getDisplayName()));
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++);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()));
}


Expand Down Expand Up @@ -147,8 +145,8 @@ private void addToSysMatchOrDiffList(final List<ReportListItem> sysMatchedList,
}


private String setReviewer(final PenCoordinator penCoordinator) {
return (penCoordinator != null && StringUtils.isNotBlank(penCoordinator.getPenCoordinatorName())) ? penCoordinator.getPenCoordinatorName() : "School PEN Coordinator";
private String setReviewer(final List<SchoolContact> studentRegistrationContacts) { //If there is more than one school registration contact we just use the first one.
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<String, Student> setStudents(final List<Student> students) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 61f73e3

Please sign in to comment.