use of com.yahoo.elide.core.request.Sorting in project elide by yahoo.
the class DataStoreLoadTest method testSortingAscending.
@Test
public void testSortingAscending() throws Exception {
DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
Map<String, Sorting.SortOrder> sortRules = new HashMap<>();
sortRules.put("name", Sorting.SortOrder.asc);
sortRules.put("modifiedDate", Sorting.SortOrder.desc);
Sorting sorting = new SortingImpl(sortRules, Item.class, dictionary);
FilterExpression filter = filterParser.parseFilterExpression("name==cymbal*", ClassType.of(Item.class), false);
Iterable<Object> loaded = testTransaction.loadObjects(EntityProjection.builder().type(Item.class).filterExpression(filter).sorting(sorting).build(), mockScope);
assertListContains(loaded, Lists.newArrayList(4L, 5L, 2L));
verify(wrappedTransaction, never()).loadObjects(any(), any());
}
use of com.yahoo.elide.core.request.Sorting in project elide by yahoo.
the class GraphQLEntityProjectionMaker method addSorting.
/**
* Creates a {@link Sorting} object from sorting GraphQL argument value and attaches it to the entity sorted
* according to the newly created {@link Sorting} object.
*
* @param argument An argument that contains the value of sorting spec
* @param projectionBuilder projection that is being built
*/
private void addSorting(Argument argument, EntityProjectionBuilder projectionBuilder) {
String sortRule = (String) variableResolver.resolveValue(argument.getValue());
try {
Sorting sorting = SortingImpl.parseSortRule(sortRule, projectionBuilder.getType(), projectionBuilder.getAttributes(), entityDictionary);
projectionBuilder.sorting(sorting);
} catch (InvalidValueException e) {
throw new BadRequestException("Invalid sorting clause " + sortRule + " for type " + entityDictionary.getJsonAliasFor(projectionBuilder.getType()));
}
}
Aggregations