Search in sources :

Example 1 with N2oSubModelsProcessor

use of net.n2oapp.framework.config.util.N2oSubModelsProcessor in project n2o-framework by i-novus-llc.

the class PageBinderTest method resolveTableFilterSubModels.

/**
 * Разрешение вложенных моделей в фильтрах по url параметру
 */
@Test
public void resolveTableFilterSubModels() {
    N2oSubModelsProcessor subModelsProcessor = mock(N2oSubModelsProcessor.class);
    // мок subModelProcessor. Докидывает name в данные
    doAnswer(invocation -> {
        List<SubModelQuery> subModelQueries = invocation.getArgument(0);
        DataSet data = invocation.getArgument(1);
        if (subModelQueries.get(0).isMulti()) {
            List<DataSet> list = (List<DataSet>) data.get(subModelQueries.get(0).getSubModel());
            for (DataSet item : list) {
                item.put("name", "test" + item.get("id"));
            }
        } else {
            data.put(subModelQueries.get(0).getSubModel() + ".name", "test" + data.get(subModelQueries.get(0).getSubModel() + ".id"));
        }
        return null;
    }).when(subModelsProcessor).executeSubModels(anyListOf(SubModelQuery.class), anyObject());
    DataSet data = new DataSet();
    List<String> ids = new ArrayList<>();
    ids.add("1");
    ids.add("2");
    data.put("multiParam", ids);
    data.put("singleParam", "1");
    data.put("singleOptionParam", "1");
    data.put("multiFormParam", ids);
    data.put("singleFormParam", "1");
    data.put("singleOptionFormParam", "1");
    Page page = bind("net/n2oapp/framework/config/metadata/compile/page/submodels/testSubModels.page.xml", "net/n2oapp/framework/config/metadata/compile/page/submodels/testModel.query.xml", "net/n2oapp/framework/config/metadata/compile/page/submodels/testSubModel.query.xml").get(new PageContext("testSubModels"), data, subModelsProcessor);
    // single фильтр по умолчанию
    assertThat(((DefaultValues) page.getModels().get("filter['testSubModels_w0'].testSingleDefault").getValue()).getValues().get("name"), is("test1"));
    // multi фильтр по умолчанию
    assertThat(((DefaultValues) ((List) page.getModels().get("filter['testSubModels_w0'].testMultiDefault").getValue()).get(0)).getValues().get("name"), is("test1"));
    // single фильтр c options(значение test1 из Mock)
    assertThat(((DefaultValues) page.getModels().get("filter['testSubModels_w1'].testSingleOptions").getValue()).getValues().get("name"), is("test1"));
    // single фильтр по URL
    assertThat(((DefaultValues) page.getModels().get("filter['testSubModels_w1'].testSingleUrl").getValue()).getValues().get("name"), is("test1"));
    // multi фильтр по URL
    assertThat(((DefaultValues) ((List) page.getModels().get("filter['testSubModels_w1'].testMultiUrl").getValue()).get(0)).getValues().get("name"), is("test1"));
    assertThat(((DefaultValues) ((List) page.getModels().get("filter['testSubModels_w1'].testMultiUrl").getValue()).get(1)).getValues().get("name"), is("test2"));
    // single поле по умолчанию
    assertThat(((DefaultValues) page.getModels().get("resolve['testSubModels_w2'].testSingle").getValue()).getValues().get("name"), is("test1"));
    // multi поле по умолчанию
    assertThat(((DefaultValues) ((List) page.getModels().get("resolve['testSubModels_w2'].testMulti").getValue()).get(0)).getValues().get("name"), is("test1"));
    data.put("w0_testSingleDefault_id", "2");
    data.put("w0_testMultiDefault_id", Arrays.asList("2"));
    // single поле из параметров
    assertThat(((DefaultValues) page.getModels().get("resolve['testSubModels_w3'].testSingleOptionsForm").getValue()).getValues().get("name"), is("test1"));
    // single поле с options из параметров
    assertThat(((DefaultValues) page.getModels().get("resolve['testSubModels_w3'].testSingleUrlForm").getValue()).getValues().get("name"), is("test1"));
    // multi поле из параметров
    assertThat(((DefaultValues) ((List) page.getModels().get("resolve['testSubModels_w3'].testMultiUrlForm").getValue()).get(0)).getValues().get("name"), is("test1"));
    assertThat(((DefaultValues) ((List) page.getModels().get("resolve['testSubModels_w3'].testMultiUrlForm").getValue()).get(1)).getValues().get("name"), is("test2"));
    data.put("w0_testSingleDefault_id", "2");
    data.put("w0_testMultiDefault_id", Arrays.asList("2"));
    page = bind("net/n2oapp/framework/config/metadata/compile/page/submodels/testSubModels.page.xml", "net/n2oapp/framework/config/metadata/compile/page/submodels/testModel.query.xml", "net/n2oapp/framework/config/metadata/compile/page/submodels/testSubModel.query.xml").get(new PageContext("testSubModels"), data, subModelsProcessor);
    // Фильтры из URL перекрывают дефолтные значения
    assertThat(((DefaultValues) page.getModels().get("filter['testSubModels_w0'].testSingleDefault").getValue()).getValues().get("name"), is("test2"));
    assertThat(((DefaultValues) ((List) page.getModels().get("filter['testSubModels_w0'].testMultiDefault").getValue()).get(0)).getValues().get("name"), is("test2"));
    assertThat(((List) page.getModels().get("filter['testSubModels_w0'].testMultiDefault").getValue()).size(), is(1));
}
Also used : SubModelQuery(net.n2oapp.framework.api.metadata.local.view.widget.util.SubModelQuery) DataSet(net.n2oapp.criteria.dataset.DataSet) N2oSubModelsProcessor(net.n2oapp.framework.config.util.N2oSubModelsProcessor) DefaultValues(net.n2oapp.framework.api.metadata.meta.control.DefaultValues) Collections.singletonList(java.util.Collections.singletonList) CollectionPage(net.n2oapp.criteria.api.CollectionPage) Page(net.n2oapp.framework.api.metadata.meta.page.Page) SimplePage(net.n2oapp.framework.api.metadata.meta.page.SimplePage) PageContext(net.n2oapp.framework.config.metadata.compile.context.PageContext) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 2 with N2oSubModelsProcessor

