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;
}
Aggregations