use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.
the class ResourceRepositoryBase method findOne.
/**
* Forwards to {@link #findAll(QuerySpec)}
*
* @param id of the resource
* @param querySpec for field and relation inclusion
* @return resource
*/
@Override
public T findOne(I id, QuerySpec querySpec) {
RegistryEntry entry = resourceRegistry.findEntry(resourceClass);
String idName = entry.getResourceInformation().getIdField().getUnderlyingName();
QuerySpec idQuerySpec = querySpec.duplicate();
idQuerySpec.addFilter(new FilterSpec(Arrays.asList(idName), FilterOperator.EQ, id));
Iterable<T> iterable = findAll(idQuerySpec);
Iterator<T> iterator = iterable.iterator();
if (iterator.hasNext()) {
T resource = iterator.next();
PreconditionUtil.assertFalse("expected unique result", iterator.hasNext());
return resource;
} else {
throw new ResourceNotFoundException("resource not found");
}
}
use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.
the class ResourceRepositoryBase method findAll.
/**
* Forwards to {@link #findAll(QuerySpec)}
*
* @param ids of the resources
* @param querySpec for field and relation inclusion
* @return resources
*/
@Override
public ResourceList<T> findAll(Iterable<I> ids, QuerySpec querySpec) {
RegistryEntry entry = resourceRegistry.findEntry(resourceClass);
String idName = entry.getResourceInformation().getIdField().getUnderlyingName();
QuerySpec idQuerySpec = querySpec.duplicate();
idQuerySpec.addFilter(new FilterSpec(Arrays.asList(idName), FilterOperator.EQ, ids));
return findAll(idQuerySpec);
}
use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.
the class DefaultQueryParamsConverter method applyFiltering.
protected void applyFiltering(QuerySpec spec, QueryParams queryParams) {
List<FilterSpec> filters = spec.getFilters();
Map<String, FilterParams> decodedFiltersMap = new LinkedHashMap<>();
if (filters != null && !filters.isEmpty()) {
String resourceType = getResourceType(spec.getResourceClass());
Map<String, Set<String>> map = new LinkedHashMap<>();
for (FilterSpec filter : filters) {
applyFilterSpec(map, filter);
}
decodedFiltersMap.put(resourceType, new FilterParams(map));
}
queryParams.setFilters(new TypedParams<>(Collections.unmodifiableMap(decodedFiltersMap)));
}
use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.
the class MetaDefaultLimitIntTest method limitShouldNotAffectRelationshipsWithCustomLimit.
@Test
public void limitShouldNotAffectRelationshipsWithCustomLimit() {
QuerySpec querySpec = new QuerySpec(MetaResource.class);
querySpec.includeRelation(Arrays.asList("attributes"));
querySpec.setLimit(3L);
querySpec.addFilter(new FilterSpec(Arrays.asList("resourceType"), FilterOperator.EQ, "tasks"));
ResourceList<MetaResource> list = repository.findAll(querySpec);
Assert.assertEquals(1, list.size());
MetaResource taskMeta = list.get(0);
List<? extends MetaAttribute> attributes = taskMeta.getAttributes();
Assert.assertTrue(attributes.size() > 5);
}
use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.
the class MetaDefaultLimitIntTest method limitShouldNotAffectRelationshipsWithMetaElement.
@Test
public void limitShouldNotAffectRelationshipsWithMetaElement() {
ResourceRepositoryV2<MetaElement, Serializable> elementRepository = client.getRepositoryForType(MetaElement.class);
QuerySpec querySpec = new QuerySpec(MetaElement.class);
querySpec.includeRelation(Arrays.asList("attributes"));
querySpec.addFilter(new FilterSpec(Arrays.asList("id"), FilterOperator.EQ, "resources.tasks"));
ResourceList<MetaElement> list = elementRepository.findAll(querySpec);
Assert.assertEquals(1, list.size());
MetaResource taskMeta = (MetaResource) list.get(0);
List<? extends MetaAttribute> attributes = taskMeta.getAttributes();
Assert.assertTrue(attributes.size() > 5);
}
Aggregations