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;
}
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));
}
}
}
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();
}
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();
}
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();
}
Aggregations