Search in sources :

Example 1 with RepositoryInformationProvider

use of io.crnk.core.engine.information.repository.RepositoryInformationProvider 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 RepositoryInformationProvider

use of io.crnk.core.engine.information.repository.RepositoryInformationProvider 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 RepositoryInformationProvider

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

the class ModuleRegistryTest method repositoryInformationBuilderAccept.

@Test
public void repositoryInformationBuilderAccept() {
    RepositoryInformationProvider builder = moduleRegistry.getRepositoryInformationBuilder();
    Assert.assertFalse(builder.accept("no resource"));
    Assert.assertFalse(builder.accept(String.class));
    Assert.assertTrue(builder.accept(TaskRepository.class));
    Assert.assertTrue(builder.accept(ProjectRepository.class));
    Assert.assertTrue(builder.accept(TaskToProjectRepository.class));
    Assert.assertTrue(builder.accept(new TaskRepository()));
    Assert.assertTrue(builder.accept(new TaskToProjectRepository()));
}
Also used : RepositoryInformationProvider(io.crnk.core.engine.information.repository.RepositoryInformationProvider) Test(org.junit.Test)

Example 4 with RepositoryInformationProvider

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

the class ModuleRegistryTest method buildResourceRepositoryInformationFromInstance.

@Test
public void buildResourceRepositoryInformationFromInstance() {
    RepositoryInformationProvider builder = moduleRegistry.getRepositoryInformationBuilder();
    ResourceRepositoryInformation info = (ResourceRepositoryInformation) builder.build(new TaskRepository(), newRepositoryInformationBuilderContext());
    Assert.assertEquals(Task.class, info.getResourceInformation().get().getResourceClass());
    Assert.assertEquals("tasks", info.getPath());
}
Also used : ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) RepositoryInformationProvider(io.crnk.core.engine.information.repository.RepositoryInformationProvider) Test(org.junit.Test)

Example 5 with RepositoryInformationProvider

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

the class ModuleRegistryTest method buildResourceRepositoryInformationFromClass.

@Test
public void buildResourceRepositoryInformationFromClass() {
    RepositoryInformationProvider builder = moduleRegistry.getRepositoryInformationBuilder();
    ResourceRepositoryInformation info = (ResourceRepositoryInformation) builder.build(TaskRepository.class, newRepositoryInformationBuilderContext());
    Assert.assertEquals(Task.class, info.getResourceInformation().get().getResourceClass());
    Assert.assertEquals("tasks", info.getPath());
}
Also used : ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) RepositoryInformationProvider(io.crnk.core.engine.information.repository.RepositoryInformationProvider) Test(org.junit.Test)

Aggregations

RepositoryInformationProvider (io.crnk.core.engine.information.repository.RepositoryInformationProvider)6 ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)5 DefaultRepositoryInformationProviderContext (io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext)3 Test (org.junit.Test)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