use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class ForwardingStrategyContext method createSourceQuerySpec.
private QuerySpec createSourceQuerySpec() {
RegistryEntry sourceEntry = getSourceEntry();
ResourceInformation resourceInformation = sourceEntry.getResourceInformation();
return new QuerySpec(resourceInformation.getResourceClass(), resourceInformation.getResourceType());
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class DefaultQuerySpecSerializer method serialize.
private void serialize(QuerySpec querySpec, Map<String, Set<String>> map, QuerySpec parentQuerySpec) {
String resourceType = querySpec.getResourceType();
if (resourceType == null) {
RegistryEntry entry = resourceRegistry.getEntry(querySpec.getResourceClass());
if (entry == null) {
throw new RepositoryNotFoundException(querySpec.getResourceClass());
}
resourceType = entry.getResourceInformation().getResourceType();
}
serializeFilters(querySpec, resourceType, map);
serializeSorting(querySpec, resourceType, map);
serializeIncludedFields(querySpec, resourceType, map);
serializeIncludedRelations(querySpec, resourceType, map);
RegistryEntry entry = resourceRegistry.getEntry(parentQuerySpec.getResourceClass());
if (entry != null && entry.getResourceInformation() != null && entry.getResourceInformation().getPagingBehavior() != null) {
map.putAll(entry.getResourceInformation().getPagingBehavior().serialize(querySpec.getPagingSpec(), resourceType));
}
for (QuerySpec relatedSpec : querySpec.getRelatedSpecs().values()) {
serialize(relatedSpec, map, querySpec);
}
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class ModuleRegistry method applyRepositoryRegistration.
private void applyRepositoryRegistration(Object repository) {
RegistryEntryBuilder entryBuilder = getContext().newRegistryEntryBuilder();
entryBuilder.fromImplementation(repository);
RegistryEntry entry = entryBuilder.build();
resourceRegistry.addEntry(entry);
}
use of io.crnk.core.engine.registry.RegistryEntry 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.engine.registry.RegistryEntry 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);
}
Aggregations