Search in sources :

Example 1 with ContextProcessor

use of net.n2oapp.framework.api.context.ContextProcessor in project n2o-framework by i-novus-llc.

the class InvocationProcessorTest method setUp.

@Before
public void setUp() throws Exception {
    N2oInvocationFactory actionInvocationFactory = mock(N2oInvocationFactory.class);
    javaDataProviderEngine = new JavaDataProviderEngine();
    when(actionInvocationFactory.produce(N2oJavaDataProvider.class)).thenReturn(javaDataProviderEngine);
    SqlInvocationEngine sqlInvocationEngine = new SqlInvocationEngine();
    when(actionInvocationFactory.produce(N2oSqlDataProvider.class)).thenReturn(sqlInvocationEngine);
    TestDataProviderEngine testDataProviderEngine = new TestDataProviderEngine();
    when(actionInvocationFactory.produce(N2oTestDataProvider.class)).thenReturn(testDataProviderEngine);
    ContextProcessor processor = mock(ContextProcessor.class);
    when(processor.resolve(anyMap())).thenAnswer((Answer<DataSet>) invocation -> (DataSet) invocation.getArguments()[0]);
    when(processor.resolve(anyString())).thenAnswer((Answer<String>) invocation -> (String) invocation.getArguments()[0]);
    when(processor.resolve(anyInt())).thenAnswer((Answer<Integer>) invocation -> (Integer) invocation.getArguments()[0]);
    when(processor.resolve(anyList())).thenAnswer((Answer<List>) invocation -> (List) invocation.getArguments()[0]);
    when(processor.resolve(anyBoolean())).thenAnswer((Answer<Boolean>) invocation -> (Boolean) invocation.getArguments()[0]);
    N2oEnvironment env = new N2oEnvironment();
    env.setContextProcessor(processor);
    invocationProcessor = new N2oInvocationProcessor(actionInvocationFactory);
    invocationProcessor.setEnvironment(env);
}
Also used : N2oInvocationFactory(net.n2oapp.framework.engine.data.N2oInvocationFactory) java.util(java.util) N2oJavaDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider) N2oSqlDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oSqlDataProvider) ArgumentMatchers(org.mockito.ArgumentMatchers) DataSet(net.n2oapp.criteria.dataset.DataSet) ObjectSetField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSetField) Matchers.anyString(org.mockito.Matchers.anyString) ObjectListField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectListField) ContextProcessor(net.n2oapp.framework.api.context.ContextProcessor) Answer(org.mockito.stubbing.Answer) JavaDataProviderEngine(net.n2oapp.framework.engine.data.java.JavaDataProviderEngine) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ObjectReferenceField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectReferenceField) MapInvocationEngine(net.n2oapp.framework.api.data.MapInvocationEngine) N2oEnvironment(net.n2oapp.framework.config.compile.pipeline.N2oEnvironment) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AbstractParameter(net.n2oapp.framework.api.metadata.global.dao.object.AbstractParameter) Before(org.junit.Before) N2oInvocationFactory(net.n2oapp.framework.engine.data.N2oInvocationFactory) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) N2oInvocationProcessor(net.n2oapp.framework.engine.data.N2oInvocationProcessor) ObjectSimpleField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField) N2oTestDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oTestDataProvider) TestDataProviderEngine(net.n2oapp.framework.engine.data.json.TestDataProviderEngine) TestEntity(net.n2oapp.framework.engine.util.TestEntity) Argument(net.n2oapp.framework.api.metadata.global.dao.invocation.model.Argument) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) DataSet(net.n2oapp.criteria.dataset.DataSet) TestDataProviderEngine(net.n2oapp.framework.engine.data.json.TestDataProviderEngine) Matchers.anyString(org.mockito.Matchers.anyString) N2oInvocationProcessor(net.n2oapp.framework.engine.data.N2oInvocationProcessor) JavaDataProviderEngine(net.n2oapp.framework.engine.data.java.JavaDataProviderEngine) N2oEnvironment(net.n2oapp.framework.config.compile.pipeline.N2oEnvironment) ContextProcessor(net.n2oapp.framework.api.context.ContextProcessor) Before(org.junit.Before)

Example 2 with ContextProcessor

use of net.n2oapp.framework.api.context.ContextProcessor 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 3 with ContextProcessor

use of net.n2oapp.framework.api.context.ContextProcessor 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 4 with ContextProcessor

use of net.n2oapp.framework.api.context.ContextProcessor in project n2o-framework by i-novus-llc.

the class ContextProcessorTest method setUp.

@Before
public void setUp() throws Exception {
    Context service = new ContextMock();
    processor = new ContextProcessor(service);
}
Also used : Context(net.n2oapp.framework.api.context.Context) ContextProcessor(net.n2oapp.framework.api.context.ContextProcessor) Before(org.junit.Before)

Example 5 with ContextProcessor

use of net.n2oapp.framework.api.context.ContextProcessor in project n2o-framework by i-novus-llc.

the class SecurityProvider method checkRestrictions.

/**
 * Вызывает исключение, если данные не удовлетворяют фильтрам доступа
 * @param data Данные
 * @param securityFilters Фильтры доступа
 * @param userContext Контекст пользователя
 */
public void checkRestrictions(DataSet data, SecurityFilters securityFilters, UserContext userContext) {
    List<Restriction> restrictions = collectRestrictions(securityFilters, userContext);
    ContextProcessor contextProcessor = new ContextProcessor(userContext);
    for (Restriction securityRestriction : restrictions) {
        Object realValue = data.get(securityRestriction.getFieldId());
        if (realValue != null || strictFiltering) {
            if (FilterType.Arity.nullary.equals(securityRestriction.getType().arity)) {
                Filter securityFilter = new Filter(securityRestriction.getType());
                checkByField(securityRestriction.getFieldId(), realValue, securityFilter);
            } else {
                Object filterValue = contextProcessor.resolve(securityRestriction.getValue());
                if (filterValue != null) {
                    Filter securityFilter = new Filter(filterValue, securityRestriction.getType());
                    checkByField(securityRestriction.getFieldId(), realValue, securityFilter);
                }
            }
        }
    }
}
Also used : Restriction(net.n2oapp.framework.api.criteria.Restriction) N2oObjectFilter(net.n2oapp.framework.access.metadata.accesspoint.model.N2oObjectFilter) Filter(net.n2oapp.criteria.filters.Filter) ContextProcessor(net.n2oapp.framework.api.context.ContextProcessor)

Aggregations

ContextProcessor (net.n2oapp.framework.api.context.ContextProcessor)9 Test (org.junit.Test)5 N2oEnvironment (net.n2oapp.framework.config.compile.pipeline.N2oEnvironment)4 N2oInvocationFactory (net.n2oapp.framework.engine.data.N2oInvocationFactory)4 TestDataProviderEngine (net.n2oapp.framework.engine.data.json.TestDataProviderEngine)4 DataSet (net.n2oapp.criteria.dataset.DataSet)3 N2oQueryExceptionHandler (net.n2oapp.framework.engine.data.N2oQueryExceptionHandler)3 N2oQueryProcessor (net.n2oapp.framework.engine.data.N2oQueryProcessor)3 Before (org.junit.Before)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 Context (net.n2oapp.framework.api.context.Context)2 ContextEngine (net.n2oapp.framework.api.context.ContextEngine)2 Restriction (net.n2oapp.framework.api.criteria.Restriction)2 UserContext (net.n2oapp.framework.api.user.UserContext)2 N2oRouter (net.n2oapp.framework.config.register.route.N2oRouter)2 N2oSubModelsProcessor (net.n2oapp.framework.config.util.N2oSubModelsProcessor)2