use of org.molgenis.data.UnknownSortAttributeException in project molgenis by molgenis.
the class SortMapper method map.
/**
* @param sort api-sort that will be mapped to a data-sort
* @param entityType data-sort entity type
* @throws UnknownSortAttributeException if api-sort contains an unknown entity type attribute
*/
public Sort map(org.molgenis.api.model.Sort sort, EntityType entityType) {
Sort newSort = new Sort();
sort.getOrders().forEach(order -> {
String attributeName = order.getId();
if (entityType.getAttribute(attributeName) == null) {
throw new UnknownSortAttributeException(entityType, attributeName);
}
Order.Direction direction = order.getDirection();
newSort.on(attributeName, direction != null ? Direction.valueOf(direction.name()) : Direction.ASC);
});
return newSort;
}
Aggregations