Search in sources :

Example 6 with ResourceRepositoryV2

use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.

the class DefaultRegistryEntryBuilder method decorateRepository.

@SuppressWarnings({ "rawtypes", "unchecked" })
public Object decorateRepository(Object repository) {
    Object decoratedRepository = repository;
    List<RepositoryDecoratorFactory> repositoryDecorators = moduleRegistry.getRepositoryDecoratorFactories();
    for (RepositoryDecoratorFactory repositoryDecorator : repositoryDecorators) {
        Decorator decorator = null;
        if (decoratedRepository instanceof RelationshipRepositoryV2) {
            decorator = repositoryDecorator.decorateRepository((RelationshipRepositoryV2) decoratedRepository);
        } else if (decoratedRepository instanceof ResourceRepositoryV2) {
            decorator = repositoryDecorator.decorateRepository((ResourceRepositoryV2) decoratedRepository);
        }
        if (decorator != null) {
            decorator.setDecoratedObject(decoratedRepository);
            decoratedRepository = decorator;
        }
    }
    return decoratedRepository;
}
Also used : Decorator(io.crnk.core.engine.internal.utils.Decorator) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) RepositoryDecoratorFactory(io.crnk.core.repository.decorate.RepositoryDecoratorFactory) RelationshipRepositoryV2(io.crnk.core.repository.RelationshipRepositoryV2)

Example 7 with ResourceRepositoryV2

use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.

the class ResourceRepositoryAdapter method delete.

public JsonApiResponse delete(I id, QueryAdapter queryAdapter) {
    RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {

        @SuppressWarnings("rawtypes")
        @Override
        protected JsonApiResponse invoke(RepositoryFilterContext context) {
            RepositoryRequestSpec request = context.getRequest();
            QueryAdapter queryAdapter = request.getQueryAdapter();
            Serializable id = request.getId();
            if (isAnnotated) {
                ((AnnotatedResourceRepositoryAdapter) resourceRepository).delete(id, queryAdapter);
            } else if (resourceRepository instanceof ResourceRepositoryV2) {
                ((ResourceRepositoryV2) resourceRepository).delete(id);
            } else {
                ((ResourceRepository) resourceRepository).delete(id);
            }
            return new JsonApiResponse();
        }
    };
    RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forDelete(moduleRegistry, resourceInformation, queryAdapter, id);
    return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Also used : Serializable(java.io.Serializable) RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) AnnotatedResourceRepositoryAdapter(io.crnk.legacy.internal.AnnotatedResourceRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext)

Example 8 with ResourceRepositoryV2

use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.

the class ResourceRepositoryAdapter method findAll.

public JsonApiResponse findAll(Iterable ids, QueryAdapter queryAdapter) {
    RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {

        @SuppressWarnings("rawtypes")
        @Override
        protected JsonApiResponse invoke(RepositoryFilterContext context) {
            RepositoryRequestSpec request = context.getRequest();
            QueryAdapter queryAdapter = request.getQueryAdapter();
            Iterable<?> ids = request.getIds();
            Object resources;
            if (isAnnotated) {
                resources = ((AnnotatedResourceRepositoryAdapter) resourceRepository).findAll(ids, queryAdapter);
            } else if (resourceRepository instanceof ResourceRepositoryV2) {
                resources = ((ResourceRepositoryV2) resourceRepository).findAll(ids, request.getQuerySpec(resourceInformation));
            } else {
                resources = ((ResourceRepository) resourceRepository).findAll(ids, request.getQueryParams());
            }
            return getResponse(resourceRepository, resources, request);
        }
    };
    RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forFindIds(moduleRegistry, resourceInformation, queryAdapter, ids);
    return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Also used : RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext) ResourceRepository(io.crnk.legacy.repository.ResourceRepository)

Example 9 with ResourceRepositoryV2

use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.

the class ResourceRepositoryAdapter method findOne.

public JsonApiResponse findOne(I id, QueryAdapter queryAdapter) {
    RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {

        @SuppressWarnings("rawtypes")
        @Override
        protected JsonApiResponse invoke(RepositoryFilterContext context) {
            RepositoryRequestSpec request = context.getRequest();
            QueryAdapter queryAdapter = request.getQueryAdapter();
            Serializable id = request.getId();
            Object resource;
            if (isAnnotated) {
                resource = ((AnnotatedResourceRepositoryAdapter) resourceRepository).findOne(id, queryAdapter);
            } else if (resourceRepository instanceof ResourceRepositoryV2) {
                resource = ((ResourceRepositoryV2) resourceRepository).findOne(id, request.getQuerySpec(resourceInformation));
            } else {
                resource = ((ResourceRepository) resourceRepository).findOne(id, request.getQueryParams());
            }
            if (resource == null && return404OnNull) {
                throw new ResourceNotFoundException(resourceInformation.getResourceType());
            }
            return getResponse(resourceRepository, resource, request);
        }
    };
    RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forFindId(moduleRegistry, resourceInformation, queryAdapter, id);
    return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Also used : Serializable(java.io.Serializable) RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext) ResourceRepository(io.crnk.legacy.repository.ResourceRepository) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException)

Example 10 with ResourceRepositoryV2

use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.

the class ResourceRepositoryAdapter method save.

private <S extends T> JsonApiResponse save(S entity, QueryAdapter queryAdapter, final HttpMethod method) {
    RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {

        @SuppressWarnings("rawtypes")
        @Override
        protected JsonApiResponse invoke(RepositoryFilterContext context) {
            RepositoryRequestSpec request = context.getRequest();
            Object entity = request.getEntity();
            Object resource;
            if (isAnnotated) {
                resource = ((AnnotatedResourceRepositoryAdapter) resourceRepository).save(entity);
            } else if (resourceRepository instanceof ResourceRepositoryV2) {
                if (method == HttpMethod.POST) {
                    resource = ((ResourceRepositoryV2) resourceRepository).create(entity);
                } else {
                    resource = ((ResourceRepositoryV2) resourceRepository).save(entity);
                }
            } else {
                resource = ((ResourceRepository) resourceRepository).save(entity);
            }
            return getResponse(resourceRepository, resource, request);
        }
    };
    RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forSave(moduleRegistry, method, resourceInformation, queryAdapter, entity);
    return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Also used : RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext) ResourceRepository(io.crnk.legacy.repository.ResourceRepository)

Aggregations

ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)14 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)5 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)5 QuerySpec (io.crnk.core.queryspec.QuerySpec)5 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)4 ResourceRepository (io.crnk.legacy.repository.ResourceRepository)4 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)3 Serializable (java.io.Serializable)3 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)2 FilterSpec (io.crnk.core.queryspec.FilterSpec)2 ResourceList (io.crnk.core.resource.list.ResourceList)2 ApprovalManager (io.crnk.activiti.example.approval.ApprovalManager)1 ApprovalMapper (io.crnk.activiti.example.approval.ApprovalMapper)1 ActivitiResourceMapper (io.crnk.activiti.mapper.ActivitiResourceMapper)1 DefaultDateTimeMapper (io.crnk.activiti.mapper.DefaultDateTimeMapper)1 ClientStubInvocationHandler (io.crnk.client.internal.ClientStubInvocationHandler)1 RepositoryAction (io.crnk.core.engine.information.repository.RepositoryAction)1 RepositoryInformationProvider (io.crnk.core.engine.information.repository.RepositoryInformationProvider)1 ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)1 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)1