Search in sources :

Example 1 with Query

use of com.vaadin.flow.data.provider.Query in project flow by vaadin.

the class VaadinSpringDataHelpersTest method toSpringDataSort_generatesAscendingAndDescendingSpringSort.

@Test
public void toSpringDataSort_generatesAscendingAndDescendingSpringSort() {
    List<QuerySortOrder> querySortOrders = QuerySortOrder.asc("name").thenDesc("age").build();
    Query<?, ?> query = new Query<>(0, 1, querySortOrders, null, null);
    Sort sort = VaadinSpringDataHelpers.toSpringDataSort(query);
    Assert.assertNotNull(sort);
    Assert.assertEquals(2L, sort.stream().count());
    Sort.Order nameOrder = sort.getOrderFor("name");
    Assert.assertNotNull(nameOrder);
    Assert.assertTrue(nameOrder.isAscending());
    Sort.Order ageOrder = sort.getOrderFor("age");
    Assert.assertNotNull(ageOrder);
    Assert.assertTrue(ageOrder.isDescending());
}
Also used : QuerySortOrder(com.vaadin.flow.data.provider.QuerySortOrder) Query(com.vaadin.flow.data.provider.Query) Sort(org.springframework.data.domain.Sort) Test(org.junit.Test)

Example 2 with Query

use of com.vaadin.flow.data.provider.Query in project vaadin-app-layout by appreciated.

the class MainLayout method getLayoutConfiguration.

