Search in sources :

Example 1 with CollectionPage

use of net.n2oapp.criteria.api.CollectionPage in project n2o-framework by i-novus-llc.

the class PageBinderTest method defaultValuesQueryTest.

/**
 * Разрешение моделей фильтров через выборку
 */
@Test
public void defaultValuesQueryTest() {
    N2oSubModelsProcessor subModelsProcessor = mock(N2oSubModelsProcessor.class);
    PageContext context = new PageContext("testDefValQuery", "table");
    doAnswer(invocation -> new CollectionPage<>(1, singletonList(new DataSet("name", "test1")), new Criteria())).when(subModelsProcessor).getQueryResult(anyString(), any());
    Page page = bind("net/n2oapp/framework/config/metadata/compile/page/defaultValuesQuery/testDefValQuery.page.xml", "net/n2oapp/framework/config/metadata/compile/page/defaultValuesQuery/testDefValQuery.query.xml", "net/n2oapp/framework/config/metadata/compile/page/defaultValuesQuery/default.query.xml").get(context, new DataSet(), subModelsProcessor);
    // Разрешится значение из выборки
    ModelLink name = page.getModels().get("filter['table_main'].name");
    assertThat(name.getValue(), is("test1"));
    doAnswer(invocation -> new CollectionPage<>(1, singletonList(new DataSet()), new Criteria())).when(subModelsProcessor).getQueryResult(anyString(), any());
    page = bind("net/n2oapp/framework/config/metadata/compile/page/defaultValuesQuery/testDefValQuery.page.xml", "net/n2oapp/framework/config/metadata/compile/page/defaultValuesQuery/testDefValQuery.query.xml", "net/n2oapp/framework/config/metadata/compile/page/defaultValuesQuery/default.query.xml").get(context, new DataSet(), subModelsProcessor);
    // Разрешится значение по умолчанию на поле, т.к. в выборке не пришло значение
    name = page.getModels().get("filter['table_main'].name");
    assertThat(name.getValue(), is("test2"));
/* todo NNO-7523
        doAnswer(invocation -> new CollectionPage<>(1, singletonList(new DataSet("name", "test1")), new Criteria())).when(subModelsProcessor).getQueryResult(anyString(), any());
        page = bind("net/n2oapp/framework/config/metadata/compile/page/defaultValuesQuery/testDefValQuery.page.xml",
                "net/n2oapp/framework/config/metadata/compile/page/defaultValuesQuery/testDefValQuery.query.xml",
                "net/n2oapp/framework/config/metadata/compile/page/defaultValuesQuery/default.query.xml")
                .get(context, new DataSet("name", "test3"), subModelsProcessor);

        //Разрешится значение из запроса, т.к. оно самое приоритетное
        name = page.getModels().get("filter['table_main'].name");
        assertThat(name.getValue(), is("test3"));*/
}
Also used : DataSet(net.n2oapp.criteria.dataset.DataSet) ModelLink(net.n2oapp.framework.api.metadata.meta.ModelLink) N2oSubModelsProcessor(net.n2oapp.framework.config.util.N2oSubModelsProcessor) PageContext(net.n2oapp.framework.config.metadata.compile.context.PageContext) CollectionPage(net.n2oapp.criteria.api.CollectionPage) Page(net.n2oapp.framework.api.metadata.meta.page.Page) SimplePage(net.n2oapp.framework.api.metadata.meta.page.SimplePage) Criteria(net.n2oapp.criteria.api.Criteria) Test(org.junit.Test)

Example 2 with CollectionPage

use of net.n2oapp.criteria.api.CollectionPage in project n2o-framework by i-novus-llc.

the class TestRestController method list.

