Skip to content

Commit 61f73e3

Browse files
authored
Merge pull request #306 from bcgov/feature/schoolDerek
Upgrading to allow list of student registration contacts
2 parents 749edd7 + a3be92f commit 61f73e3

37 files changed

+640
-8436
lines changed

api/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272
<plugin>
273273
<groupId>org.jacoco</groupId>
274274
<artifactId>jacoco-maven-plugin</artifactId>
275-
<version>0.8.4</version>
275+
<version>0.8.8</version>
276276
</plugin>
277277
<plugin>
278278
<groupId>org.hibernate.orm.tooling</groupId>

api/src/main/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessor.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import ca.bc.gov.educ.penreg.api.properties.ApplicationProperties;
1919
import ca.bc.gov.educ.penreg.api.rest.RestUtils;
2020
import ca.bc.gov.educ.penreg.api.service.NotificationService;
21-
import ca.bc.gov.educ.penreg.api.service.PenCoordinatorService;
21+
import ca.bc.gov.educ.penreg.api.service.StudentRegistrationContactService;
2222
import ca.bc.gov.educ.penreg.api.struct.School;
2323
import com.google.common.base.Stopwatch;
2424
import lombok.Getter;
@@ -36,7 +36,6 @@
3636

3737
import java.io.*;
3838
import java.nio.charset.Charset;
39-
import java.nio.charset.CharsetDecoder;
4039
import java.util.*;
4140
import java.util.concurrent.CompletableFuture;
4241
import java.util.concurrent.ExecutionException;
@@ -95,9 +94,9 @@ public class PenRegBatchProcessor {
9594
*/
9695
private final NotificationService notificationService;
9796
/**
98-
* The Pen coordinator service.
97+
* The Student Registration Contact service.
9998
*/
100-
private final PenCoordinatorService penCoordinatorService;
99+
private final StudentRegistrationContactService studentRegistrationContactService;
101100

102101
/**
103102
* The Duplicate file check service map.
@@ -115,17 +114,17 @@ public class PenRegBatchProcessor {
115114
* @param penRequestBatchFileService the pen request batch file service
116115
* @param applicationProperties the application properties
117116
* @param notificationService the notification service
118-
* @param penCoordinatorService the pen coordinator service
117+
* @param studentRegistrationContactService the student registration contact service
119118
* @param duplicateFileCheckServiceList the duplicate file check service list
120119
* @param penRequestBatchFileValidator the pen request batch file validator
121120
*/
122121
@Autowired
123-
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) {
122+
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) {
124123
this.penRegBatchStudentRecordsProcessor = penRegBatchStudentRecordsProcessor;
125124
this.penRequestBatchFileService = penRequestBatchFileService;
126125
this.applicationProperties = applicationProperties;
127126
this.notificationService = notificationService;
128-
this.penCoordinatorService = penCoordinatorService;
127+
this.studentRegistrationContactService = studentRegistrationContactService;
129128
this.duplicateFileCheckServiceMap = duplicateFileCheckServiceList.stream().collect(Collectors.toMap(DuplicateFileCheckService::getSchoolGroupCode, Function.identity()));
130129
this.penRequestBatchFileValidator = penRequestBatchFileValidator;
131130
this.restUtils = restUtils;
@@ -220,7 +219,7 @@ private void processFileUnProcessableException(@NonNull final String guid, @NonN
220219
val notifySchoolForFileFormatErrorsOptional = this.notifySchoolForFileFormatErrors(guid, penWebBlobEntity, fileUnProcessableException);
221220
final PenRequestBatchEntity entity = mapper.toPenReqBatchEntityForBusinessException(penWebBlobEntity, fileUnProcessableException.getReason(), fileUnProcessableException.getPenRequestBatchStatusCode(), batchFile, persistStudentRecords(fileUnProcessableException.getFileError())); // batch file can be processed further and persisted.
222221
final Optional<School> school = this.restUtils.getSchoolByMincode(penWebBlobEntity.getMincode());
223-
school.ifPresent(value -> entity.setSchoolName(value.getSchoolName()));
222+
school.ifPresent(value -> entity.setSchoolName(value.getDisplayName()));
224223
//wait here if notification was sent, if there was any error this file will be picked up again as it wont be persisted.
225224
if (notifySchoolForFileFormatErrorsOptional.isPresent()) {
226225
final boolean isNotified = this.waitForNotificationToCompleteIfPresent(guid, notifySchoolForFileFormatErrorsOptional.get());
@@ -272,10 +271,10 @@ private Optional<CompletableFuture<Boolean>> notifySchoolForFileFormatErrors(fin
272271
Optional<CompletableFuture<Boolean>> isSchoolNotifiedFutureOptional = Optional.empty();
273272
if (this.isNotificationToSchoolRequired(fileUnProcessableException)) {
274273
log.info("notification to school is required :: {}", guid);
275-
val coordinatorEmailOptional = this.penCoordinatorService.getPenCoordinatorEmailByMinCode(penWebBlobEntity.getMincode());
276-
if (coordinatorEmailOptional.isPresent()) {
277-
log.info("pen coordinator email found :: {}, for guid :: {}", coordinatorEmailOptional.get(), guid);
278-
isSchoolNotifiedFutureOptional = Optional.ofNullable(this.notificationService.notifySchoolForLoadFailed(guid, penWebBlobEntity.getFileName(), penWebBlobEntity.getSubmissionNumber(), fileUnProcessableException.getReason(), coordinatorEmailOptional.get()));
274+
val studentRegistrationContactList = this.studentRegistrationContactService.getStudentRegistrationContactEmailsByMincode(penWebBlobEntity.getMincode());
275+
if (!studentRegistrationContactList.isEmpty()) {
276+
log.info("student registration school contact email(s) found :: {}, for guid :: {}", studentRegistrationContactList, guid);
277+
isSchoolNotifiedFutureOptional = Optional.ofNullable(this.notificationService.notifySchoolForLoadFailed(guid, penWebBlobEntity.getFileName(), penWebBlobEntity.getSubmissionNumber(), fileUnProcessableException.getReason(), studentRegistrationContactList));
279278
}
280279
}
281280
return isSchoolNotifiedFutureOptional;
@@ -311,7 +310,7 @@ private void processLoadedRecordsInBatchFile(@NonNull final String guid, @NonNul
311310
log.info("going to persist data for batch :: {}", guid);
312311
final PenRequestBatchEntity entity = mapper.toPenReqBatchEntityLoaded(penWebBlobEntity, batchFile); // batch file can be processed further and persisted.
313312
final Optional<School> school = this.restUtils.getSchoolByMincode(penWebBlobEntity.getMincode());
314-
school.ifPresent(value -> entity.setSchoolName(value.getSchoolName()));
313+
school.ifPresent(value -> entity.setSchoolName(value.getDisplayName()));
315314
for (final var student : batchFile.getStudentDetails()) { // set the object so that PK/FK relationship will be auto established by hibernate.
316315
final var penRequestBatchStudentEntity = mapper.toPenRequestBatchStudentEntity(student, entity);
317316
penRequestBatchStudentEntity.setRecordNumber(counter++);

api/src/main/java/ca/bc/gov/educ/penreg/api/batch/validator/PenRequestBatchFileValidator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ public void validateMincode(final String guid, final String mincode) throws File
162162
if (school.isEmpty()) {
163163
throw new FileUnProcessableException(INVALID_MINCODE_HEADER, guid, PenRequestBatchStatusCodes.LOAD_FAIL);
164164
}
165-
final String openedDate = school.get().getDateOpened();
166-
final String closedDate = school.get().getDateClosed();
165+
final String openedDate = school.get().getOpenedDate();
166+
final String closedDate = school.get().getClosedDate();
167167
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()))) {
168168
throw new FileUnProcessableException(INVALID_MINCODE_SCHOOL_CLOSED, guid, PenRequestBatchStatusCodes.LOAD_FAIL);
169169
}

api/src/main/java/ca/bc/gov/educ/penreg/api/mappers/v1/PenRequestBatchReportDataDecorator.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package ca.bc.gov.educ.penreg.api.mappers.v1;
22

33
import ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes;
4-
import ca.bc.gov.educ.penreg.api.constants.StudentDemogCode;
54
import ca.bc.gov.educ.penreg.api.helpers.PenRegBatchHelper;
6-
import ca.bc.gov.educ.penreg.api.struct.Student;
5+
import ca.bc.gov.educ.penreg.api.struct.*;
76
import ca.bc.gov.educ.penreg.api.struct.v1.BasePenRequestBatchReturnFilesSagaData;
8-
import ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator;
97
import ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent;
108
import ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.PenRequestBatchReportData;
119
import ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.ReportListItem;
@@ -83,7 +81,7 @@ public PenRequestBatchReportData toReportData(final BasePenRequestBatchReturnFil
8381
reportData.setProcessDate(processDateTime.format(DateTimeFormatter.ofPattern("yyyy/MM/dd")));
8482
reportData.setProcessTime(processDateTime.format(DateTimeFormatter.ofPattern("HH:mm")));
8583
reportData.setReportDate(processDateTime.format(DateTimeFormatter.ofPattern("yyyy-MMM-dd")).toUpperCase().replace(".", ""));
86-
reportData.setReviewer(this.setReviewer(data.getPenCoordinator()));
84+
reportData.setReviewer(this.setReviewer(data.getStudentRegistrationContacts()));
8785
}
8886

8987

@@ -147,8 +145,8 @@ private void addToSysMatchOrDiffList(final List<ReportListItem> sysMatchedList,
147145
}
148146

149147

150-
private String setReviewer(final PenCoordinator penCoordinator) {
151-
return (penCoordinator != null && StringUtils.isNotBlank(penCoordinator.getPenCoordinatorName())) ? penCoordinator.getPenCoordinatorName() : "School PEN Coordinator";
148+
private String setReviewer(final List<SchoolContact> studentRegistrationContacts) { //If there is more than one school registration contact we just use the first one.
149+
return (!studentRegistrationContacts.isEmpty() && StringUtils.isNotBlank(studentRegistrationContacts.get(0).getFirstName() + " " + studentRegistrationContacts.get(0).getLastName())) ? studentRegistrationContacts.get(0).getFirstName() + " " + studentRegistrationContacts.get(0).getLastName() : "School PEN Coordinator";
152150
}
153151

154152
private Map<String, Student> setStudents(final List<Student> students) {

api/src/main/java/ca/bc/gov/educ/penreg/api/mappers/v1/PenRequestBatchReportDataMapper.java

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public interface PenRequestBatchReportDataMapper {
2222
@Mapping(target = "penCordinatorEmail", source = "fromEmail")
2323
@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))")
2424
@Mapping(target = "submissionNumber", source = "data.penRequestBatch.submissionNumber")
25-
@Mapping(target = "reviewer", source = "data.penCoordinator.penCoordinatorName")
2625
@Mapping(target = "processDate", ignore = true)
2726
@Mapping(target = "processTime", ignore = true)
2827
@Mapping(target = "reportDate", ignore = true)

0 commit comments

Comments
 (0)