use of io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl 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.internal.information.repository.ResourceRepositoryInformationImpl in project crnk-framework by crnk-project.
the class RegistryEntryTest method newRepositoryInformation.
private <T> ResourceRepositoryInformation newRepositoryInformation(Class<T> repositoryClass, String path) {
ModuleRegistry moduleRegistry = new ModuleRegistry();
TypeParser typeParser = moduleRegistry.getTypeParser();
return new ResourceRepositoryInformationImpl(path, new ResourceInformation(typeParser, Task.class, path, null, null, null, null), RepositoryMethodAccess.ALL);
}
use of io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl in project crnk-framework by crnk-project.
the class ResourceRegistryTest method onExistingResourceShouldReturnUrl.
@Test
public void onExistingResourceShouldReturnUrl() {
Task task = new Task();
task.setId(1L);
ResourceField idField = new ResourceFieldImpl("id", "id", ResourceFieldType.ID, Long.class, Long.class, null);
ResourceField valueField = new ResourceFieldImpl("value", "value", ResourceFieldType.RELATIONSHIP, String.class, String.class, "projects");
ResourceInformation resourceInformation = new ResourceInformation(moduleRegistry.getTypeParser(), Task.class, "tasks", null, Arrays.asList(idField, valueField), new OffsetLimitPagingBehavior());
RegistryEntry registryEntry = new RegistryEntry(new DirectResponseResourceEntry(null, new ResourceRepositoryInformationImpl("tasks", resourceInformation, RepositoryMethodAccess.ALL)));
resourceRegistry.addEntry(Task.class, registryEntry);
String resourceUrl = resourceRegistry.getResourceUrl(task);
assertThat(resourceUrl).isEqualTo(TEST_MODELS_URL + "/tasks/1");
}
use of io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl in project crnk-framework by crnk-project.
the class QuerySpecAdapterTest method test.
@Test
public void test() {
ModuleRegistry moduleRegistry = new ModuleRegistry();
ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
ResourceInformation resourceInformation = new ResourceInformation(moduleRegistry.getTypeParser(), Task.class, "tasks", null, null, new OffsetLimitPagingBehavior());
resourceRegistry.addEntry(new RegistryEntry(new DirectResponseResourceEntry(null, new ResourceRepositoryInformationImpl("tasks", resourceInformation, RepositoryMethodAccess.ALL))));
QuerySpec spec = new QuerySpec(Task.class);
spec.includeField(Arrays.asList("test"));
spec.includeRelation(Arrays.asList("relation"));
QuerySpecAdapter adapter = new QuerySpecAdapter(spec, resourceRegistry);
Assert.assertEquals(Task.class, adapter.getResourceInformation().getResourceClass());
Assert.assertEquals(spec, adapter.getQuerySpec());
TypedParams<IncludedFieldsParams> includedFields = adapter.getIncludedFields();
IncludedFieldsParams includedFieldsParams = includedFields.getParams().get("tasks");
Assert.assertEquals(1, includedFieldsParams.getParams().size());
Assert.assertEquals("test", includedFieldsParams.getParams().iterator().next());
TypedParams<IncludedRelationsParams> includedRelations = adapter.getIncludedRelations();
IncludedRelationsParams includedRelationsParams = includedRelations.getParams().get("tasks");
Assert.assertEquals(1, includedRelationsParams.getParams().size());
Assert.assertEquals("relation", includedRelationsParams.getParams().iterator().next().getPath());
Assert.assertEquals(new OffsetLimitPagingSpec(), adapter.getPagingSpec());
}
use of io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl in project crnk-framework by crnk-project.
the class DefaultResourceRepositoryInformationProvider method build.
private RepositoryInformation build(Object repository, Class<? extends Object> repositoryClass, RepositoryInformationProviderContext context) {
Class<?> resourceClass = getResourceClass(repository, repositoryClass);
ResourceInformationProvider resourceInformationProvider = context.getResourceInformationBuilder();
PreconditionUtil.assertTrue("cannot get ResourceInformation for " + resourceClass, resourceInformationProvider.accept(resourceClass));
ResourceInformation resourceInformation = resourceInformationProvider.build(resourceClass);
String path = getPath(resourceInformation, repository);
return new ResourceRepositoryInformationImpl(path, resourceInformation, buildActions(repositoryClass), getAccess(repository));
}
Aggregations