Search in sources :

Example 1 with DocumentFilter

use of io.crnk.core.engine.filter.DocumentFilter in project crnk-framework by crnk-project.

the class MetaModule method setupModule.

@Override
public void setupModule(ModuleContext context) {
    this.context = context;
    informationBuilder = registerInformationBuilder(context.getPropertiesProvider());
    if (context.isServer()) {
        context.addFilter(new DocumentFilter() {

            @Override
            public Response filter(DocumentFilterContext filterRequestContext, DocumentFilterChain chain) {
                try {
                    return chain.doFilter(filterRequestContext);
                } finally {
                    lookupRequestLocal.remove();
                }
            }
        });
    } else {
        context.addResourceLookup(new ResourceLookup() {

            @SuppressWarnings("unchecked")
            @Override
            public Set<Class<?>> getResourceClasses() {
                return (Set) collectMetaClasses();
            }
        });
    }
}
Also used : Response(io.crnk.core.engine.dispatcher.Response) DocumentFilterContext(io.crnk.core.engine.filter.DocumentFilterContext) HashSet(java.util.HashSet) Set(java.util.Set) DocumentFilterChain(io.crnk.core.engine.filter.DocumentFilterChain) DocumentFilter(io.crnk.core.engine.filter.DocumentFilter) ResourceLookup(io.crnk.core.module.discovery.ResourceLookup)

Example 2 with DocumentFilter

use of io.crnk.core.engine.filter.DocumentFilter in project crnk-framework by crnk-project.

the class JsonApiActionResponseTest method setupFeature.

@Override
protected void setupFeature(CrnkTestFeature feature) {
    filter = Mockito.spy(new DocumentFilter() {

        @Override
        public Response filter(DocumentFilterContext filterRequestContext, DocumentFilterChain chain) {
            return chain.doFilter(filterRequestContext);
        }
    });
    SimpleModule testModule = new SimpleModule("testFilter");
    testModule.addFilter(filter);
    feature.addModule(testModule);
}
Also used : DocumentFilterContext(io.crnk.core.engine.filter.DocumentFilterContext) DocumentFilterChain(io.crnk.core.engine.filter.DocumentFilterChain) DocumentFilter(io.crnk.core.engine.filter.DocumentFilter) SimpleModule(io.crnk.core.module.SimpleModule)

Example 3 with DocumentFilter

use of io.crnk.core.engine.filter.DocumentFilter in project crnk-framework by crnk-project.

the class BasicActionTest method setupFeature.

@Override
protected void setupFeature(CrnkTestFeature feature) {
    filter = Mockito.spy(new DocumentFilter() {

        @Override
        public Response filter(DocumentFilterContext filterRequestContext, DocumentFilterChain chain) {
            return chain.doFilter(filterRequestContext);
        }
    });
    SimpleModule testModule = new SimpleModule("testFilter");
    testModule.addFilter(filter);
    feature.addModule(testModule);
}
Also used : DocumentFilterContext(io.crnk.core.engine.filter.DocumentFilterContext) DocumentFilterChain(io.crnk.core.engine.filter.DocumentFilterChain) DocumentFilter(io.crnk.core.engine.filter.DocumentFilter) SimpleModule(io.crnk.core.module.SimpleModule)

Example 4 with DocumentFilter

use of io.crnk.core.engine.filter.DocumentFilter in project crnk-framework by crnk-project.

the class CrnkBoot method setupComponents.

