use of de.symeda.sormas.api.event.EventGroupIndexDto in project SORMAS-Project by hzi-braunschweig.
the class EventGroupList method drawDisplayedEntries.
@Override
protected void drawDisplayedEntries() {
EventDto event = FacadeProvider.getEventFacade().getEventByUuid(this.event.getUuid(), false);
List<EventGroupIndexDto> displayedEntries = getDisplayedEntries();
for (int i = 0, displayedEntriesSize = displayedEntries.size(); i < displayedEntriesSize; i++) {
EventGroupIndexDto eventGroup = displayedEntries.get(i);
EventGroupListEntry listEntry = new EventGroupListEntry(eventGroup);
UserProvider userProvider = UserProvider.getCurrent();
if (userProvider != null && userProvider.hasUserRight(UserRight.EVENTGROUP_LINK)) {
listEntry.addUnlinkEventListener(i, (ClickListener) clickEvent -> {
if (!userProvider.hasNationalJurisdictionLevel() && !userProvider.hasRegion(event.getEventLocation().getRegion())) {
new Notification(I18nProperties.getString(Strings.headingEventGroupUnlinkEventIssue), I18nProperties.getString(Strings.errorEventFromAnotherJurisdiction), Notification.Type.ERROR_MESSAGE, false).show(Page.getCurrent());
return;
}
ControllerProvider.getEventGroupController().unlinkEventGroup(this.event, listEntry.getEventGroup().toReference());
reload();
});
}
if (userProvider != null && userProvider.hasUserRight(UserRight.EVENTGROUP_EDIT)) {
listEntry.addEditListener(i, (ClickListener) clickEvent -> {
ControllerProvider.getEventGroupController().navigateToData(listEntry.getEventGroup().getUuid());
});
}
listEntry.addListEventsListener(i, (ClickListener) clickEvent -> {
EventCriteria eventCriteria = new EventCriteria();
eventCriteria.setEventGroup(listEntry.getEventGroup().toReference());
ControllerProvider.getEventController().navigateTo(eventCriteria);
});
listLayout.addComponent(listEntry);
}
}
use of de.symeda.sormas.api.event.EventGroupIndexDto in project SORMAS-Project by hzi-braunschweig.
the class EventGroupController method selectOrCreate.
public void selectOrCreate(List<EventReferenceDto> eventReferences, Runnable callback) {
Set<String> excludedEventGroupUuids = FacadeProvider.getEventGroupFacade().getCommonEventGroupsByEvents(eventReferences).stream().map(EventGroupReferenceDto::getUuid).collect(Collectors.toSet());
EventGroupSelectionField selectionField = new EventGroupSelectionField(excludedEventGroupUuids);
selectionField.setWidth(1024, Sizeable.Unit.PIXELS);
final CommitDiscardWrapperComponent<EventGroupSelectionField> component = new CommitDiscardWrapperComponent<>(selectionField);
component.addCommitListener(() -> {
EventGroupIndexDto selectedEventGroup = selectionField.getValue();
if (selectedEventGroup != null) {
FacadeProvider.getEventGroupFacade().linkEventsToGroup(eventReferences, selectedEventGroup.toReference());
FacadeProvider.getEventGroupFacade().notifyEventAddedToEventGroup(selectedEventGroup.toReference(), eventReferences);
Notification.show(I18nProperties.getString(Strings.messageEventLinkedToGroup), Type.TRAY_NOTIFICATION);
if (callback != null) {
callback.run();
} else {
SormasUI.refreshView();
}
} else {
create(eventReferences, callback);
}
});
selectionField.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateEventGroup));
}
use of de.symeda.sormas.api.event.EventGroupIndexDto in project SORMAS-Project by hzi-braunschweig.
the class EventGroupFacadeEjb method getIndexList.
@Override
public List<EventGroupIndexDto> getIndexList(EventGroupCriteria eventGroupCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<EventGroupIndexDto> cq = cb.createQuery(EventGroupIndexDto.class);
Root<EventGroup> eventGroup = cq.from(EventGroup.class);
Subquery<Long> eventCountSubquery = cq.subquery(Long.class);
Root<EventGroup> eventGroupSubQuery = eventCountSubquery.from(EventGroup.class);
Join<EventGroup, Event> eventSubQueryJoin = eventGroupSubQuery.join(EventGroup.EVENTS, JoinType.LEFT);
eventCountSubquery.select(cb.countDistinct(eventSubQueryJoin.get(Event.ID)));
eventCountSubquery.where(cb.equal(eventGroupSubQuery.get(EventGroup.ID), eventGroup.get(EventGroup.ID)));
eventCountSubquery.groupBy(eventGroupSubQuery.get(EventGroup.ID));
cq.multiselect(eventGroup.get(EventGroup.UUID), eventGroup.get(EventGroup.NAME), eventGroup.get(EventGroup.CHANGE_DATE), eventCountSubquery.getSelection());
Predicate filter = null;
if (eventGroupCriteria != null) {
if (eventGroupCriteria.getUserFilterIncluded()) {
filter = eventGroupService.createUserFilter(cb, cq, eventGroup);
}
Predicate criteriaFilter = eventGroupService.buildCriteriaFilter(eventGroupCriteria, cb, eventGroup);
filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
}
if (filter != null) {
cq.where(filter);
}
if (sortProperties != null && sortProperties.size() > 0) {
List<Order> order = new ArrayList<>(sortProperties.size());
for (SortProperty sortProperty : sortProperties) {
Expression<?> expression;
switch(sortProperty.propertyName) {
case EventGroupIndexDto.UUID:
case EventGroupIndexDto.NAME:
expression = eventGroup.get(sortProperty.propertyName);
break;
default:
throw new IllegalArgumentException(sortProperty.propertyName);
}
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
}
cq.orderBy(order);
} else {
cq.orderBy(cb.desc(eventGroup.get(EventGroup.CHANGE_DATE)));
}
cq.distinct(true);
return QueryHelper.getResultList(em, cq, first, max);
}
use of de.symeda.sormas.api.event.EventGroupIndexDto in project SORMAS-Project by hzi-braunschweig.
the class EventGroupController method select.
public void select(List<EventReferenceDto> eventReferences, Runnable callback) {
Set<String> excludedEventGroupUuids = FacadeProvider.getEventGroupFacade().getCommonEventGroupsByEvents(eventReferences).stream().map(EventGroupReferenceDto::getUuid).collect(Collectors.toSet());
EventGroupSelectionField selectionField = new EventGroupSelectionField(excludedEventGroupUuids);
selectionField.setWidth(1024, Sizeable.Unit.PIXELS);
final CommitDiscardWrapperComponent<EventGroupSelectionField> component = new CommitDiscardWrapperComponent<>(selectionField);
component.addCommitListener(() -> {
EventGroupIndexDto selectedEventGroup = selectionField.getValue();
if (selectedEventGroup != null) {
FacadeProvider.getEventGroupFacade().linkEventsToGroup(eventReferences, selectedEventGroup.toReference());
FacadeProvider.getEventGroupFacade().notifyEventAddedToEventGroup(selectedEventGroup.toReference(), eventReferences);
Notification.show(I18nProperties.getString(Strings.messageEventLinkedToGroup), Type.TRAY_NOTIFICATION);
if (callback != null) {
callback.run();
} else {
SormasUI.refreshView();
}
}
});
selectionField.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateEventGroup));
}
use of de.symeda.sormas.api.event.EventGroupIndexDto in project SORMAS-Project by hzi-braunschweig.
the class EventGroupsGrid method setLazyDataProvider.
public void setLazyDataProvider() {
DataProvider<EventGroupIndexDto, EventGroupCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getEventGroupFacade().getIndexList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> (int) FacadeProvider.getEventGroupFacade().count(query.getFilter().orElse(null)));
setDataProvider(dataProvider);
setSelectionMode(SelectionMode.NONE);
}
Aggregations