Skip to content

Commit

Permalink
Cleaning up code and replacing references to PEN Coordinator to Data …
Browse files Browse the repository at this point in the history
…Management Unit. Removed reference to schoolAPI and changed config map to include Institute API and removed permission for PEN_COORDINATORS.
  • Loading branch information
soletsdev committed Feb 7, 2024
1 parent 312b039 commit b144019
Show file tree
Hide file tree
Showing 25 changed files with 138 additions and 8,230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public class PenRegBatchProcessor {
*/
private final NotificationService notificationService;
/**
* The Pen coordinator service.
* The Student Registration Contact service.
*/
private final StudentRegistrationContactService penCoordinatorService;
private final StudentRegistrationContactService studentRegistrationContactService;

/**
* The Duplicate file check service map.
Expand All @@ -114,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 StudentRegistrationContactService 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 @@ -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> school = this.restUtils.getSchoolByMincode(penWebBlobEntity.getMincode());
school.ifPresent(value -> entity.setSchoolName(value.getDisplayNameNoSpecialChars())); //TODO should this be no special characters?
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 @@ -271,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.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()));
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 @@ -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> school = this.restUtils.getSchoolByMincode(penWebBlobEntity.getMincode());
school.ifPresent(value -> entity.setSchoolName(value.getDisplayNameNoSpecialChars())); //TODO check if we need to make sure to have a safe display name
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 @@ -81,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.getStudentRegistrationContacts())); //TODO figure out what to do here if we have more than 1 reviewer
reportData.setReviewer(this.setReviewer(data.getStudentRegistrationContacts()));
}


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


private String setReviewer(final List<SchoolContact> studentRegistrationContacts) { //TODO check for potential bug last name could be blank?
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";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import ca.bc.gov.educ.penreg.api.model.v1.Saga;
import ca.bc.gov.educ.penreg.api.model.v1.SagaEvent;
import ca.bc.gov.educ.penreg.api.orchestrator.base.BaseOrchestrator;
import ca.bc.gov.educ.penreg.api.properties.PenCoordinatorProperties;
import ca.bc.gov.educ.penreg.api.properties.DataManagementUnitProperties;
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.*;
Expand Down Expand Up @@ -54,15 +54,15 @@ public abstract class BaseReturnFilesOrchestrator<T> extends BaseOrchestrator<T>
@Getter(PROTECTED)
private final PenRequestBatchService penRequestBatchService;
@Getter(PROTECTED)
private final StudentRegistrationContactService penCoordinatorService;
private final StudentRegistrationContactService studentRegistrationContactService;
@Getter(PROTECTED)
private final ResponseFileGeneratorService responseFileGeneratorService;
@Getter(PROTECTED)
private final PenRequestBatchStudentValidationIssueService penRequestBatchStudentValidationIssueService;
@Getter(PROTECTED)
private final RestUtils restUtils;
@Getter(PROTECTED)
private final PenCoordinatorProperties penCoordinatorProperties;
private final DataManagementUnitProperties dataManagementUnitProperties;

/**
* Instantiates a new Base orchestrator.
Expand All @@ -73,21 +73,21 @@ public abstract class BaseReturnFilesOrchestrator<T> extends BaseOrchestrator<T>
* @param sagaName the saga name
* @param topicToSubscribe the topic to subscribe
* @param penRequestBatchService the pen request batch service
* @param penCoordinatorService the pen coordinator service
* @param penCoordinatorProperties the pen coordinator properties
* @param studentRegistrationContactService the student registration contact service
* @param dataManagementUnitProperties the data mangement unit properties
*/
protected BaseReturnFilesOrchestrator(final SagaService sagaService, final MessagePublisher messagePublisher,
final Class<T> clazz, final String sagaName, final String topicToSubscribe,
final PenRequestBatchService penRequestBatchService,
final StudentRegistrationContactService penCoordinatorService,
final PenCoordinatorProperties penCoordinatorProperties,
final StudentRegistrationContactService studentRegistrationContactService,
final DataManagementUnitProperties dataManagementUnitProperties,
final ResponseFileGeneratorService responseFileGeneratorService,
final PenRequestBatchStudentValidationIssueService penRequestBatchStudentValidationIssueService,
final RestUtils restUtils) {
super(sagaService, messagePublisher, clazz, sagaName, topicToSubscribe);
this.penRequestBatchService = penRequestBatchService;
this.penCoordinatorService = penCoordinatorService;
this.penCoordinatorProperties = penCoordinatorProperties;
this.studentRegistrationContactService = studentRegistrationContactService;
this.dataManagementUnitProperties = dataManagementUnitProperties;
this.responseFileGeneratorService = responseFileGeneratorService;
this.penRequestBatchStudentValidationIssueService = penRequestBatchStudentValidationIssueService;
this.restUtils = restUtils;
Expand All @@ -106,12 +106,11 @@ protected void gatherReportData(final Event event, final Saga saga, final BasePe
final List<PenRequestBatchStudent> 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.setStudentRegistrationContacts(this.getPenCoordinator(penRequestBatch.get()));
penRequestBatchReturnFilesSagaData.setFromEmail(this.penCoordinatorProperties.getFromEmail());
penRequestBatchReturnFilesSagaData.setTelephone(this.penCoordinatorProperties.getTelephone());
penRequestBatchReturnFilesSagaData.setFacsimile(this.penCoordinatorProperties.getFacsimile());
penRequestBatchReturnFilesSagaData.setMailingAddress(this.penCoordinatorProperties.getMailingAddress());
penRequestBatchReturnFilesSagaData.setStudentRegistrationContacts(this.getStudentRegistrationContactsByMincode(penRequestBatch.get()));
penRequestBatchReturnFilesSagaData.setFromEmail(this.dataManagementUnitProperties.getFromEmail());
penRequestBatchReturnFilesSagaData.setTelephone(this.dataManagementUnitProperties.getTelephone());
penRequestBatchReturnFilesSagaData.setFacsimile(this.dataManagementUnitProperties.getFacsimile());
penRequestBatchReturnFilesSagaData.setMailingAddress(this.dataManagementUnitProperties.getMailingAddress());
saga.setPayload(JsonUtil.getJsonStringFromObject(penRequestBatchReturnFilesSagaData)); // save the updated payload to DB...
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);
nextEvent.setEventOutcome(REPORT_DATA_GATHERED);
Expand Down Expand Up @@ -216,7 +215,7 @@ protected void sendArchivedEmail(final Event event, final Saga saga, final BaseP
}
log.debug("Pending Records value :: {}", pendingRecords);
final PenRequestBatchArchivedEmailEvent penRequestBatchArchivedEmailEvent = PenRequestBatchArchivedEmailEvent.builder()
.fromEmail(this.getPenCoordinatorProperties().getFromEmail())
.fromEmail(this.getDataManagementUnitProperties().getFromEmail())
.mincode(penRequestBatchReturnFilesSagaData.getPenRequestBatch().getMincode())
.submissionNumber(penRequestBatchReturnFilesSagaData.getPenRequestBatch().getSubmissionNumber())
.schoolName(penRequestBatchReturnFilesSagaData.getSchoolName())
Expand All @@ -226,10 +225,10 @@ protected void sendArchivedEmail(final Event event, final Saga saga, final BaseP
.replyTo(this.getTopicToSubscribe())
.build();

//set toEmail and email type depending on whether a penCoordinator exists for the mincode
//set toEmail and email type depending on whether a student registration school contact 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(new ArrayList<>(List.of(this.getPenCoordinatorProperties().getFromEmail())));
penRequestBatchArchivedEmailEvent.setToEmail(new ArrayList<>(List.of(this.getDataManagementUnitProperties().getFromEmail())));
} else {
nextEvent.setEventType(NOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT);
penRequestBatchArchivedEmailEvent.setToEmail(penRequestBatchReturnFilesSagaData.getStudentRegistrationContacts().stream().map(SchoolContact::getEmail).toList());
Expand All @@ -253,11 +252,11 @@ private long getValueFromMap(final String code, final Map<String, Long> prbStude
}


protected boolean hasPenCoordinatorEmail(final BasePenRequestBatchReturnFilesSagaData penRequestBatchReturnFilesSagaData) {
return !this.hasNoPenCoordinatorEmail(penRequestBatchReturnFilesSagaData);
protected boolean hasStudentRegistrationContactEmail(final BasePenRequestBatchReturnFilesSagaData penRequestBatchReturnFilesSagaData) {
return !this.hasNoStudentRegistrationContactEmail(penRequestBatchReturnFilesSagaData);
}

protected boolean hasNoPenCoordinatorEmail(final BasePenRequestBatchReturnFilesSagaData penRequestBatchReturnFilesSagaData) {
protected boolean hasNoStudentRegistrationContactEmail(final BasePenRequestBatchReturnFilesSagaData penRequestBatchReturnFilesSagaData) {
return penRequestBatchReturnFilesSagaData.getStudentRegistrationContacts().isEmpty();
}

Expand All @@ -275,22 +274,19 @@ protected boolean isNotSupportingPDFGeneration(final BasePenRequestBatchReturnFi
&& penRequestBatchReturnFilesSagaData.getPenRequestBatchStudents().size() > this.restUtils.getProps().getBlockPdfGenerationThreshold());
}

protected void sendHasNoCoordinatorEmail(final Event event, final Saga saga, final BasePenRequestBatchReturnFilesSagaData penRequestBatchReturnFilesSagaData) throws JsonProcessingException {
protected void sendHasNoStudentRegistrationContactEmail(final Event event, final Saga saga, final BasePenRequestBatchReturnFilesSagaData penRequestBatchReturnFilesSagaData) throws JsonProcessingException {
this.sendArchivedEmail(event, saga, penRequestBatchReturnFilesSagaData, NOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_NO_SCHOOL_CONTACT);
}

protected void sendHasCoordinatorEmail(final Event event, final Saga saga, final BasePenRequestBatchReturnFilesSagaData penRequestBatchReturnFilesSagaData) throws JsonProcessingException {
protected void sendHasStudentRegistrationContactEmail(final Event event, final Saga saga, final BasePenRequestBatchReturnFilesSagaData penRequestBatchReturnFilesSagaData) throws JsonProcessingException {
this.sendArchivedEmail(event, saga, penRequestBatchReturnFilesSagaData, NOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT);
}

protected List<SchoolContact> getPenCoordinator(final PenRequestBatchEntity penRequestBatchEntity) {
protected List<SchoolContact> getStudentRegistrationContactsByMincode(final PenRequestBatchEntity penRequestBatchEntity) {
try {
// TODO refactor name to getStudentRegistrationContacts
final var penCoordinatorOptional = this.getPenCoordinatorService().getStudentRegistrationContactsByMincode(penRequestBatchEntity.getMincode());

return penCoordinatorOptional;
return this.getStudentRegistrationContactService().getStudentRegistrationContactsByMincode(penRequestBatchEntity.getMincode());
} catch (final NullPointerException 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
log.error("Error while trying to get get student registration contact. The student registration contact map is null", e);
return null;
}
}
Expand Down
Loading

0 comments on commit b144019

Please sign in to comment.