Search in sources :

Example 1 with DefaultRepositoryInformationProviderContext

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

the class DefaultRegistryEntryBuilder method findRelationshipMatch.

private ResponseRelationshipEntry findRelationshipMatch(ResourceField relationshipField) {
    Collection<Object> repositories = moduleRegistry.getRepositories();
    RepositoryInformationProvider repositoryInformationBuilder = moduleRegistry.getRepositoryInformationBuilder();
    ResponseRelationshipEntry matchedEntry = null;
    for (Object repository : repositories) {
        RepositoryInformation repositoryInformation = repositoryInformationBuilder.build(repository, new DefaultRepositoryInformationProviderContext(moduleRegistry));
        if (repositoryInformation instanceof RelationshipRepositoryInformation) {
            RelationshipRepositoryInformation relationshipRepositoryInformation = (RelationshipRepositoryInformation) repositoryInformation;
            RelationshipMatcher matcher = relationshipRepositoryInformation.getMatcher();
            if (matcher.matches(relationshipField)) {
                if (matchedEntry != null) {
                    throw new IllegalStateException("multiple repositories for " + relationshipField + ": " + repository + ", " + matchedEntry);
                }
                matcher.matches(relationshipField);
                matchedEntry = setupRelationship(relationshipField, relationshipRepositoryInformation, repository);
            }
        }
    }
    return matchedEntry;
}
Also used : RelationshipRepositoryInformation(io.crnk.core.engine.information.repository.RelationshipRepositoryInformation) ResponseRelationshipEntry(io.crnk.core.engine.registry.ResponseRelationshipEntry) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) DefaultRepositoryInformationProviderContext(io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext) RepositoryInformationProvider(io.crnk.core.engine.information.repository.RepositoryInformationProvider) RelationshipMatcher(io.crnk.core.repository.RelationshipMatcher) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) RepositoryInformation(io.crnk.core.engine.information.repository.RepositoryInformation) RelationshipRepositoryInformation(io.crnk.core.engine.information.repository.RelationshipRepositoryInformation)

Example 2 with DefaultRepositoryInformationProviderContext

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

the class DefaultRegistryEntryBuilder method fromImplementation.

@Override
public void fromImplementation(Object repository) {
    RepositoryInformationProvider repositoryInformationBuilder = moduleRegistry.getRepositoryInformationBuilder();
    RepositoryInformationProviderContext builderContext = new DefaultRepositoryInformationProviderContext(moduleRegistry);
    ResourceRepositoryInformation repositoryInformation = (ResourceRepositoryInformation) repositoryInformationBuilder.build(repository, builderContext);
    ResourceInformation resourceInformation = repositoryInformation.getResourceInformation().get();
    resource().from(resourceInformation);
    resourceRepository().information().from(repositoryInformation);
    resourceRepository().instance(repository);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) DefaultRepositoryInformationProviderContext(io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext) DefaultRepositoryInformationProviderContext(io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext) RepositoryInformationProviderContext(io.crnk.core.engine.information.repository.RepositoryInformationProviderContext) RepositoryInformationProvider(io.crnk.core.engine.information.repository.RepositoryInformationProvider)

Example 3 with DefaultRepositoryInformationProviderContext

use of io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext 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)

Aggregations

RepositoryInformationProvider (io.crnk.core.engine.information.repository.RepositoryInformationProvider)3 ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)3 DefaultRepositoryInformationProviderContext (io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext)3 ClientStubInvocationHandler (io.crnk.client.internal.ClientStubInvocationHandler)1 RelationshipRepositoryInformation (io.crnk.core.engine.information.repository.RelationshipRepositoryInformation)1 RepositoryInformation (io.crnk.core.engine.information.repository.RepositoryInformation)1 RepositoryInformationProviderContext (io.crnk.core.engine.information.repository.RepositoryInformationProviderContext)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 ResponseRelationshipEntry (io.crnk.core.engine.registry.ResponseRelationshipEntry)1 RelationshipMatcher (io.crnk.core.repository.RelationshipMatcher)1 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)1 DirectResponseRelationshipEntry (io.crnk.legacy.internal.DirectResponseRelationshipEntry)1 Serializable (java.io.Serializable)1 InvocationHandler (java.lang.reflect.InvocationHandler)1