Search in sources :

Example 1 with SortingParams

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));
}
Also used : TypedParams(io.crnk.legacy.queryParams.params.TypedParams) SortingParams(io.crnk.legacy.queryParams.params.SortingParams)

Example 2 with SortingParams

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)));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SortSpec(io.crnk.core.queryspec.SortSpec) SortingParams(io.crnk.legacy.queryParams.params.SortingParams) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

SortingParams (io.crnk.legacy.queryParams.params.SortingParams)2 SortSpec (io.crnk.core.queryspec.SortSpec)1 TypedParams (io.crnk.legacy.queryParams.params.TypedParams)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1