Search in sources :

Example 86 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation 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 87 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation 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)

Example 88 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.

the class DefaultResourceRegistryPart method addEntry.

@Override
public RegistryEntry addEntry(RegistryEntry entry) {
    ResourceInformation resourceInformation = entry.getResourceInformation();
    Class<?> resourceClass = resourceInformation.getResourceClass();
    String resourceType = resourceInformation.getResourceType();
    PreconditionUtil.assertNotNull("no resourceType set", resourceType);
    resourcesByClass.put(resourceClass, entry);
    resourcesByType.put(resourceType, entry);
    logger.debug("Added resource {} to ResourceRegistry", entry.getResourceInformation().getResourceType());
    notifyChange();
    return entry;
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation)

Example 89 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.

the class RegistryEntry method getResourceRepository.

@SuppressWarnings("unchecked")
public ResourceRepositoryAdapter getResourceRepository(RepositoryMethodParameterProvider parameterProvider) {
    Object repoInstance = null;
    if (resourceEntry instanceof DirectResponseResourceEntry) {
        repoInstance = ((DirectResponseResourceEntry) resourceEntry).getResourceRepository();
    } else if (resourceEntry instanceof AnnotatedResourceEntry) {
        repoInstance = ((AnnotatedResourceEntry) resourceEntry).build(parameterProvider);
    }
    if (repoInstance instanceof ResourceRegistryAware) {
        ((ResourceRegistryAware) repoInstance).setResourceRegistry(moduleRegistry.getResourceRegistry());
    }
    ResourceInformation resourceInformation = getResourceInformation();
    return new ResourceRepositoryAdapter(resourceInformation, moduleRegistry, repoInstance);
}
Also used : AnnotatedResourceEntry(io.crnk.legacy.registry.AnnotatedResourceEntry) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)

Example 90 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.

the class DefaultResourceInformationProviderTest method shouldHaveOneIdFieldOfTypeLong.

@Test
public void shouldHaveOneIdFieldOfTypeLong() {
    /*
 			Task has a Long getId() field and a boolean hasId() which is ignored, only the former should have survived
 		 */
    ResourceInformation resourceInformation = resourceInformationProvider.build(Task.class);
    assertThat(resourceInformation.getIdField()).isNotNull();
    assertThat(resourceInformation.getIdField().getType()).isEqualTo(Long.class);
    assertThat(containsFieldWithName(resourceInformation, "hasId")).isFalse();
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Aggregations

ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)167 Test (org.junit.Test)79 ResourceField (io.crnk.core.engine.information.resource.ResourceField)76 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)60 QuerySpec (io.crnk.core.queryspec.QuerySpec)16 Resource (io.crnk.core.engine.document.Resource)15 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)15 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)9 Task (io.crnk.core.mock.models.Task)9 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)9 HashSet (java.util.HashSet)9 Collection (java.util.Collection)8 Relationship (io.crnk.core.engine.document.Relationship)7 HttpMethod (io.crnk.core.engine.http.HttpMethod)7 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)7 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)7 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)7 DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)7 Set (java.util.Set)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6