use of net.n2oapp.framework.config.util.N2oSubModelsProcessor 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 3 with N2oSubModelsProcessor

use of net.n2oapp.framework.config.util.N2oSubModelsProcessor in project n2o-framework by i-novus-llc.

the class CopyValuesControllerTest method testQuery.

private GetDataResponse testQuery(String path, ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline> pipeline, Map<String, String[]> params) {
    N2oInvocationFactory invocationFactory = Mockito.mock(N2oInvocationFactory.class);
    TestDataProviderEngine testDataProviderEngine = new TestDataProviderEngine();
    testDataProviderEngine.setResourceLoader(new DefaultResourceLoader());
    Mockito.when(invocationFactory.produce(Mockito.any(Class.class))).thenReturn(testDataProviderEngine);
    ContextEngine contextEngine = Mockito.mock(ContextEngine.class);
    UserContext userContext = new UserContext(contextEngine);
    ContextProcessor contextProcessor = new ContextProcessor(userContext);
    N2oQueryProcessor queryProcessor = new N2oQueryProcessor(invocationFactory, new N2oQueryExceptionHandler());
    N2oEnvironment env = new N2oEnvironment();
    env.setContextProcessor(contextProcessor);
    queryProcessor.setEnvironment(env);
    N2oSubModelsProcessor subModelsProcessor = Mockito.mock(N2oSubModelsProcessor.class);
    Mockito.doNothing().when(subModelsProcessor);
    DataProcessingStack dataProcessingStack = Mockito.mock(SpringDataProcessingStack.class);
    CopyValuesController copyValuesController = new CopyValuesController(dataProcessingStack, queryProcessor, subModelsProcessor, null, null);
    Map<String, Object> map = new HashMap<>();
    map.put("CopyValuesController", copyValuesController);
    N2oRouter router = new N2oRouter(builder.getEnvironment(), pipeline);
    N2oControllerFactory factory = new N2oControllerFactory(map);
    factory.setEnvironment(builder.getEnvironment());
    DataController controller = new DataController(factory, builder.getEnvironment(), router);
    return controller.getData(path, params, userContext);
}
Also used : N2oInvocationFactory(net.n2oapp.framework.engine.data.N2oInvocationFactory) CopyValuesController(net.n2oapp.framework.ui.controller.query.CopyValuesController) SpringDataProcessingStack(net.n2oapp.framework.engine.modules.stack.SpringDataProcessingStack) DataProcessingStack(net.n2oapp.framework.engine.modules.stack.DataProcessingStack) HashMap(java.util.HashMap) UserContext(net.n2oapp.framework.api.user.UserContext) N2oSubModelsProcessor(net.n2oapp.framework.config.util.N2oSubModelsProcessor) TestDataProviderEngine(net.n2oapp.framework.engine.data.json.TestDataProviderEngine) ContextEngine(net.n2oapp.framework.api.context.ContextEngine) N2oQueryProcessor(net.n2oapp.framework.engine.data.N2oQueryProcessor) N2oEnvironment(net.n2oapp.framework.config.compile.pipeline.N2oEnvironment) N2oRouter(net.n2oapp.framework.config.register.route.N2oRouter) ContextProcessor(net.n2oapp.framework.api.context.ContextProcessor) N2oQueryExceptionHandler(net.n2oapp.framework.engine.data.N2oQueryExceptionHandler) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 4 with N2oSubModelsProcessor

use of net.n2oapp.framework.config.util.N2oSubModelsProcessor in project n2o-framework by i-novus-llc.

the class DefaultValuesControllerTest method testQuery.

