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"));*/
}
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());
}
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;
}
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;
}
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());
}
Aggregations