Search in sources :

Example 1 with DirectResponseResourceEntry

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;
}
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 DirectResponseResourceEntry

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");
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) Task(io.crnk.core.mock.models.Task) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ResourceFieldImpl(io.crnk.core.engine.internal.information.resource.ResourceFieldImpl) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) ResourceRepositoryInformationImpl(io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Example 3 with DirectResponseResourceEntry

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);
    }
}
Also used : AnnotatedResourceEntry(io.crnk.legacy.registry.AnnotatedResourceEntry) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) JsonApiResourceRepository(io.crnk.legacy.repository.annotations.JsonApiResourceRepository) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder)

Example 4 with DirectResponseResourceEntry

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);
}
Also used : AnnotatedResourceEntry(io.crnk.legacy.registry.AnnotatedResourceEntry) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)

Example 5 with DirectResponseResourceEntry

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);
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) HashMap(java.util.HashMap) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) HashMap(java.util.HashMap) Map(java.util.Map) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Aggregations

DirectResponseResourceEntry (io.crnk.legacy.internal.DirectResponseResourceEntry)6 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)4 ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)3 ResourceField (io.crnk.core.engine.information.resource.ResourceField)3 ResourceRepositoryInformationImpl (io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl)3 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)3 RepositoryInstanceBuilder (io.crnk.legacy.registry.RepositoryInstanceBuilder)3 Test (org.junit.Test)3 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)2 DirectResponseRelationshipEntry (io.crnk.legacy.internal.DirectResponseRelationshipEntry)2 AnnotatedResourceEntry (io.crnk.legacy.registry.AnnotatedResourceEntry)2 ResourceRepositoryStubImpl (io.crnk.client.internal.ResourceRepositoryStubImpl)1 ResourceInformationProvider (io.crnk.core.engine.information.resource.ResourceInformationProvider)1 ResourceFieldImpl (io.crnk.core.engine.internal.information.resource.ResourceFieldImpl)1 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)1 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)1 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)1 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)1 Task (io.crnk.core.mock.models.Task)1 ModuleRegistry (io.crnk.core.module.ModuleRegistry)1