Search in sources :

Example 11 with RegistryEntry

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());
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) QuerySpec(io.crnk.core.queryspec.QuerySpec) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 12 with RegistryEntry

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);
    }
}
Also used : RepositoryNotFoundException(io.crnk.core.exception.RepositoryNotFoundException) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 13 with RegistryEntry

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);
}
Also used : DefaultRegistryEntryBuilder(io.crnk.core.engine.internal.registry.DefaultRegistryEntryBuilder) RegistryEntryBuilder(io.crnk.core.engine.registry.RegistryEntryBuilder) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 14 with RegistryEntry

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");
    }
}
Also used : QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 15 with RegistryEntry

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);
}
Also used : QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Aggregations

RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)119 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)60 Test (org.junit.Test)38 ResourceField (io.crnk.core.engine.information.resource.ResourceField)36 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)19 QuerySpec (io.crnk.core.queryspec.QuerySpec)18 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)14 Serializable (java.io.Serializable)14 Task (io.crnk.core.mock.models.Task)13 Response (io.crnk.core.engine.dispatcher.Response)12 Document (io.crnk.core.engine.document.Document)11 Resource (io.crnk.core.engine.document.Resource)11 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)10 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)9 FilterSpec (io.crnk.core.queryspec.FilterSpec)9 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)8 Before (org.junit.Before)8 Collection (java.util.Collection)7 HashSet (java.util.HashSet)7 HttpMethod (io.crnk.core.engine.http.HttpMethod)6