Search in sources :

Example 1 with EventGroupIndexDto

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);
    }
}
Also used : PaginationList(de.symeda.sormas.ui.utils.PaginationList) EventGroupIndexDto(de.symeda.sormas.api.event.EventGroupIndexDto) ClickListener(com.vaadin.ui.Button.ClickListener) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) EventDto(de.symeda.sormas.api.event.EventDto) EventGroupCriteria(de.symeda.sormas.api.event.EventGroupCriteria) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) UserRight(de.symeda.sormas.api.user.UserRight) List(java.util.List) EventCriteria(de.symeda.sormas.api.event.EventCriteria) Notification(com.vaadin.ui.Notification) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) Page(com.vaadin.server.Page) Label(com.vaadin.ui.Label) Strings(de.symeda.sormas.api.i18n.Strings) UserProvider(de.symeda.sormas.ui.UserProvider) UserProvider(de.symeda.sormas.ui.UserProvider) EventDto(de.symeda.sormas.api.event.EventDto) EventCriteria(de.symeda.sormas.api.event.EventCriteria) Notification(com.vaadin.ui.Notification) EventGroupIndexDto(de.symeda.sormas.api.event.EventGroupIndexDto)

Example 2 with EventGroupIndexDto

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));
}
Also used : EventGroupSelectionField(de.symeda.sormas.ui.events.groups.EventGroupSelectionField) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) EventGroupIndexDto(de.symeda.sormas.api.event.EventGroupIndexDto)

Example 3 with EventGroupIndexDto

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);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) ArrayList(java.util.ArrayList) EventGroupIndexDto(de.symeda.sormas.api.event.EventGroupIndexDto) Predicate(javax.persistence.criteria.Predicate) SortProperty(de.symeda.sormas.api.utils.SortProperty)

Example 4 with EventGroupIndexDto

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));
}
Also used : EventGroupSelectionField(de.symeda.sormas.ui.events.groups.EventGroupSelectionField) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) EventGroupIndexDto(de.symeda.sormas.api.event.EventGroupIndexDto)

Example 5 with EventGroupIndexDto

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);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) EventGroupCriteria(de.symeda.sormas.api.event.EventGroupCriteria) EventGroupIndexDto(de.symeda.sormas.api.event.EventGroupIndexDto)

Aggregations

EventGroupIndexDto (de.symeda.sormas.api.event.EventGroupIndexDto)6 EventGroupCriteria (de.symeda.sormas.api.event.EventGroupCriteria)3 SortProperty (de.symeda.sormas.api.utils.SortProperty)3 FacadeProvider (de.symeda.sormas.api.FacadeProvider)2 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)2 EventGroupSelectionField (de.symeda.sormas.ui.events.groups.EventGroupSelectionField)2 CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)2 ConfigurableFilterDataProvider (com.vaadin.data.provider.ConfigurableFilterDataProvider)1 DataProvider (com.vaadin.data.provider.DataProvider)1 DataProviderListener (com.vaadin.data.provider.DataProviderListener)1 Page (com.vaadin.server.Page)1 SortDirection (com.vaadin.shared.data.sort.SortDirection)1 HeightMode (com.vaadin.shared.ui.grid.HeightMode)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 Label (com.vaadin.ui.Label)1 Notification (com.vaadin.ui.Notification)1 EntityRelevanceStatus (de.symeda.sormas.api.EntityRelevanceStatus)1 EventCriteria (de.symeda.sormas.api.event.EventCriteria)1 EventDto (de.symeda.sormas.api.event.EventDto)1 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)1