Search in sources :

Example 61 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class ConstraintViolationExceptionMapper method getResourceType.

protected String getResourceType(Object resource) {
    ResourceRegistry resourceRegistry = context.getResourceRegistry();
    RegistryEntry entry = resourceRegistry.findEntry(resource.getClass());
    ResourceInformation resourceInformation = entry.getResourceInformation();
    return resourceInformation.getResourceType();
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 62 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class DefaultRegistryEntryBuilder method build.

@Override
public RegistryEntry build() {
    ResourceInformation resourceInformation = buildResource();
    ResourceEntry resourceEntry = buildResourceRepository(resourceInformation);
    Map<ResourceField, ResponseRelationshipEntry> relationshipEntries = buildRelationships(resourceInformation);
    RegistryEntry entry = new RegistryEntry(resourceEntry, relationshipEntries);
    entry.initialize(moduleRegistry);
    return entry;
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResponseRelationshipEntry(io.crnk.core.engine.registry.ResponseRelationshipEntry) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) ResourceEntry(io.crnk.core.engine.registry.ResourceEntry) AnnotatedResourceEntry(io.crnk.legacy.registry.AnnotatedResourceEntry) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 63 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class ResourceRegistryImpl method getResourceUrl.

@Override
public String getResourceUrl(final Class<?> clazz, final String id) {
    RegistryEntry registryEntry = findEntry(clazz);
    String typeUrl = getResourceUrl(registryEntry.getResourceInformation());
    return typeUrl != null ? String.format("%s/%s", typeUrl, id) : null;
}
Also used : RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 64 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class ResourceFilterDirectoryImpl method get.

@Override
public FilterBehavior get(ResourceField field, HttpMethod method) {
    Map<Object, FilterBehavior> map = getCache(method);
    FilterBehavior behavior = map.get(field);
    if (behavior != null) {
        return behavior;
    }
    behavior = FilterBehavior.NONE;
    for (ResourceFilter filter : filters) {
        behavior = behavior.merge(filter.filterField(field, method));
        if (behavior == FilterBehavior.FORBIDDEN) {
            break;
        }
    }
    if (field.getResourceFieldType() == ResourceFieldType.RELATIONSHIP) {
        // for relationships opposite site must also be accessible (at least with GET)
        String oppositeResourceType = field.getOppositeResourceType();
        RegistryEntry oppositeRegistryEntry = resourceRegistry.getEntry(oppositeResourceType);
        if (oppositeRegistryEntry != null) {
            PreconditionUtil.assertNotNull(oppositeResourceType, oppositeRegistryEntry);
            ResourceInformation oppositeResourceInformation = oppositeRegistryEntry.getResourceInformation();
            // consider checking more than GET? intersection/union of multiple?
            behavior = behavior.merge(get(oppositeResourceInformation, HttpMethod.GET));
        } else {
            LOGGER.warn("opposite side {} not found", oppositeResourceType);
        }
    }
    map.put(field, behavior);
    return behavior;
}
Also used : ResourceFilter(io.crnk.core.engine.filter.ResourceFilter) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) FilterBehavior(io.crnk.core.engine.filter.FilterBehavior) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 65 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class DefaultQuerySpecDeserializer method getAttributeType.

protected Class<?> getAttributeType(Class<?> clazz, String propertyName) {
    if (resourceRegistry.hasEntry(clazz)) {
        RegistryEntry entry = resourceRegistry.getEntryForClass(clazz);
        ResourceInformation resourceInformation = entry.getResourceInformation();
        ResourceField field = resourceInformation.findFieldByName(propertyName);
        if (field != null) {
            return field.getType();
        }
    }
    return PropertyUtils.getPropertyClass(clazz, propertyName);
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) 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