Search in sources :

Example 11 with ResourceRepositoryInformation

use of io.crnk.core.engine.information.repository.ResourceRepositoryInformation in project crnk-framework by crnk-project.

the class CrnkClient method getRepositoryForInterface.

@SuppressWarnings("unchecked")
public <R extends ResourceRepositoryV2<?, ?>> R getRepositoryForInterface(Class<R> repositoryInterfaceClass) {
    init();
    RepositoryInformationProvider informationBuilder = moduleRegistry.getRepositoryInformationBuilder();
    PreconditionUtil.assertTrue("no a valid repository interface", informationBuilder.accept(repositoryInterfaceClass));
    ResourceRepositoryInformation repositoryInformation = (ResourceRepositoryInformation) informationBuilder.build(repositoryInterfaceClass, new DefaultRepositoryInformationProviderContext(moduleRegistry));
    Class<?> resourceClass = repositoryInformation.getResourceInformation().get().getResourceClass();
    Object actionStub = actionStubFactory != null ? actionStubFactory.createStub(repositoryInterfaceClass) : null;
    ResourceRepositoryV2<?, Serializable> repositoryStub = getQuerySpecRepository(resourceClass);
    ClassLoader classLoader = repositoryInterfaceClass.getClassLoader();
    InvocationHandler invocationHandler = new ClientStubInvocationHandler(repositoryInterfaceClass, repositoryStub, actionStub);
    return (R) Proxy.newProxyInstance(classLoader, new Class[] { repositoryInterfaceClass, ResourceRepositoryV2.class }, invocationHandler);
}
Also used : Serializable(java.io.Serializable) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) ClientStubInvocationHandler(io.crnk.client.internal.ClientStubInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) ClientStubInvocationHandler(io.crnk.client.internal.ClientStubInvocationHandler) DefaultRepositoryInformationProviderContext(io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext) RepositoryInformationProvider(io.crnk.core.engine.information.repository.RepositoryInformationProvider)

Example 12 with ResourceRepositoryInformation

use of io.crnk.core.engine.information.repository.ResourceRepositoryInformation in project crnk-framework by crnk-project.

the class DefaultInformationBuilderTest method checkResourceRepository.

@Test
public void checkResourceRepository() {
    ResourceInformation resourceInformation = builder.createResource(Task.class, "tasks").build();
    InformationBuilder.ResourceRepository repositoryBuilder = builder.createResourceRepository();
    repositoryBuilder.setResourceInformation(resourceInformation);
    RepositoryMethodAccess expectedAccess = new RepositoryMethodAccess(true, false, true, false);
    repositoryBuilder.setAccess(expectedAccess);
    ResourceRepositoryInformation repositoryInformation = repositoryBuilder.build();
    RepositoryMethodAccess actualAccess = repositoryInformation.getAccess();
    Assert.assertEquals(expectedAccess, actualAccess);
    Assert.assertSame(resourceInformation, repositoryInformation.getResourceInformation().get());
}
Also used : InformationBuilder(io.crnk.core.engine.information.InformationBuilder) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Task(io.crnk.core.mock.models.Task) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) RepositoryMethodAccess(io.crnk.core.engine.information.repository.RepositoryMethodAccess) Test(org.junit.Test)

Aggregations

ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)12 Test (org.junit.Test)5 RepositoryInformationProvider (io.crnk.core.engine.information.repository.RepositoryInformationProvider)4 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)4 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)4 DirectResponseResourceEntry (io.crnk.legacy.internal.DirectResponseResourceEntry)3 RepositoryInstanceBuilder (io.crnk.legacy.registry.RepositoryInstanceBuilder)3 Serializable (java.io.Serializable)3 RepositoryAction (io.crnk.core.engine.information.repository.RepositoryAction)2 ResourceField (io.crnk.core.engine.information.resource.ResourceField)2 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)2 DefaultRepositoryInformationProviderContext (io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext)2 DirectResponseRelationshipEntry (io.crnk.legacy.internal.DirectResponseRelationshipEntry)2 ClientStubInvocationHandler (io.crnk.client.internal.ClientStubInvocationHandler)1 ResourceRepositoryStubImpl (io.crnk.client.internal.ResourceRepositoryStubImpl)1 CrnkBoot (io.crnk.core.boot.CrnkBoot)1 InformationBuilder (io.crnk.core.engine.information.InformationBuilder)1 RepositoryInformationProviderContext (io.crnk.core.engine.information.repository.RepositoryInformationProviderContext)1 RepositoryMethodAccess (io.crnk.core.engine.information.repository.RepositoryMethodAccess)1 ResourceInformationProvider (io.crnk.core.engine.information.resource.ResourceInformationProvider)1