private AppLayout getLayoutConfiguration(Class<? extends AppLayout> variant) {
    this.variant = variant;
    dataProvider = new ListDataProvider<>(Arrays.asList(new TestSearchResult("Header1", "Description1"), new TestSearchResult("Header2", "Description2"), new TestSearchResult("Header3", "Description3"), new TestSearchResult("Header4", "Description4"), new TestSearchResult("Header5", "Description5"), new TestSearchResult("Header6", "Description6"), new TestSearchResult("Header7", "Description7"), new TestSearchResult("Header8", "Description8"), new TestSearchResult("Header9", "Description9"), new TestSearchResult("Header10", "Description10")));
    button = new SearchOverlayButtonBuilder<TestSearchResult, SerializablePredicate<TestSearchResult>>().withDataProvider(dataProvider).withQueryProvider(s -> new Query<>(testEntity -> !s.equals("") && testEntity.getHeader().startsWith(s))).withDataViewProvider(queryResult -> {
        RippleClickableCard card = new RippleClickableCard(new Item(queryResult.getHeader(), queryResult.getDescription()));
        card.setWidthFull();
        card.setBackground("var(--app-layout-bar-background-base-color)");
        return card;
    }).withQueryResultListener(testSearchResult -> Notification.show(testSearchResult.getHeader())).build();
    if (this.variant != TopLayouts.Top.class && this.variant != TopLayouts.TopLarge.class) {
        LeftNavigationItem home = new LeftNavigationItem("Home", VaadinIcon.HOME.create(), View1.class);
        LeftNavigationItem menu = new LeftNavigationItem("Menu", VaadinIcon.MENU.create(), View9.class);
        notificationHolder.bind(home.getBadge());
        badgeHolder.bind(menu.getBadge());
        AppLayout build = AppLayoutBuilder.get(this.variant).withTitle("App Layout").withIcon("/frontend/images/logo.png").withAppBar(AppBarBuilder.get().add(button, AppBarProfileButtonBuilder.get().withItem("Profile", event -> Notification.show("Profile clicked")).withItem("Profile", event -> Notification.show("Profile clicked")).withItem("Profile", event -> Notification.show("Profile clicked")).build(), AppBarImageProfileButtonBuilder.get("/frontend/images/logo.png").withItem("Profile", event -> Notification.show("Profile clicked")).withItem("Profile", event -> Notification.show("Profile clicked")).withItem("Profile", event -> Notification.show("Profile clicked")).build(), new SearchButton().withValueChangeListener(event -> Notification.show(event.getValue())), new NotificationButton<>(VaadinIcon.BELL, notificationHolder)).build()).withAppMenu(LeftAppMenuBuilder.get().addToSection(HEADER, new LeftHeaderItem("App-Layout", "Version 4.0.0", "/frontend/images/logo.png"), new LeftClickableItem("Set Behaviour HEADER", VaadinIcon.COG.create(), clickEvent -> openModeSelector(this.variant))).add(home, new LeftNavigationItem("Grid", VaadinIcon.TABLE.create(), GridTest.class), LeftSubMenuBuilder.get("My Submenu 1", VaadinIcon.PLUS.create()).add(LeftSubMenuBuilder.get("My Submenu 2", VaadinIcon.PLUS.create()).add(new LeftNavigationItem("Charts", VaadinIcon.SPLINE_CHART.create(), View2.class), new LeftNavigationItem("Contact", VaadinIcon.CONNECT.create(), View3.class), new LeftNavigationItem("More", VaadinIcon.COG.create(), View4.class)).build(), new LeftNavigationItem("Contact1", VaadinIcon.CONNECT.create(), View5.class), new LeftNavigationItem("More1", VaadinIcon.COG.create(), View6.class)).build(), new LeftSectionItem(), LeftSubMenuBuilder.get("My Submenu 3").add(new LeftNavigationItem("Contact2", VaadinIcon.CONNECT.create(), View7.class), new LeftNavigationItem("More2", VaadinIcon.COG.create(), View8.class)).build(), new LeftSectionItem("Test"), menu).addToSection(FOOTER, new LeftClickableItem("Set Behaviour FOOTER", VaadinIcon.COG.create(), clickEvent -> openModeSelector(this.variant))).build()).withUpNavigation().build();
        return build;
    } else {
        return AppLayoutBuilder.get(this.variant).withTitle("App Layout").withAppBar(AppBarBuilder.get().add(button, AppBarProfileButtonBuilder.get().withItem("Profile", event -> Notification.show("Profile clicked")).withItem("Profile", event -> Notification.show("Profile clicked")).withItem("Profile", event -> Notification.show("Profile clicked")).build(), new NotificationButton<>(VaadinIcon.BELL, notificationHolder)).build()).withAppMenu(TopAppMenuBuilder.get().add(new TopClickableItem("Set Behaviour 1", VaadinIcon.COG.create(), event -> openModeSelector(this.variant)), new TopNavigationItem("Home", VaadinIcon.HOME.create(), View1.class), new TopNavigationItem("Contact", VaadinIcon.SPLINE_CHART.create(), View2.class), new TopClickableItem("Set Behaviour 2", VaadinIcon.COG.create(), event -> openModeSelector(this.variant)), new TopNavigationItem("More", VaadinIcon.CONNECT.create(), View3.class)).build()).withUpNavigation().build();
    }
}
Also used : ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) LeftLayouts(com.github.appreciated.app.layout.component.applayout.LeftLayouts) Arrays(java.util.Arrays) SearchOverlayButton(com.github.appreciated.app.layout.addons.search.overlay.SearchOverlayButton) Priority(com.github.appreciated.app.layout.addons.notification.entity.Priority) SearchButton(com.github.appreciated.app.layout.addons.search.SearchButton) LeftSubMenuBuilder(com.github.appreciated.app.layout.component.menu.left.builder.LeftSubMenuBuilder) DefaultNotificationHolder(com.github.appreciated.app.layout.addons.notification.DefaultNotificationHolder) FOOTER(com.github.appreciated.app.layout.entity.Section.FOOTER) DefaultBadgeHolder(com.github.appreciated.app.layout.entity.DefaultBadgeHolder) AppBarProfileButtonBuilder(com.github.appreciated.app.layout.addons.profile.builder.AppBarProfileButtonBuilder) TopNavigationItem(com.github.appreciated.app.layout.component.menu.top.item.TopNavigationItem) RadioButtonGroup(com.vaadin.flow.component.radiobutton.RadioButtonGroup) TopLayouts(com.github.appreciated.app.layout.component.applayout.TopLayouts) Theme(com.vaadin.flow.theme.Theme) NotificationButton(com.github.appreciated.app.layout.addons.notification.component.NotificationButton) MEDIUM(com.github.appreciated.app.layout.addons.notification.entity.Priority.MEDIUM) LeftClickableItem(com.github.appreciated.app.layout.component.menu.left.items.LeftClickableItem) AppBarImageProfileButtonBuilder(com.github.appreciated.app.layout.addons.profile.builder.AppBarImageProfileButtonBuilder) AppLayout(com.github.appreciated.app.layout.component.applayout.AppLayout) Item(com.github.appreciated.card.content.Item) SerializablePredicate(com.vaadin.flow.function.SerializablePredicate) AppBarBuilder(com.github.appreciated.app.layout.component.appbar.AppBarBuilder) TopClickableItem(com.github.appreciated.app.layout.component.menu.top.item.TopClickableItem) Notification(com.vaadin.flow.component.notification.Notification) LeftNavigationItem(com.github.appreciated.app.layout.component.menu.left.items.LeftNavigationItem) SearchOverlayButtonBuilder(com.github.appreciated.app.layout.addons.search.overlay.SearchOverlayButtonBuilder) Query(com.vaadin.flow.data.provider.Query) AppLayoutBuilder(com.github.appreciated.app.layout.component.builder.AppLayoutBuilder) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) AppLayoutRouterLayout(com.github.appreciated.app.layout.component.router.AppLayoutRouterLayout) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) HEADER(com.github.appreciated.app.layout.entity.Section.HEADER) Lumo(com.vaadin.flow.theme.lumo.Lumo) Consumer(java.util.function.Consumer) LeftHeaderItem(com.github.appreciated.app.layout.component.menu.left.items.LeftHeaderItem) RippleClickableCard(com.github.appreciated.card.RippleClickableCard) LeftAppMenuBuilder(com.github.appreciated.app.layout.component.menu.left.builder.LeftAppMenuBuilder) TestSearchResult(com.github.appreciated.app.layout.navigation.TestSearchResult) TopAppMenuBuilder(com.github.appreciated.app.layout.component.menu.top.builder.TopAppMenuBuilder) TextRenderer(com.vaadin.flow.data.renderer.TextRenderer) Dialog(com.vaadin.flow.component.dialog.Dialog) Viewport(com.vaadin.flow.component.page.Viewport) DefaultNotification(com.github.appreciated.app.layout.addons.notification.entity.DefaultNotification) LeftSectionItem(com.github.appreciated.app.layout.component.menu.left.items.LeftSectionItem) Push(com.vaadin.flow.component.page.Push) SearchOverlayButtonBuilder(com.github.appreciated.app.layout.addons.search.overlay.SearchOverlayButtonBuilder) TopClickableItem(com.github.appreciated.app.layout.component.menu.top.item.TopClickableItem) TestSearchResult(com.github.appreciated.app.layout.navigation.TestSearchResult) NotificationButton(com.github.appreciated.app.layout.addons.notification.component.NotificationButton) LeftClickableItem(com.github.appreciated.app.layout.component.menu.left.items.LeftClickableItem) LeftSectionItem(com.github.appreciated.app.layout.component.menu.left.items.LeftSectionItem) TopNavigationItem(com.github.appreciated.app.layout.component.menu.top.item.TopNavigationItem) LeftClickableItem(com.github.appreciated.app.layout.component.menu.left.items.LeftClickableItem) Item(com.github.appreciated.card.content.Item) TopClickableItem(com.github.appreciated.app.layout.component.menu.top.item.TopClickableItem) LeftNavigationItem(com.github.appreciated.app.layout.component.menu.left.items.LeftNavigationItem) LeftHeaderItem(com.github.appreciated.app.layout.component.menu.left.items.LeftHeaderItem) LeftSectionItem(com.github.appreciated.app.layout.component.menu.left.items.LeftSectionItem) TopNavigationItem(com.github.appreciated.app.layout.component.menu.top.item.TopNavigationItem) RippleClickableCard(com.github.appreciated.card.RippleClickableCard) AppLayout(com.github.appreciated.app.layout.component.applayout.AppLayout) SearchButton(com.github.appreciated.app.layout.addons.search.SearchButton) LeftHeaderItem(com.github.appreciated.app.layout.component.menu.left.items.LeftHeaderItem) LeftNavigationItem(com.github.appreciated.app.layout.component.menu.left.items.LeftNavigationItem)

