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