Search in sources :

Example 1 with AnnotatedResourceEntry

use of io.crnk.legacy.registry.AnnotatedResourceEntry 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 2 with AnnotatedResourceEntry

use of io.crnk.legacy.registry.AnnotatedResourceEntry 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)

Aggregations

DirectResponseResourceEntry (io.crnk.legacy.internal.DirectResponseResourceEntry)2 AnnotatedResourceEntry (io.crnk.legacy.registry.AnnotatedResourceEntry)2 ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)1 RepositoryInstanceBuilder (io.crnk.legacy.registry.RepositoryInstanceBuilder)1 JsonApiResourceRepository (io.crnk.legacy.repository.annotations.JsonApiResourceRepository)1