Search in sources :

Example 1 with ResourceInformationProvider

use of io.crnk.core.engine.information.resource.ResourceInformationProvider in project crnk-framework by crnk-project.

the class CrnkClient method allocateRepository.

@SuppressWarnings({ "rawtypes", "unchecked" })
private <T, I extends Serializable> RegistryEntry allocateRepository(Class<T> resourceClass) {
    ResourceInformationProvider resourceInformationProvider = moduleRegistry.getResourceInformationBuilder();
    ResourceInformation resourceInformation = resourceInformationProvider.build(resourceClass);
    final ResourceRepositoryStub<T, I> repositoryStub = new ResourceRepositoryStubImpl<>(this, resourceClass, resourceInformation, urlBuilder);
    // create interface for it!
    RepositoryInstanceBuilder repositoryInstanceBuilder = new RepositoryInstanceBuilder(null, null) {

        @Override
        public Object buildRepository() {
            return repositoryStub;
        }
    };
    ResourceRepositoryInformation repositoryInformation = new ResourceRepositoryInformationImpl(resourceInformation.getResourceType(), resourceInformation, RepositoryMethodAccess.ALL);
    ResourceEntry resourceEntry = new DirectResponseResourceEntry(repositoryInstanceBuilder, repositoryInformation);
    Map<ResourceField, ResponseRelationshipEntry> relationshipEntries = new HashMap<>();
    RegistryEntry registryEntry = new RegistryEntry(resourceEntry, relationshipEntries);
    registryEntry.initialize(moduleRegistry);
    resourceRegistry.addEntry(resourceClass, registryEntry);
    allocateRepositoryRelations(registryEntry);
    return registryEntry;
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceRepositoryStubImpl(io.crnk.client.internal.ResourceRepositoryStubImpl) ResourceRepositoryInformationImpl(io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder)

Example 2 with ResourceInformationProvider

use of io.crnk.core.engine.information.resource.ResourceInformationProvider in project crnk-framework by crnk-project.

the class ResourceMetaFilter method getResourceInformation.

private ResourceInformation getResourceInformation(MetaResourceBase meta, boolean allowNull) {
    ResourceRegistry resourceRegistry = context.getModuleContext().getResourceRegistry();
    if (meta instanceof MetaResource) {
        RegistryEntry entry = resourceRegistry.getEntry(((MetaResource) meta).getResourceType());
        if (entry != null) {
            return entry.getResourceInformation();
        }
    }
    Class<?> resourceClass = meta.getImplementationClass();
    ResourceInformationProvider infoBuilder = context.getModuleContext().getResourceInformationBuilder();
    if (infoBuilder.accept(resourceClass)) {
        return infoBuilder.build(resourceClass);
    }
    if (allowNull) {
        return null;
    }
    throw new IllegalStateException("failed to get information for " + resourceClass.getName());
}
Also used : MetaResource(io.crnk.meta.model.resource.MetaResource) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 3 with ResourceInformationProvider

use of io.crnk.core.engine.information.resource.ResourceInformationProvider in project crnk-framework by crnk-project.

the class ModuleRegistryTest method testInformationBuilder.

@Test
public void testInformationBuilder() throws Exception {
    ResourceInformationProvider informationProvider = moduleRegistry.getResourceInformationBuilder();
    Assert.assertTrue(informationProvider.accept(ComplexPojo.class));
    Assert.assertTrue(informationProvider.accept(Document.class));
    Assert.assertTrue(informationProvider.accept(FancyProject.class));
    Assert.assertTrue(informationProvider.accept(Project.class));
    Assert.assertTrue(informationProvider.accept(Task.class));
    Assert.assertTrue(informationProvider.accept(Thing.class));
    Assert.assertTrue(informationProvider.accept(User.class));
    Assert.assertTrue(informationProvider.accept(TestResource.class));
    Assert.assertFalse(informationProvider.accept(TestRepository.class));
    Assert.assertFalse(informationProvider.accept(DocumentRepository.class));
    Assert.assertFalse(informationProvider.accept(PojoRepository.class));
    Assert.assertFalse(informationProvider.accept(ProjectRepository.class));
    Assert.assertFalse(informationProvider.accept(ResourceWithoutRepositoryToProjectRepository.class));
    Assert.assertFalse(informationProvider.accept(TaskToProjectRepository.class));
    Assert.assertFalse(informationProvider.accept(TaskWithLookupRepository.class));
    Assert.assertFalse(informationProvider.accept(UserRepository.class));
    Assert.assertFalse(informationProvider.accept(UserToProjectRepository.class));
    Assert.assertFalse(informationProvider.accept(Object.class));
    Assert.assertFalse(informationProvider.accept(String.class));
    try {
        informationProvider.build(Object.class);
        Assert.fail();
    } catch (UnsupportedOperationException e) {
    // ok
    }
    ResourceInformation userInfo = informationProvider.build(User.class);
    Assert.assertEquals("id", userInfo.getIdField().getUnderlyingName());
    ResourceInformation testInfo = informationProvider.build(TestResource.class);
    Assert.assertEquals("id", testInfo.getIdField().getUnderlyingName());
    // setup by TestResourceInformationProvider
    Assert.assertEquals("testId", testInfo.getIdField().getJsonName());
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) Test(org.junit.Test)

Example 4 with ResourceInformationProvider

use of io.crnk.core.engine.information.resource.ResourceInformationProvider in project crnk-framework by crnk-project.

the class DefaultResourceInformationProviderTest method shouldInheritGlobalForDefaultLookupBehaviorWhenDefault.

@Test
public void shouldInheritGlobalForDefaultLookupBehaviorWhenDefault() throws Exception {
    ResourceInformationProvider resourceInformationProviderWithProperty = getResourceInformationProviderWithProperty(CrnkProperties.INCLUDE_AUTOMATICALLY_OVERWRITE, "true");
    ResourceInformation resourceInformation = resourceInformationProviderWithProperty.build(JsonResourceWithDefaultLookupBehaviorRelationship.class);
    assertThat(resourceInformation.getRelationshipFields()).extracting("lookupIncludeBehavior").contains(LookupIncludeBehavior.AUTOMATICALLY_ALWAYS);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) Test(org.junit.Test)

Example 5 with ResourceInformationProvider

use of io.crnk.core.engine.information.resource.ResourceInformationProvider in project crnk-framework by crnk-project.

the class DefaultResourceInformationProviderTest method getResourceInformationProviderWithProperty.

private ResourceInformationProvider getResourceInformationProviderWithProperty(String key, String value) {
    PropertiesProvider propertiesProvider = Mockito.mock(PropertiesProvider.class);
    Mockito.when(propertiesProvider.getProperty(Mockito.eq(key))).thenReturn(value);
    ResourceInformationProvider resourceInformationProvider = new DefaultResourceInformationProvider(propertiesProvider, new OffsetLimitPagingBehavior(), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
    resourceInformationProvider.init(context);
    return resourceInformationProvider;
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) JacksonResourceFieldInformationProvider(io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider) DefaultResourceFieldInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)

Aggregations

ResourceInformationProvider (io.crnk.core.engine.information.resource.ResourceInformationProvider)10 DefaultResourceInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider)6 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)5 DefaultResourceFieldInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)4 JacksonResourceFieldInformationProvider (io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider)4 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)3 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)3 Before (org.junit.Before)3 Test (org.junit.Test)3 CrnkBoot (io.crnk.core.boot.CrnkBoot)2 InformationBuilder (io.crnk.core.engine.information.InformationBuilder)2 ResourceField (io.crnk.core.engine.information.resource.ResourceField)2 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)2 ResourceRepositoryInformationImpl (io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl)2 TypeParser (io.crnk.core.engine.parser.TypeParser)2 SimpleModule (io.crnk.core.module.SimpleModule)2 DefaultQuerySpecConverter (io.crnk.legacy.internal.DefaultQuerySpecConverter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ResourceRepositoryStubImpl (io.crnk.client.internal.ResourceRepositoryStubImpl)1 RepositoryInformationProviderContext (io.crnk.core.engine.information.repository.RepositoryInformationProviderContext)1