use of io.crnk.legacy.queryParams.params.SortingParams in project crnk-framework by crnk-project.
the class JsonApiQueryParamsParser method parseSortingParameters.
@Override
protected TypedParams<SortingParams> parseSortingParameters(final QueryParamsParserContext context) {
String sortingKey = RestrictedQueryParamsMembers.sort.name();
Set<String> rawSortingQueryParams = parseDelimitedParameters(context.getParameterValue(sortingKey));
Map<String, SortingParams> decodedSortingMap = new LinkedHashMap<>();
if (!rawSortingQueryParams.isEmpty()) {
Map<String, RestrictedSortingValues> temporarySortingMap = new LinkedHashMap<>();
for (String sortParam : rawSortingQueryParams) {
if (sortParam.startsWith(JSON_API_SORT_INDICATOR_DESC)) {
temporarySortingMap.put(sortParam.substring(1), RestrictedSortingValues.desc);
} else {
temporarySortingMap.put(sortParam, RestrictedSortingValues.asc);
}
}
decodedSortingMap.put(context.getRequestedResourceInformation().getResourceType(), new SortingParams(temporarySortingMap));
}
return new TypedParams<>(Collections.unmodifiableMap(decodedSortingMap));
}
use of io.crnk.legacy.queryParams.params.SortingParams in project crnk-framework by crnk-project.
the class DefaultQueryParamsConverter method applySorting.
protected void applySorting(QuerySpec spec, QueryParams queryParams) {
List<SortSpec> sortSpecs = spec.getSort();
Map<String, SortingParams> decodedSortingMap = new LinkedHashMap<>();
if (sortSpecs != null && !sortSpecs.isEmpty()) {
String resourceType = getResourceType(spec.getResourceClass());
for (SortSpec sortSpec : sortSpecs) {
Map<String, RestrictedSortingValues> sortingValues = new HashMap<>();
String joinedPath = joinPath(sortSpec.getAttributePath());
RestrictedSortingValues sortValue = sortSpec.getDirection() == Direction.DESC ? RestrictedSortingValues.desc : RestrictedSortingValues.asc;
SortingParams sortingParams = new SortingParams(sortingValues);
sortingValues.put(joinedPath, sortValue);
decodedSortingMap.put(resourceType, sortingParams);
}
}
queryParams.setSorting(new TypedParams<>(Collections.unmodifiableMap(decodedSortingMap)));
}
Aggregations