private GetDataResponse testQuery(String path, ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline> pipeline, Map<String, String[]> params) {
    N2oInvocationFactory invocationFactory = Mockito.mock(N2oInvocationFactory.class);
    TestDataProviderEngine testDataProviderEngine = new TestDataProviderEngine();
    testDataProviderEngine.setResourceLoader(new DefaultResourceLoader());
    Mockito.when(invocationFactory.produce(Mockito.any(Class.class))).thenReturn(testDataProviderEngine);
    ContextEngine contextEngine = Mockito.mock(ContextEngine.class);
    UserContext userContext = new UserContext(contextEngine);
    ContextProcessor contextProcessor = new ContextProcessor(userContext);
    N2oQueryProcessor queryProcessor = new N2oQueryProcessor(invocationFactory, new N2oQueryExceptionHandler());
    N2oEnvironment env = new N2oEnvironment();
    env.setContextProcessor(contextProcessor);
    queryProcessor.setEnvironment(env);
    N2oSubModelsProcessor subModelsProcessor = Mockito.mock(N2oSubModelsProcessor.class);
    Mockito.doNothing().when(subModelsProcessor);
    DataProcessingStack dataProcessingStack = Mockito.mock(SpringDataProcessingStack.class);
    SimpleDefaultValuesController valuesController = new SimpleDefaultValuesController(dataProcessingStack, queryProcessor, subModelsProcessor, null, null);
    Map<String, Object> map = new HashMap<>();
    map.put("SimpleDefaultValuesController", valuesController);
    N2oRouter router = new N2oRouter(builder.getEnvironment(), pipeline);
    N2oControllerFactory factory = new N2oControllerFactory(map);
    factory.setEnvironment(builder.getEnvironment());
    DataController controller = new DataController(factory, builder.getEnvironment(), router);
    return controller.getData(path, params, userContext);
}
Also used : N2oInvocationFactory(net.n2oapp.framework.engine.data.N2oInvocationFactory) SpringDataProcessingStack(net.n2oapp.framework.engine.modules.stack.SpringDataProcessingStack) DataProcessingStack(net.n2oapp.framework.engine.modules.stack.DataProcessingStack) SimpleDefaultValuesController(net.n2oapp.framework.ui.controller.query.SimpleDefaultValuesController) HashMap(java.util.HashMap) UserContext(net.n2oapp.framework.api.user.UserContext) N2oSubModelsProcessor(net.n2oapp.framework.config.util.N2oSubModelsProcessor) TestDataProviderEngine(net.n2oapp.framework.engine.data.json.TestDataProviderEngine) ContextEngine(net.n2oapp.framework.api.context.ContextEngine) N2oQueryProcessor(net.n2oapp.framework.engine.data.N2oQueryProcessor) N2oEnvironment(net.n2oapp.framework.config.compile.pipeline.N2oEnvironment) N2oRouter(net.n2oapp.framework.config.register.route.N2oRouter) ContextProcessor(net.n2oapp.framework.api.context.ContextProcessor) N2oQueryExceptionHandler(net.n2oapp.framework.engine.data.N2oQueryExceptionHandler) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 5 with N2oSubModelsProcessor

use of net.n2oapp.framework.config.util.N2oSubModelsProcessor in project n2o-framework by i-novus-llc.

the class N2oEngineConfiguration method subModelsProcessor.

@Bean
@ConditionalOnMissingBean
public SubModelsProcessor subModelsProcessor(QueryProcessor queryProcessor, MetadataEnvironment environment, DomainProcessor domainProcessor) {
    N2oSubModelsProcessor n2oSubModelsProcessor = new N2oSubModelsProcessor(queryProcessor, domainProcessor);
    n2oSubModelsProcessor.setEnvironment(environment);
    return n2oSubModelsProcessor;
}
Also used : N2oSubModelsProcessor(net.n2oapp.framework.config.util.N2oSubModelsProcessor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

N2oSubModelsProcessor (net.n2oapp.framework.config.util.N2oSubModelsProcessor)13 DataSet (net.n2oapp.criteria.dataset.DataSet)8 Test (org.junit.Test)7 SubModelQuery (net.n2oapp.framework.api.metadata.local.view.widget.util.SubModelQuery)6 ModelLink (net.n2oapp.framework.api.metadata.meta.ModelLink)6 PageContext (net.n2oapp.framework.config.metadata.compile.context.PageContext)6 HashMap (java.util.HashMap)4 Page (net.n2oapp.framework.api.metadata.meta.page.Page)4 CollectionPage (net.n2oapp.criteria.api.CollectionPage)3 DefaultValues (net.n2oapp.framework.api.metadata.meta.control.DefaultValues)3 SimplePage (net.n2oapp.framework.api.metadata.meta.page.SimplePage)3 N2oEnvironment (net.n2oapp.framework.config.compile.pipeline.N2oEnvironment)3 List (java.util.List)2 ContextEngine (net.n2oapp.framework.api.context.ContextEngine)2 ContextProcessor (net.n2oapp.framework.api.context.ContextProcessor)2 BindLink (net.n2oapp.framework.api.metadata.meta.BindLink)2 UserContext (net.n2oapp.framework.api.user.UserContext)2 N2oRouter (net.n2oapp.framework.config.register.route.N2oRouter)2 N2oInvocationFactory (net.n2oapp.framework.engine.data.N2oInvocationFactory)2 N2oQueryExceptionHandler (net.n2oapp.framework.engine.data.N2oQueryExceptionHandler)2