Example 3 with Query

use of com.vaadin.flow.data.provider.Query in project vaadin-app-layout by appreciated.

the class MainAppLayout method initSearchOverlayButton.

private SearchOverlayButton<TestSearchResult, SerializablePredicate<TestSearchResult>> initSearchOverlayButton() {
    // The data provider that provides the entities for the search
    ListDataProvider<TestSearchResult> listDataProvider = new ListDataProvider<>(Arrays.asList(new TestSearchResult("Header1", "Description1"), new TestSearchResult("Header2", "Description2"), new TestSearchResult("Header3", "Description3"), new TestSearchResult("Header4", "Description4"), new TestSearchResult("Header5", "Description5"), new TestSearchResult("Header6", "Description6"), new TestSearchResult("Header7", "Description7"), new TestSearchResult("Header8", "Description8"), new TestSearchResult("Header9", "Description9"), new TestSearchResult("Header10", "Description10")));
    return new SearchOverlayButtonBuilder<TestSearchResult, SerializablePredicate<TestSearchResult>>().withDataProvider(listDataProvider).withQueryProvider(s -> new Query<>(testEntity -> !s.equals("") && testEntity.getHeader().startsWith(s))).withDataViewProvider(queryResult -> {
        RippleClickableCard card = new RippleClickableCard(new Item(queryResult.getHeader(), queryResult.getDescription()));
        card.setWidthFull();
        card.setBackground("var(--lumo-base-color)");
        return card;
    }).withQueryResultListener(testSearchResult -> Notification.show(testSearchResult.getHeader())).build();
}
Also used : ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) SearchOverlayButtonBuilder(com.github.appreciated.app.layout.addons.search.overlay.SearchOverlayButtonBuilder) LeftLayouts(com.github.appreciated.app.layout.component.applayout.LeftLayouts) Arrays(java.util.Arrays) SearchOverlayButton(com.github.appreciated.app.layout.addons.search.overlay.SearchOverlayButton) Query(com.vaadin.flow.data.provider.Query) SearchButton(com.github.appreciated.app.layout.addons.search.SearchButton) AppLayoutBuilder(com.github.appreciated.app.layout.component.builder.AppLayoutBuilder) FOOTER(com.github.appreciated.app.layout.entity.Section.FOOTER) AppLayoutRouterLayout(com.github.appreciated.app.layout.component.router.AppLayoutRouterLayout) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) HEADER(com.github.appreciated.app.layout.entity.Section.HEADER) LeftHeaderItem(com.github.appreciated.app.layout.component.menu.left.items.LeftHeaderItem) RippleClickableCard(com.github.appreciated.card.RippleClickableCard) LeftAppMenuBuilder(com.github.appreciated.app.layout.component.menu.left.builder.LeftAppMenuBuilder) LeftClickableItem(com.github.appreciated.app.layout.component.menu.left.items.LeftClickableItem) Item(com.github.appreciated.card.content.Item) SerializablePredicate(com.vaadin.flow.function.SerializablePredicate) AppBarBuilder(com.github.appreciated.app.layout.component.appbar.AppBarBuilder) Viewport(com.vaadin.flow.component.page.Viewport) Notification(com.vaadin.flow.component.notification.Notification) LeftNavigationItem(com.github.appreciated.app.layout.component.menu.left.items.LeftNavigationItem) Push(com.vaadin.flow.component.page.Push) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) LeftHeaderItem(com.github.appreciated.app.layout.component.menu.left.items.LeftHeaderItem) LeftClickableItem(com.github.appreciated.app.layout.component.menu.left.items.LeftClickableItem) Item(com.github.appreciated.card.content.Item) LeftNavigationItem(com.github.appreciated.app.layout.component.menu.left.items.LeftNavigationItem) Query(com.vaadin.flow.data.provider.Query) RippleClickableCard(com.github.appreciated.card.RippleClickableCard) SerializablePredicate(com.vaadin.flow.function.SerializablePredicate)