private void setupComponents() {
    // not that the provided default implementation here are added last and
    // as a consequence,
    // can be overriden by other modules, like the
    // JaxrsResourceRepositoryInformationBuilder.
    SimpleModule module = new SimpleModule("discovery") {

        @Override
        public void setupModule(ModuleContext context) {
            this.addHttpRequestProcessor(new JsonApiRequestProcessor(context));
            super.setupModule(context);
        }
    };
    for (JsonApiExceptionMapper<?> exceptionMapper : getInstancesByType(JsonApiExceptionMapper.class)) {
        module.addExceptionMapper(exceptionMapper);
    }
    for (DocumentFilter filter : getInstancesByType(DocumentFilter.class)) {
        module.addFilter(filter);
    }
    for (Object repository : getInstancesByType(Repository.class)) {
        module.addRepository(repository);
    }
    for (Object repository : serviceDiscovery.getInstancesByAnnotation(JsonApiResourceRepository.class)) {
        JsonApiResourceRepository annotation = ClassUtils.getAnnotation(repository.getClass(), JsonApiResourceRepository.class).get();
        Class<?> resourceClass = annotation.value();
        module.addRepository(resourceClass, repository);
    }
    for (Object repository : serviceDiscovery.getInstancesByAnnotation(JsonApiRelationshipRepository.class)) {
        JsonApiRelationshipRepository annotation = ClassUtils.getAnnotation(repository.getClass(), JsonApiRelationshipRepository.class).get();
        module.addRepository(annotation.source(), annotation.target(), repository);
    }
    moduleRegistry.addModule(module);
    moduleRegistry.addModule(new CoreModule());
}
Also used : JsonApiRequestProcessor(io.crnk.core.engine.internal.http.JsonApiRequestProcessor) JsonApiRelationshipRepository(io.crnk.legacy.repository.annotations.JsonApiRelationshipRepository) JsonApiResourceRepository(io.crnk.legacy.repository.annotations.JsonApiResourceRepository) DocumentFilter(io.crnk.core.engine.filter.DocumentFilter) CoreModule(io.crnk.core.engine.internal.CoreModule) SimpleModule(io.crnk.core.module.SimpleModule)

Example 5 with DocumentFilter

use of io.crnk.core.engine.filter.DocumentFilter in project crnk-framework by crnk-project.

the class CrnkBootTest method testServiceDiscovery.

@Test
public void testServiceDiscovery() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscoveryFactory(serviceDiscoveryFactory);
    boot.setServiceUrlProvider(mock(ServiceUrlProvider.class));
    Module module = mock(Module.class);
    DocumentFilter filter = mock(DocumentFilter.class);
    JsonApiExceptionMapper exceptionMapper = new TestExceptionMapper();
    Mockito.when(serviceDiscovery.getInstancesByType(eq(DocumentFilter.class))).thenReturn(Arrays.asList(filter));
    Mockito.when(serviceDiscovery.getInstancesByType(eq(Module.class))).thenReturn(Arrays.asList(module));
    Mockito.when(serviceDiscovery.getInstancesByType(eq(JsonApiExceptionMapper.class))).thenReturn(Arrays.asList(exceptionMapper));
    boot.boot();
    ModuleRegistry moduleRegistry = boot.getModuleRegistry();
    Assert.assertTrue(moduleRegistry.getModules().contains(module));
    Assert.assertTrue(moduleRegistry.getFilters().contains(filter));
    Assert.assertTrue(moduleRegistry.getExceptionMapperLookup().getExceptionMappers().contains(exceptionMapper));
}
Also used : ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ServiceUrlProvider(io.crnk.core.engine.url.ServiceUrlProvider) ModuleRegistry(io.crnk.core.module.ModuleRegistry) DocumentFilter(io.crnk.core.engine.filter.DocumentFilter) SimpleModule(io.crnk.core.module.SimpleModule) Module(io.crnk.core.module.Module) JsonApiExceptionMapper(io.crnk.core.engine.error.JsonApiExceptionMapper) Test(org.junit.Test)

Aggregations

DocumentFilter (io.crnk.core.engine.filter.DocumentFilter)6 SimpleModule (io.crnk.core.module.SimpleModule)4 DocumentFilterChain (io.crnk.core.engine.filter.DocumentFilterChain)3 DocumentFilterContext (io.crnk.core.engine.filter.DocumentFilterContext)3 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Response (io.crnk.core.engine.dispatcher.Response)1 JsonApiExceptionMapper (io.crnk.core.engine.error.JsonApiExceptionMapper)1 CoreModule (io.crnk.core.engine.internal.CoreModule)1 JsonApiRequestProcessor (io.crnk.core.engine.internal.http.JsonApiRequestProcessor)1 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)1 ServiceUrlProvider (io.crnk.core.engine.url.ServiceUrlProvider)1 Module (io.crnk.core.module.Module)1 ModuleRegistry (io.crnk.core.module.ModuleRegistry)1 ResourceLookup (io.crnk.core.module.discovery.ResourceLookup)1 JsonApiRelationshipRepository (io.crnk.legacy.repository.annotations.JsonApiRelationshipRepository)1 JsonApiResourceRepository (io.crnk.legacy.repository.annotations.JsonApiResourceRepository)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1