use of io.crnk.core.engine.internal.utils.FieldOrderedComparator 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;
}
use of io.crnk.core.engine.internal.utils.FieldOrderedComparator in project crnk-framework by crnk-project.
the class FieldOrderedComparatorTest method onNoOrderShouldPersistInsertionOrder.
@Test
public void onNoOrderShouldPersistInsertionOrder() throws Exception {
// GIVEN
Set<ResourceField> fields = new TreeSet<>(new FieldOrderedComparator(new String[] {}, false));
// WHEN
fields.add(fieldB);
fields.add(fieldA);
// THEN
assertThat(fields).containsSequence(fieldB, fieldA);
}
use of io.crnk.core.engine.internal.utils.FieldOrderedComparator in project crnk-framework by crnk-project.
the class FieldOrderedComparatorTest method onAlphabeticOrderShouldSortCorrectly.
@Test
public void onAlphabeticOrderShouldSortCorrectly() throws Exception {
// GIVEN
Set<ResourceField> fields = new TreeSet<>(new FieldOrderedComparator(new String[] {}, true));
// WHEN
fields.add(fieldB);
fields.add(fieldA);
// THEN
assertThat(fields).containsSequence(fieldA, fieldB);
}
use of io.crnk.core.engine.internal.utils.FieldOrderedComparator in project crnk-framework by crnk-project.
the class FieldOrderedComparatorTest method onOneFieldShouldSortCorrectly.
@Test
public void onOneFieldShouldSortCorrectly() throws Exception {
// GIVEN
Set<ResourceField> fields = new TreeSet<>(new FieldOrderedComparator(new String[] { "b" }, false));
// WHEN
fields.add(fieldA);
fields.add(fieldB);
// THEN
assertThat(fields).containsSequence(fieldB, fieldA);
}
use of io.crnk.core.engine.internal.utils.FieldOrderedComparator in project crnk-framework by crnk-project.
the class FieldOrderedComparatorTest method onTwoFieldsShouldSortCorrectly.
@Test
public void onTwoFieldsShouldSortCorrectly() throws Exception {
// GIVEN
Set<ResourceField> fields = new TreeSet<>(new FieldOrderedComparator(new String[] { "b", "a" }, false));
// WHEN
fields.add(fieldA);
fields.add(fieldB);
// THEN
assertThat(fields).containsSequence(fieldB, fieldA);
}
Aggregations