Search in sources :

Example 1 with ResourceIdNotFoundException

use of io.crnk.core.exception.ResourceIdNotFoundException in project crnk-framework by crnk-project.

the class DefaultResourceInformationProvider method build.

public ResourceInformation build(Class<?> resourceClass, boolean allowNonResourceBaseClass) {
    List<ResourceField> resourceFields = getResourceFields(resourceClass);
    String resourceType = getResourceType(resourceClass, allowNonResourceBaseClass);
    Optional<JsonPropertyOrder> propertyOrder = ClassUtils.getAnnotation(resourceClass, JsonPropertyOrder.class);
    if (propertyOrder.isPresent()) {
        JsonPropertyOrder propertyOrderAnnotation = propertyOrder.get();
        Collections.sort(resourceFields, new FieldOrderedComparator(propertyOrderAnnotation.value(), propertyOrderAnnotation.alphabetic()));
    }
    DefaultResourceInstanceBuilder<?> instanceBuilder = new DefaultResourceInstanceBuilder(resourceClass);
    Class<?> superclass = resourceClass.getSuperclass();
    String superResourceType = superclass != Object.class && context.accept(superclass) ? context.getResourceType(superclass) : null;
    ResourceInformation information = new ResourceInformation(context.getTypeParser(), resourceClass, resourceType, superResourceType, instanceBuilder, resourceFields, pagingBehaviors.get(ClassUtils.getAnnotation(resourceClass, JsonApiResource.class).get().pagingBehavior()));
    if (!allowNonResourceBaseClass && information.getIdField() == null) {
        throw new ResourceIdNotFoundException(resourceClass.getCanonicalName());
    }
    return information;
}
Also used : FieldOrderedComparator(io.crnk.core.engine.internal.utils.FieldOrderedComparator) ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) JsonPropertyOrder(com.fasterxml.jackson.annotation.JsonPropertyOrder) ResourceIdNotFoundException(io.crnk.core.exception.ResourceIdNotFoundException)

Aggregations

JsonPropertyOrder (com.fasterxml.jackson.annotation.JsonPropertyOrder)1 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 FieldOrderedComparator (io.crnk.core.engine.internal.utils.FieldOrderedComparator)1 ResourceIdNotFoundException (io.crnk.core.exception.ResourceIdNotFoundException)1