Example 4 with Query

use of com.vaadin.flow.data.provider.Query in project flow by vaadin.

the class VaadinSpringDataHelpersTest method toSpringPageRequest_generatesSpringPageRequestWithPagingAndSort.

@Test
public void toSpringPageRequest_generatesSpringPageRequestWithPagingAndSort() {
    List<QuerySortOrder> querySortOrders = QuerySortOrder.asc("name").build();
    Query<?, ?> query = new Query<>(100, 50, querySortOrders, null, null);
    PageRequest pageRequest = VaadinSpringDataHelpers.toSpringPageRequest(query);
    Assert.assertNotNull(pageRequest);
    Assert.assertEquals(50, pageRequest.getPageSize());
    Assert.assertEquals(2, pageRequest.getPageNumber());
    Sort.Order order = pageRequest.getSort().getOrderFor("name");
    Assert.assertNotNull(order);
    Assert.assertTrue(order.isAscending());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) QuerySortOrder(com.vaadin.flow.data.provider.QuerySortOrder) Query(com.vaadin.flow.data.provider.Query) Sort(org.springframework.data.domain.Sort) Test(org.junit.Test)

Example 5 with Query

use of com.vaadin.flow.data.provider.Query in project flow by vaadin.

the class VaadinSpringDataHelpersTest method fromPagingRepository_fetchesItemsFromPagingRepoAccordingToVaadinQuery.

