Search in sources :

Example 1 with ResourceRepository

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

use of io.crnk.legacy.repository.ResourceRepository 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 3 with ResourceRepository

use of io.crnk.legacy.repository.ResourceRepository 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)

Example 4 with ResourceRepository

use of io.crnk.legacy.repository.ResourceRepository in project crnk-framework by crnk-project.

the class ResourceRepositoryAdapter method findAll.

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

        @SuppressWarnings("rawtypes")
        @Override
        protected JsonApiResponse invoke(RepositoryFilterContext context) {
            RepositoryRequestSpec request = context.getRequest();
            QueryAdapter queryAdapter = request.getQueryAdapter();
            Object resources;
            if (isAnnotated) {
                resources = ((AnnotatedResourceRepositoryAdapter) resourceRepository).findAll(queryAdapter);
            } else if (resourceRepository instanceof ResourceRepositoryV2) {
                QuerySpec querySpec = request.getQuerySpec(resourceInformation);
                resources = ((ResourceRepositoryV2) resourceRepository).findAll(querySpec);
            } else {
                resources = ((ResourceRepository) resourceRepository).findAll(request.getQueryParams());
            }
            return getResponse(resourceRepository, resources, request);
        }
    };
    RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forFindAll(moduleRegistry, resourceInformation, queryAdapter);
    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) QuerySpec(io.crnk.core.queryspec.QuerySpec) ResourceRepository(io.crnk.legacy.repository.ResourceRepository)

Aggregations

RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)4 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)4 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)4 ResourceRepository (io.crnk.legacy.repository.ResourceRepository)4 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)3 ResourceNotFoundException (io.crnk.core.exception.ResourceNotFoundException)1 QuerySpec (io.crnk.core.queryspec.QuerySpec)1 Serializable (java.io.Serializable)1