Search in sources :

Example 1 with NotificationType

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);
    }
}
Also used : Disease(de.symeda.sormas.api.Disease) NotificationType(de.symeda.sormas.api.user.NotificationType) ArrayList(java.util.ArrayList) Region(de.symeda.sormas.backend.infrastructure.region.Region) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Case(de.symeda.sormas.backend.caze.Case) Contact(de.symeda.sormas.backend.contact.Contact) HashSet(java.util.HashSet)

Example 2 with NotificationType

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.");
    }
}
Also used : DtoHelper(de.symeda.sormas.backend.util.DtoHelper) Join(javax.persistence.criteria.Join) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) LoggerFactory(org.slf4j.LoggerFactory) EventGroupDto(de.symeda.sormas.api.event.EventGroupDto) StringUtils(org.apache.commons.lang3.StringUtils) Valid(javax.validation.Valid) Page(de.symeda.sormas.api.common.Page) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) NotificationService(de.symeda.sormas.backend.common.NotificationService) EventGroupFacade(de.symeda.sormas.api.event.EventGroupFacade) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException) Set(java.util.Set) Region(de.symeda.sormas.backend.infrastructure.region.Region) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) MessageContents(de.symeda.sormas.backend.common.messaging.MessageContents) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) Order(javax.persistence.criteria.Order) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) Location(de.symeda.sormas.backend.location.Location) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) EventGroupIndexDto(de.symeda.sormas.api.event.EventGroupIndexDto) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) HashMap(java.util.HashMap) EventGroupCriteria(de.symeda.sormas.api.event.EventGroupCriteria) EventGroupReferenceDto(de.symeda.sormas.api.event.EventGroupReferenceDto) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) LocalBean(javax.ejb.LocalBean) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) Logger(org.slf4j.Logger) DataHelper(de.symeda.sormas.api.utils.DataHelper) MessageSubject(de.symeda.sormas.backend.common.messaging.MessageSubject) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) SortProperty(de.symeda.sormas.api.utils.SortProperty) Maps(com.google.common.collect.Maps) UserRight(de.symeda.sormas.api.user.UserRight) NotificationType(de.symeda.sormas.api.user.NotificationType) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) Subquery(javax.persistence.criteria.Subquery) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) User(de.symeda.sormas.backend.user.User) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException)

Aggregations

NotificationType (de.symeda.sormas.api.user.NotificationType)2 Region (de.symeda.sormas.backend.infrastructure.region.Region)2 ArrayList (java.util.ArrayList)2 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 Disease (de.symeda.sormas.api.Disease)1 Page (de.symeda.sormas.api.common.Page)1 EventGroupCriteria (de.symeda.sormas.api.event.EventGroupCriteria)1 EventGroupDto (de.symeda.sormas.api.event.EventGroupDto)1 EventGroupFacade (de.symeda.sormas.api.event.EventGroupFacade)1 EventGroupIndexDto (de.symeda.sormas.api.event.EventGroupIndexDto)1 EventGroupReferenceDto (de.symeda.sormas.api.event.EventGroupReferenceDto)1 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)1 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)1 Strings (de.symeda.sormas.api.i18n.Strings)1 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)1 JurisdictionLevel (de.symeda.sormas.api.user.JurisdictionLevel)1 UserRight (de.symeda.sormas.api.user.UserRight)1 DataHelper (de.symeda.sormas.api.utils.DataHelper)1 SortProperty (de.symeda.sormas.api.utils.SortProperty)1