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;
}
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());
}
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());
}
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);
}
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;
}
Aggregations