@Test
public void fromPagingRepository_fetchesItemsFromPagingRepoAccordingToVaadinQuery() {
    PagingAndSortingRepository repo = Mockito.mock(PagingAndSortingRepository.class);
    Mockito.doAnswer(mock -> {
        PageRequest pageRequest = mock.getArgument(0);
        int from = pageRequest.getPageNumber() * pageRequest.getPageSize();
        Sort.Order order = pageRequest.getSort().getOrderFor("someSortField");
        Stream<Integer> itemsStream = IntStream.range(0, 500).boxed();
        if (order.isDescending()) {
            itemsStream = itemsStream.sorted(Collections.reverseOrder());
        }
        // given string items 'Item XYZ' ordered according to a given query
        List<String> items = itemsStream.skip(from).limit(pageRequest.getPageSize()).map(i -> "Item " + i).collect(Collectors.toList());
        return new PageImpl<>(items);
    }).when(repo).findAll(Mockito.any(PageRequest.class));
    CallbackDataProvider.FetchCallback<String, Void> callback = VaadinSpringDataHelpers.fromPagingRepository(repo);
    // when items with indexes 100..149 and descending order are fetched
    Query<String, Void> query = new Query<>(100, 50, QuerySortOrder.desc("someSortField").build(), null, null);
    List<String> result = callback.fetch(query).collect(Collectors.toList());
    // then the result should contain items 'Item 399'...'Item 350'.
    Assert.assertEquals(50, result.size());
    Assert.assertEquals("Item 399", result.get(0));
    Assert.assertEquals("Item 350", result.get(49));
}
Also used : IntStream(java.util.stream.IntStream) Query(com.vaadin.flow.data.provider.Query) PagingAndSortingRepository(org.springframework.data.repository.PagingAndSortingRepository) PageRequest(org.springframework.data.domain.PageRequest) CallbackDataProvider(com.vaadin.flow.data.provider.CallbackDataProvider) Test(org.junit.Test) Collectors(java.util.stream.Collectors) QuerySortOrder(com.vaadin.flow.data.provider.QuerySortOrder) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) Sort(org.springframework.data.domain.Sort) Assert(org.junit.Assert) Collections(java.util.Collections) PageImpl(org.springframework.data.domain.PageImpl) PageImpl(org.springframework.data.domain.PageImpl) Query(com.vaadin.flow.data.provider.Query) CallbackDataProvider(com.vaadin.flow.data.provider.CallbackDataProvider) PageRequest(org.springframework.data.domain.PageRequest) PagingAndSortingRepository(org.springframework.data.repository.PagingAndSortingRepository) Sort(org.springframework.data.domain.Sort) Test(org.junit.Test)

Aggregations

Query (com.vaadin.flow.data.provider.Query)6 SearchOverlayButton (com.github.appreciated.app.layout.addons.search.overlay.SearchOverlayButton)3 SearchOverlayButtonBuilder (com.github.appreciated.app.layout.addons.search.overlay.SearchOverlayButtonBuilder)3 LeftLayouts (com.github.appreciated.app.layout.component.applayout.LeftLayouts)3 AppLayoutBuilder (com.github.appreciated.app.layout.component.builder.AppLayoutBuilder)3 RippleClickableCard (com.github.appreciated.card.RippleClickableCard)3 Item (com.github.appreciated.card.content.Item)3 Notification (com.vaadin.flow.component.notification.Notification)3 ListDataProvider (com.vaadin.flow.data.provider.ListDataProvider)3 SerializablePredicate (com.vaadin.flow.function.SerializablePredicate)3 Arrays (java.util.Arrays)3 SearchButton (com.github.appreciated.app.layout.addons.search.SearchButton)2 AppBarBuilder (com.github.appreciated.app.layout.component.appbar.AppBarBuilder)2 AppLayout (com.github.appreciated.app.layout.component.applayout.AppLayout)2 LeftAppMenuBuilder (com.github.appreciated.app.layout.component.menu.left.builder.LeftAppMenuBuilder)2 LeftClickableItem (com.github.appreciated.app.layout.component.menu.left.items.LeftClickableItem)2 LeftHeaderItem (com.github.appreciated.app.layout.component.menu.left.items.LeftHeaderItem)2 LeftNavigationItem (com.github.appreciated.app.layout.component.menu.left.items.LeftNavigationItem)2 AppLayoutRouterLayout (com.github.appreciated.app.layout.component.router.AppLayoutRouterLayout)2 FOOTER (com.github.appreciated.app.layout.entity.Section.FOOTER)2