Search in sources :

Example 1 with SortingDirection

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo.SortingDirection in project pnc by project-ncl.

the class SortRSQLNodeTraveller method visit.

@Override
public SortInfo visit(ComparisonNode node) {
    SortingDirection sortingDirection;
    List<String> sortingFields = new ArrayList<>();
    if (node.getOperator().equals(ASC)) {
        sortingDirection = SortInfo.SortingDirection.ASC;
    } else if (node.getOperator().equals(DESC)) {
        sortingDirection = SortInfo.SortingDirection.DESC;
    } else {
        throw new UnsupportedOperationException("Unsupported sorting: " + node.getOperator());
    }
    logger.trace("Sorting direction - {}, arguments {}", sortingDirection, node.getArguments());
    for (String argument : node.getArguments()) {
        if ("id".equals(argument)) {
            // Disable sorting by id
            throw new RSQLException("Sorting by id is not supported.");
        }
        sortingFields.add(toPath.apply(RSQLSelectorPath.get(argument)));
    }
    return new DefaultSortInfo(sortingDirection, sortingFields);
}
Also used : ArrayList(java.util.ArrayList) SortingDirection(org.jboss.pnc.spi.datastore.repositories.api.SortInfo.SortingDirection) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)

Aggregations

ArrayList (java.util.ArrayList)1 SortingDirection (org.jboss.pnc.spi.datastore.repositories.api.SortInfo.SortingDirection)1 DefaultSortInfo (org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)1