@RequestMapping(value = "/test/rest", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public CollectionPage<TestRow> list(@RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam("sort") String sorting) {
    List<TestRow> list = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        int id = (page - 1) * size + i;
        TestRow testRestModel = new TestRow(id, String.valueOf(id));
        list.add(testRestModel);
    }
    String[] split = sorting.split(",");
    String field = split[0];
    if ("value".equals(field)) {
        String dir = split[1].toLowerCase();
        Comparator<TestRow> comparing = Comparator.comparing(TestRow::getValue);
        if ("desc".equals(dir))
            list.sort(comparing.reversed());
        else
            list.sort(comparing);
    }
    return new CollectionPage<>(50, list, new TestCriteria());
}
Also used : CollectionPage(net.n2oapp.criteria.api.CollectionPage) TestRow(net.n2oapp.framework.test.engine.TestRow) ArrayList(java.util.ArrayList) TestCriteria(net.n2oapp.framework.test.engine.TestCriteria)

Example 3 with CollectionPage

use of net.n2oapp.criteria.api.CollectionPage in project n2o-framework by i-novus-llc.

the class CollectionPageTest method testSizeZero.

@Test
public void testSizeZero() {
    Criteria criteria = new Criteria();
    CollectionPage page = new CollectionPage();
    page.setCriteria(criteria);
    criteria.setSize(0);
    page.init(3, Arrays.asList(1, 2, 3));
    assert page.getPages() == 1;
    criteria.setSize(0);
    page.init(30, Arrays.asList(1, 2, 3));
    assert page.getPages() == 1;
}
Also used : FilteredCollectionPage(net.n2oapp.criteria.api.FilteredCollectionPage) CollectionPage(net.n2oapp.criteria.api.CollectionPage) Criteria(net.n2oapp.criteria.api.Criteria) Test(org.junit.Test)

Example 4 with CollectionPage

use of net.n2oapp.criteria.api.CollectionPage in project n2o-framework by i-novus-llc.

the class CollectionPageTest method testCalcPages.

@Test
public void testCalcPages() {
    Criteria criteria = new Criteria();
    CollectionPage page = new CollectionPage();
    page.setCriteria(criteria);
    criteria.setSize(3);
    page.init(3, Arrays.asList(1, 2, 3));
    assert page.getPages() == 1;
    criteria.setSize(4);
    page.init(3, Arrays.asList(1, 2, 3));
    assert page.getPages() == 1;
    criteria.setSize(1);
    page.init(3, Arrays.asList(1, 2, 3));
    assert page.getPages() == 3;
    criteria.setSize(2);
    page.init(3, Arrays.asList(1, 2, 3));
    assert page.getPages() == 2;
}
Also used : FilteredCollectionPage(net.n2oapp.criteria.api.FilteredCollectionPage) CollectionPage(net.n2oapp.criteria.api.CollectionPage) Criteria(net.n2oapp.criteria.api.Criteria) Test(org.junit.Test)

Example 5 with CollectionPage

use of net.n2oapp.criteria.api.CollectionPage in project n2o-framework by i-novus-llc.

the class DataSetConverter method convert.

public static CollectionPage<DataSet> convert(CollectionPage collectionPage, Map<String, String> fieldsMapping) {
    Collection collection = collectionPage.getCollection();
    List<DataSet> dataSetPage = convert(collection, fieldsMapping);
    return new CollectionPage<>(collectionPage.getCount(), dataSetPage, collectionPage.getCriteria());
}
Also used : CollectionPage(net.n2oapp.criteria.api.CollectionPage) Collection(java.util.Collection)

Aggregations

CollectionPage (net.n2oapp.criteria.api.CollectionPage)5 Criteria (net.n2oapp.criteria.api.Criteria)3 Test (org.junit.Test)3 FilteredCollectionPage (net.n2oapp.criteria.api.FilteredCollectionPage)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 DataSet (net.n2oapp.criteria.dataset.DataSet)1 ModelLink (net.n2oapp.framework.api.metadata.meta.ModelLink)1 Page (net.n2oapp.framework.api.metadata.meta.page.Page)1 SimplePage (net.n2oapp.framework.api.metadata.meta.page.SimplePage)1 PageContext (net.n2oapp.framework.config.metadata.compile.context.PageContext)1 N2oSubModelsProcessor (net.n2oapp.framework.config.util.N2oSubModelsProcessor)1 TestCriteria (net.n2oapp.framework.test.engine.TestCriteria)1 TestRow (net.n2oapp.framework.test.engine.TestRow)1