use of de.symeda.sormas.api.user.NotificationType in project SORMAS-Project by hzi-braunschweig.
the class PathogenTestFacadeEjb method onPathogenTestChanged.
private void onPathogenTestChanged(PathogenTestDto existingPathogenTest, PathogenTest newPathogenTest) {
// Send an email to all responsible supervisors when a new non-pending sample test is created or the status of
// a formerly pending test result has changed
final String sampleUuid = newPathogenTest.getSample().getUuid();
final Sample sample = sampleService.getByUuid(sampleUuid);
final Case caze = sample.getAssociatedCase();
final Contact contact = sample.getAssociatedContact();
final EventParticipant eventParticipant = sample.getAssociatedEventParticipant();
Disease disease = null;
Set<NotificationType> notificationTypes = new HashSet<>();
List<Region> regions = new ArrayList<>();
if (caze != null) {
disease = caze.getDisease();
notificationTypes.add(NotificationType.CASE_LAB_RESULT_ARRIVED);
regions.addAll(JurisdictionHelper.getCaseRegions(caze));
}
if (contact != null) {
disease = contact.getDisease() != null ? contact.getDisease() : contact.getCaze().getDisease();
notificationTypes.add(NotificationType.CONTACT_LAB_RESULT_ARRIVED);
regions.addAll(JurisdictionHelper.getContactRegions(contact));
}
if (eventParticipant != null) {
disease = eventParticipant.getEvent().getDisease();
notificationTypes.add(NotificationType.EVENT_PARTICIPANT_LAB_RESULT_ARRIVED);
regions.add(eventParticipant.getEvent().getEventLocation().getRegion());
if (disease == null) {
sendMessageOnPathogenTestChanged(existingPathogenTest, newPathogenTest, null, notificationTypes, regions, MessageContents.CONTENT_LAB_RESULT_ARRIVED_EVENT_PARTICIPANT_NO_DISEASE, DataHelper.getShortUuid(eventParticipant.getUuid()));
}
}
if (disease != null) {
final String contentLabResultArrived = caze != null ? MessageContents.CONTENT_LAB_RESULT_ARRIVED : contact != null ? MessageContents.CONTENT_LAB_RESULT_ARRIVED_CONTACT : MessageContents.CONTENT_LAB_RESULT_ARRIVED_EVENT_PARTICIPANT;
final String shortUuid = DataHelper.getShortUuid(caze != null ? caze.getUuid() : contact != null ? contact.getUuid() : eventParticipant.getUuid());
sendMessageOnPathogenTestChanged(existingPathogenTest, newPathogenTest, disease, notificationTypes, regions, contentLabResultArrived, shortUuid);
}
}
use of de.symeda.sormas.api.user.NotificationType in project SORMAS-Project by hzi-braunschweig.
the class EventGroupFacadeEjb method notifyModificationOfEventGroup.
private void notifyModificationOfEventGroup(EventGroupReferenceDto eventGroupReference, List<EventReferenceDto> impactedEventReferences, NotificationType notificationType, MessageSubject subject, String contentTemplate) {
EventGroup eventGroup = eventGroupService.getByUuid(eventGroupReference.getUuid());
if (eventGroup == null) {
return;
}
User currentUser = userService.getCurrentUser();
try {
notificationService.sendNotifications(notificationType, subject, () -> {
final Set<String> allRemainingEventUuids = getEventReferencesByEventGroupUuid(eventGroupReference.getUuid()).stream().map(EventReferenceDto::getUuid).collect(Collectors.toSet());
final Set<String> impactedEventUuids = impactedEventReferences.stream().map(EventReferenceDto::getUuid).collect(Collectors.toSet());
final Map<String, User> responsibleUserByEventUuid = userService.getResponsibleUsersByEventUuids(new ArrayList<>(Sets.union(allRemainingEventUuids, impactedEventUuids)));
final Map<String, User> responsibleUserByRemainingEventUuid = Maps.filterKeys(responsibleUserByEventUuid, allRemainingEventUuids::contains);
final Map<String, User> responsibleUserByImpactedEventUuid = Maps.filterKeys(responsibleUserByEventUuid, impactedEventUuids::contains);
final String message;
if (impactedEventReferences.isEmpty()) {
message = String.format(I18nProperties.getString(contentTemplate), eventGroup.getName(), DataHelper.getShortUuid(eventGroup.getUuid()), buildCaptionForUserInNotification(currentUser), buildEventGroupSummaryForNotification(responsibleUserByRemainingEventUuid));
} else {
message = String.format(I18nProperties.getString(contentTemplate), stringifyEventsWithResponsibleUser(responsibleUserByImpactedEventUuid, ", ", ""), eventGroup.getName(), DataHelper.getShortUuid(eventGroup.getUuid()), buildCaptionForUserInNotification(currentUser), buildEventGroupSummaryForNotification(responsibleUserByRemainingEventUuid));
}
return responsibleUserByEventUuid.values().stream().collect(Collectors.toMap(Function.identity(), (u) -> message));
});
} catch (NotificationDeliveryFailedException e) {
logger.error("NotificationDeliveryFailedException when trying to notify event responsible user about a modification on an EventGroup.");
}
}
Aggregations