Search in sources :

Example 1 with ModuleRegistry

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

the class CrnkClient method setProxyFactory.

public void setProxyFactory(ClientProxyFactory proxyFactory) {
    proxyFactory.init(new ClientProxyFactoryContext() {

        @Override
        public ModuleRegistry getModuleRegistry() {
            return moduleRegistry;
        }

        @Override
        public <T> DefaultResourceList<T> getCollection(Class<T> resourceClass, String url) {
            RegistryEntry entry = resourceRegistry.findEntry(resourceClass);
            ResourceInformation resourceInformation = entry.getResourceInformation();
            final ResourceRepositoryStubImpl<T, ?> repositoryStub = new ResourceRepositoryStubImpl<>(CrnkClient.this, resourceClass, resourceInformation, urlBuilder);
            return repositoryStub.findAll(url);
        }
    });
    documentMapper.setProxyFactory(proxyFactory);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRepositoryStubImpl(io.crnk.client.internal.ResourceRepositoryStubImpl) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ClientProxyFactoryContext(io.crnk.client.internal.proxy.ClientProxyFactoryContext)

Example 2 with ModuleRegistry

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

the class RegistryEntryTest method newRepositoryInformation.

private <T> ResourceRepositoryInformation newRepositoryInformation(Class<T> repositoryClass, String path) {
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    TypeParser typeParser = moduleRegistry.getTypeParser();
    return new ResourceRepositoryInformationImpl(path, new ResourceInformation(typeParser, Task.class, path, null, null, null, null), RepositoryMethodAccess.ALL);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Task(io.crnk.core.mock.models.Task) TypeParser(io.crnk.core.engine.parser.TypeParser) ResourceRepositoryInformationImpl(io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl) ModuleRegistry(io.crnk.core.module.ModuleRegistry)

Example 3 with ModuleRegistry

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

the class CdiRunner method run.

public void run(GeneratorTrigger context) throws IOException {
    Weld weld = new Weld();
    try {
        weld.setClassLoader(context.getClassLoader());
        weld.initialize();
        CrnkBoot boot = new CrnkBoot();
        boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://<generator>"));
        boot.boot();
        ModuleRegistry moduleRegistry = boot.getModuleRegistry();
        Optional<MetaModule> optionalModule = moduleRegistry.getModule(MetaModule.class);
        if (!optionalModule.isPresent()) {
            throw new IllegalStateException("add MetaModule to CDI setup, got: " + moduleRegistry.getModules() + " with " + boot.getServiceDiscovery());
        }
        MetaModule metaModule = optionalModule.get();
        MetaLookup lookup = metaModule.getLookup();
        context.generate(lookup);
    } finally {
        weld.shutdown();
    }
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) MetaLookup(io.crnk.meta.MetaLookup) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) MetaModule(io.crnk.meta.MetaModule) Weld(org.jboss.weld.environment.se.Weld)

Example 4 with ModuleRegistry

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

the class ResourceRegistryTest method resetResourceRegistry.

@Before
public void resetResourceRegistry() {
    moduleRegistry = new ModuleRegistry();
    moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider(TEST_MODELS_URL));
    resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
}
Also used : ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) Before(org.junit.Before)

Example 5 with ModuleRegistry

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

the class QueryParamsAdapterTest method test.

@Test
public void test() {
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
    ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
    QueryParams params = new QueryParams();
    DefaultResourceInformationProvider builder = new DefaultResourceInformationProvider(new NullPropertiesProvider(), new OffsetLimitPagingBehavior(), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
    builder.init(new DefaultResourceInformationProviderContext(builder, new DefaultInformationBuilder(moduleRegistry.getTypeParser()), moduleRegistry.getTypeParser(), new ObjectMapper()));
    ResourceInformation info = builder.build(Task.class);
    QueryParamsAdapter adapter = new QueryParamsAdapter(info, params, moduleRegistry);
    Assert.assertEquals(Task.class, adapter.getResourceInformation().getResourceClass());
    Assert.assertEquals(resourceRegistry, adapter.getResourceRegistry());
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) DefaultResourceInformationProviderContext(io.crnk.legacy.registry.DefaultResourceInformationProviderContext) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JacksonResourceFieldInformationProvider(io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) QueryParamsAdapter(io.crnk.legacy.internal.QueryParamsAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultResourceFieldInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider) Test(org.junit.Test)

Aggregations

ModuleRegistry (io.crnk.core.module.ModuleRegistry)13 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)6 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)6 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)5 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)5 Before (org.junit.Before)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)4 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)4 Test (org.junit.Test)4 TypeParser (io.crnk.core.engine.parser.TypeParser)3 CoreModule (io.crnk.core.engine.internal.CoreModule)2 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)2 ResourceRepositoryInformationImpl (io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl)2 DefaultResourceFieldInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)2 DefaultResourceInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider)2 JacksonModule (io.crnk.core.engine.internal.jackson.JacksonModule)2 JacksonResourceFieldInformationProvider (io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider)2 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 Task (io.crnk.core.mock.models.Task)2