Search in sources :

Example 1 with ResourceLookup

use of io.crnk.core.module.discovery.ResourceLookup 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 ResourceLookup

use of io.crnk.core.module.discovery.ResourceLookup in project crnk-framework by crnk-project.

the class ModuleRegistryTest method testResourceLookup.

@Test
public void testResourceLookup() throws Exception {
    ResourceLookup resourceLookup = moduleRegistry.getResourceLookup();
    Assert.assertFalse(resourceLookup.getResourceClasses().contains(Object.class));
    Assert.assertFalse(resourceLookup.getResourceClasses().contains(String.class));
    Assert.assertTrue(resourceLookup.getResourceClasses().contains(TestResource.class));
}
Also used : ResourceLookup(io.crnk.core.module.discovery.ResourceLookup) Test(org.junit.Test)

Aggregations

ResourceLookup (io.crnk.core.module.discovery.ResourceLookup)2 Response (io.crnk.core.engine.dispatcher.Response)1 DocumentFilter (io.crnk.core.engine.filter.DocumentFilter)1 DocumentFilterChain (io.crnk.core.engine.filter.DocumentFilterChain)1 DocumentFilterContext (io.crnk.core.engine.filter.DocumentFilterContext)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Test (org.junit.Test)1