use of io.crnk.legacy.internal.DirectResponseResourceEntry 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.legacy.internal.DirectResponseResourceEntry 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.legacy.internal.DirectResponseResourceEntry in project crnk-framework by crnk-project.
the class DefaultRegistryEntryBuilder method buildResourceRepository.
@SuppressWarnings({ "rawtypes", "unchecked" })
private ResourceEntry buildResourceRepository(ResourceInformation resourceInformation) {
resourceRepository.information().setResourceInformation(resourceInformation);
ResourceRepositoryInformation repositoryInformation = resourceRepository.information().build();
Object instance = resourceRepository.instance;
final Object decoratedRepository = decorateRepository(instance);
RepositoryInstanceBuilder repositoryInstanceBuilder = new RepositoryInstanceBuilder(null, instance.getClass()) {
@Override
public Object buildRepository() {
return decoratedRepository;
}
};
if (ClassUtils.getAnnotation(decoratedRepository.getClass(), JsonApiResourceRepository.class).isPresent()) {
return new AnnotatedResourceEntry(repositoryInstanceBuilder, repositoryInformation);
} else {
return new DirectResponseResourceEntry(repositoryInstanceBuilder, repositoryInformation);
}
}
use of io.crnk.legacy.internal.DirectResponseResourceEntry in project crnk-framework by crnk-project.
the class RegistryEntry method getResourceRepository.
@SuppressWarnings("unchecked")
public ResourceRepositoryAdapter getResourceRepository(RepositoryMethodParameterProvider parameterProvider) {
Object repoInstance = null;
if (resourceEntry instanceof DirectResponseResourceEntry) {
repoInstance = ((DirectResponseResourceEntry) resourceEntry).getResourceRepository();
} else if (resourceEntry instanceof AnnotatedResourceEntry) {
repoInstance = ((AnnotatedResourceEntry) resourceEntry).build(parameterProvider);
}
if (repoInstance instanceof ResourceRegistryAware) {
((ResourceRegistryAware) repoInstance).setResourceRegistry(moduleRegistry.getResourceRegistry());
}
ResourceInformation resourceInformation = getResourceInformation();
return new ResourceRepositoryAdapter(resourceInformation, moduleRegistry, repoInstance);
}
use of io.crnk.legacy.internal.DirectResponseResourceEntry in project crnk-framework by crnk-project.
the class RegistryEntryTest method onInvalidRelationshipClassShouldThrowException.
@Test
public void onInvalidRelationshipClassShouldThrowException() throws Exception {
// GIVEN
ResourceRepositoryInformation repositoryInformation = newRepositoryInformation(Task.class, "tasks");
ResourceField relationshipField = repositoryInformation.getResourceInformation().get().findFieldByUnderlyingName("tasks");
Map relRepos = new HashMap<>();
relRepos.put(relationshipField, new DirectResponseRelationshipEntry(new RepositoryInstanceBuilder(new SampleJsonServiceLocator(), TaskToProjectRepository.class)));
RegistryEntry sut = new RegistryEntry(new DirectResponseResourceEntry(null, repositoryInformation), relRepos);
// THEN
expectedException.expect(ResourceFieldNotFoundException.class);
// WHEN
sut.getRelationshipRepository("users", null);
}
Aggregations