Search in sources :

Example 1 with UnknownSortAttributeException

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;
}
Also used : Order(org.molgenis.api.model.Order) UnknownSortAttributeException(org.molgenis.data.UnknownSortAttributeException) Sort(org.molgenis.data.Sort)

Aggregations

Order (org.molgenis.api.model.Order)1 Sort (org.molgenis.data.Sort)1 UnknownSortAttributeException (org.molgenis.data.UnknownSortAttributeException)1