Search in sources :

Example 1 with QueryAdapter

use of io.crnk.core.engine.query.QueryAdapter in project crnk-framework by crnk-project.

the class SecurityRepositoryFilter method filterMeta.

@Override
public <T> MetaInformation filterMeta(RepositoryFilterContext context, Iterable<T> resources, RepositoryMetaFilterChain chain) {
    MetaInformation metaInformation = chain.doFilter(context, resources);
    if (metaInformation instanceof ResourcePermissionInformation) {
        ResourcePermissionInformation permissionInformation = (ResourcePermissionInformation) metaInformation;
        QueryAdapter queryAdapter = context.getRequest().getQueryAdapter();
        Class<?> resourceClass = queryAdapter.getResourceInformation().getResourceClass();
        permissionInformation.setResourcePermission(module.getResourcePermission(resourceClass));
    }
    return metaInformation;
}
Also used : ResourcePermissionInformation(io.crnk.security.ResourcePermissionInformation) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) MetaInformation(io.crnk.core.resource.meta.MetaInformation)

Example 2 with QueryAdapter

use of io.crnk.core.engine.query.QueryAdapter in project crnk-framework by crnk-project.

the class OffsetLimitPagingBehavior method doEnrichPageLinksInformation.

private void doEnrichPageLinksInformation(PagedLinksInformation linksInformation, Long total, Boolean isNextPageAvailable, QueryAdapter queryAdapter, boolean hasResults, PagingSpecUrlBuilder urlBuilder) {
    OffsetLimitPagingSpec offsetLimitPagingSpec = (OffsetLimitPagingSpec) queryAdapter.getPagingSpec();
    long pageSize = offsetLimitPagingSpec.getLimit();
    long offset = offsetLimitPagingSpec.getOffset();
    long currentPage = offset / pageSize;
    if (currentPage * pageSize != offset) {
        throw new BadRequestException("offset " + offset + " is not a multiple of limit " + pageSize);
    }
    if (total != null) {
        isNextPageAvailable = offset + pageSize < total;
    }
    if (offset > 0 || hasResults) {
        Long totalPages = total != null ? (total + pageSize - 1) / pageSize : null;
        QueryAdapter pageSpec = queryAdapter.duplicate();
        pageSpec.setPagingSpec(new OffsetLimitPagingSpec(0L, pageSize));
        linksInformation.setFirst(urlBuilder.build(pageSpec));
        if (totalPages != null && totalPages > 0) {
            pageSpec.setPagingSpec(new OffsetLimitPagingSpec((totalPages - 1) * pageSize, pageSize));
            linksInformation.setLast(urlBuilder.build(pageSpec));
        }
        if (currentPage > 0) {
            pageSpec.setPagingSpec(new OffsetLimitPagingSpec((currentPage - 1) * pageSize, pageSize));
            linksInformation.setPrev(urlBuilder.build(pageSpec));
        }
        if (isNextPageAvailable) {
            pageSpec.setPagingSpec(new OffsetLimitPagingSpec((currentPage + 1) * pageSize, pageSize));
            linksInformation.setNext(urlBuilder.build(pageSpec));
        }
    }
}
Also used : QueryAdapter(io.crnk.core.engine.query.QueryAdapter) BadRequestException(io.crnk.core.exception.BadRequestException)

Example 3 with QueryAdapter

use of io.crnk.core.engine.query.QueryAdapter in project crnk-framework by crnk-project.

the class RelationshipRepositoryBase method getTargets.

@SuppressWarnings("unchecked")
protected Iterable<D> getTargets(RegistryEntry entry, Iterable<J> targetIds) {
    ResourceRepositoryAdapter<D, J> targetAdapter = entry.getResourceRepository();
    QueryAdapter queryAdapter = new QuerySpecAdapter(new QuerySpec(entry.getResourceInformation()), resourceRegistry);
    return (Iterable<D>) targetAdapter.findAll(targetIds, queryAdapter).getEntity();
}
Also used : QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 4 with QueryAdapter

use of io.crnk.core.engine.query.QueryAdapter in project crnk-framework by crnk-project.

the class ForwardingStrategyContext method findAll.

public <Q> Iterable<Q> findAll(RegistryEntry entry, Iterable<?> targetIds) {
    ResourceRepositoryAdapter targetAdapter = entry.getResourceRepository();
    QueryAdapter queryAdapter = new QuerySpecAdapter(new QuerySpec(entry.getResourceInformation()), resourceRegistry);
    return (Iterable) targetAdapter.findAll(targetIds, queryAdapter).getEntity();
}
Also used : ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 5 with QueryAdapter

use of io.crnk.core.engine.query.QueryAdapter in project crnk-framework by crnk-project.

the class ForwardingStrategyContext method findOne.

public <Q> Q findOne(RegistryEntry entry, Serializable id) {
    ResourceRepositoryAdapter targetAdapter = entry.getResourceRepository();
    QueryAdapter queryAdapter = new QuerySpecAdapter(new QuerySpec(entry.getResourceInformation()), resourceRegistry);
    return (Q) targetAdapter.findOne(id, queryAdapter).getEntity();
}
Also used : ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Aggregations

QueryAdapter (io.crnk.core.engine.query.QueryAdapter)35 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)15 QuerySpec (io.crnk.core.queryspec.QuerySpec)14 ResourceField (io.crnk.core.engine.information.resource.ResourceField)13 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)12 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)12 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)10 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)9 BulkRelationshipRepositoryV2 (io.crnk.core.repository.BulkRelationshipRepositoryV2)8 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)7 RelationshipRepositoryV2 (io.crnk.core.repository.RelationshipRepositoryV2)6 Resource (io.crnk.core.engine.document.Resource)5 Task (io.crnk.core.mock.models.Task)5 Serializable (java.io.Serializable)5 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)4 AnnotatedRelationshipRepositoryAdapter (io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter)4 Before (org.junit.Before)4 Test (org.junit.Test)4 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)3 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)3