use of de.symeda.sormas.api.event.EventGroupReferenceDto 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.");
}
}
use of de.symeda.sormas.api.event.EventGroupReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class EventImportFacadeEjb method buildEntities.
private ImportLineResultDto<EventImportEntities> buildEntities(String[] values, String[] entityClasses, String[][] entityPropertyPaths, boolean ignoreEmptyEntries, EventImportEntities entities) {
final UserReferenceDto currentUserRef = userService.getCurrentUser().toReference();
final List<EventParticipantDto> eventParticipants = entities.getEventParticipants();
final List<EventGroupReferenceDto> eventGroupReferences = entities.getEventGroupReferences();
final MutableBoolean currentEventParticipantHasEntries = new MutableBoolean(false);
final Mutable<String> firstEventParticipantColumnName = new MutableObject<>(null);
final ImportLineResultDto<EventImportEntities> result = insertRowIntoData(values, entityClasses, entityPropertyPaths, ignoreEmptyEntries, (cellData) -> {
try {
// participant if they don't have any entries
if (String.join(".", cellData.getEntityPropertyPath()).equals(firstEventParticipantColumnName.getValue())) {
if (eventParticipants.size() > 0 && currentEventParticipantHasEntries.isFalse()) {
eventParticipants.remove(eventParticipants.size() - 1);
currentEventParticipantHasEntries.setTrue();
}
}
EventDto event = entities.getEvent();
if (DataHelper.equal(cellData.getEntityClass(), DataHelper.getHumanClassName(EventParticipantDto.class)) || DataHelper.equal(cellData.getEntityClass(), DataHelper.getHumanClassName(PersonDto.class)) || (DataHelper.equal(cellData.getEntityClass(), DataHelper.getHumanClassName(LocationDto.class)) && eventParticipants.size() > 0)) {
// to the list if the first column of a new participant has been reached and insert the entry of the cell into the participant
if (firstEventParticipantColumnName.getValue() == null) {
firstEventParticipantColumnName.setValue(String.join(".", cellData.getEntityPropertyPath()));
}
if (String.join(".", cellData.getEntityPropertyPath()).equals(firstEventParticipantColumnName.getValue())) {
currentEventParticipantHasEntries.setFalse();
EventParticipantDto eventParticipantDto = EventParticipantDto.build(new EventReferenceDto(event.getUuid()), currentUserRef);
eventParticipantDto.setPerson(PersonDto.buildImportEntity());
eventParticipants.add(eventParticipantDto);
}
if (!StringUtils.isEmpty(cellData.getValue())) {
currentEventParticipantHasEntries.setTrue();
insertColumnEntryIntoEventParticipantData(eventParticipants.get(eventParticipants.size() - 1), cellData.getValue(), cellData.getEntityPropertyPath());
}
} else if (DataHelper.equal(cellData.getEntityClass(), DataHelper.getHumanClassName(EventGroupReferenceDto.class))) {
eventGroupReferences.add(new EventGroupReferenceDto(cellData.getValue()));
} else if (!StringUtils.isEmpty(cellData.getValue())) {
// If the cell entry is not empty, try to insert it into the current event
insertColumnEntryIntoData(event, cellData.getValue(), cellData.getEntityPropertyPath());
}
} catch (ImportErrorException | InvalidColumnException e) {
return e;
}
return null;
});
// Remove the eventParticipant if empty
if (eventParticipants.size() > 0 && currentEventParticipantHasEntries.isFalse()) {
eventParticipants.remove(eventParticipants.size() - 1);
}
return result;
}
use of de.symeda.sormas.api.event.EventGroupReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class EventImportFacadeEjb method saveImportedEntities.
@Override
public ImportLineResultDto<EventImportEntities> saveImportedEntities(@Valid EventImportEntities entities) {
EventDto event = entities.getEvent();
List<EventParticipantDto> eventParticipants = entities.getEventParticipants();
List<EventGroupReferenceDto> eventGroupReferences = entities.getEventGroupReferences();
try {
event = eventFacade.save(event);
for (EventParticipantDto eventParticipant : eventParticipants) {
PersonDto existingPerson = personFacade.getPersonByUuid(eventParticipant.getPerson().getUuid());
// So no need to persist an already existing person
if (existingPerson == null) {
personFacade.savePerson(eventParticipant.getPerson());
}
eventParticipantFacade.save(eventParticipant);
}
eventGroupFacade.linkEventToGroups(event.toReference(), eventGroupReferences);
return ImportLineResultDto.successResult();
} catch (ValidationRuntimeException e) {
return ImportLineResultDto.errorResult(e.getMessage());
}
}
use of de.symeda.sormas.api.event.EventGroupReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class EventGroupFacadeEjb method unlinkEventGroup.
@Override
@RolesAllowed(UserRight._EVENTGROUP_LINK)
public void unlinkEventGroup(EventReferenceDto eventReference, EventGroupReferenceDto eventGroupReference) {
User currentUser = userService.getCurrentUser();
Event event = eventService.getByUuid(eventReference.getUuid());
final JurisdictionLevel jurisdictionLevel = currentUser.getJurisdictionLevel();
if (jurisdictionLevel != JurisdictionLevel.NATION) {
Region region = event.getEventLocation().getRegion();
if (!userService.hasRegion(new RegionReferenceDto(region.getUuid()))) {
throw new UnsupportedOperationException("User " + currentUser.getUuid() + " is not allowed to unlink events from another region to an event group.");
}
}
// Check that the event group is not already unlinked to this event
if (event.getEventGroups() == null || event.getEventGroups().stream().noneMatch(group -> group.getUuid().equals(eventGroupReference.getUuid()))) {
return;
}
List<EventGroup> groups = new ArrayList<>();
for (EventGroup eventGroup : event.getEventGroups()) {
if (eventGroup.getUuid().equals(eventGroupReference.getUuid())) {
continue;
}
groups.add(eventGroup);
}
event.setEventGroups(groups);
eventService.ensurePersisted(event);
}
use of de.symeda.sormas.api.event.EventGroupReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class EventGroupFacadeEjb method getCommonEventGroupsByEvents.
@Override
public List<EventGroupReferenceDto> getCommonEventGroupsByEvents(List<EventReferenceDto> eventReferences) {
Map<String, Set<String>> eventGroupsByEvent = new HashMap<>();
IterableHelper.executeBatched(eventReferences, ModelConstants.PARAMETER_LIMIT, batchedEventReferences -> {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<EventGroup> from = cq.from(EventGroup.class);
Join<EventGroup, Event> eventJoin = from.join(EventGroup.EVENTS, JoinType.INNER);
Set<String> eventUuids = batchedEventReferences.stream().map(EventReferenceDto::getUuid).collect(Collectors.toSet());
cq.where(eventJoin.get(Event.UUID).in(eventUuids));
cq.multiselect(eventJoin.get(Event.UUID), from.get(EventGroup.UUID));
eventGroupsByEvent.putAll(em.createQuery(cq).getResultList().stream().collect(Collectors.groupingBy(row -> (String) row[0], Collectors.mapping(row -> (String) row[1], Collectors.toSet()))));
});
if (eventGroupsByEvent.isEmpty()) {
return Collections.emptyList();
}
Set<String> commonEventGroupUuids = eventGroupsByEvent.values().stream().reduce(Sets::intersection).orElseGet(Collections::emptySet);
return commonEventGroupUuids.stream().map(EventGroupReferenceDto::new).collect(Collectors.toList());
}
Aggregations