Search in sources :

Example 1 with IncludeFieldSpec

use of io.crnk.core.queryspec.IncludeFieldSpec in project crnk-framework by crnk-project.

the class QuerySpecAdapter method addFields.

private void addFields(Map<String, IncludedFieldsParams> params, QuerySpec spec) {
    if (!spec.getIncludedFields().isEmpty()) {
        Set<String> set = new HashSet<>();
        for (IncludeFieldSpec relation : spec.getIncludedFields()) {
            set.add(StringUtils.join(".", relation.getAttributePath()));
        }
        params.put(getResourceType(spec), new IncludedFieldsParams(set));
    }
}
Also used : IncludedFieldsParams(io.crnk.legacy.queryParams.params.IncludedFieldsParams) IncludeFieldSpec(io.crnk.core.queryspec.IncludeFieldSpec) HashSet(java.util.HashSet)

Example 2 with IncludeFieldSpec

use of io.crnk.core.queryspec.IncludeFieldSpec in project crnk-framework by crnk-project.

the class DefaultQueryParamsConverter method applyIncludedFields.

protected void applyIncludedFields(QuerySpec spec, QueryParams queryParams) {
    List<IncludeFieldSpec> includedFields = spec.getIncludedFields();
    Map<String, IncludedFieldsParams> decodedSparseMap = new LinkedHashMap<>();
    if (includedFields != null && !includedFields.isEmpty()) {
        String resourceType = getResourceType(spec.getResourceClass());
        Set<String> pathSet = new LinkedHashSet<>();
        for (IncludeFieldSpec includedField : includedFields) {
            String path = joinPath(includedField.getAttributePath());
            pathSet.add(path);
        }
        IncludedFieldsParams includedFieldsParams = new IncludedFieldsParams(pathSet);
        decodedSparseMap.put(resourceType, includedFieldsParams);
    }
    queryParams.setIncludedFields(new TypedParams<>(Collections.unmodifiableMap(decodedSparseMap)));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IncludedFieldsParams(io.crnk.legacy.queryParams.params.IncludedFieldsParams) IncludeFieldSpec(io.crnk.core.queryspec.IncludeFieldSpec) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with IncludeFieldSpec

use of io.crnk.core.queryspec.IncludeFieldSpec in project crnk-framework by crnk-project.

the class QueryBuilder method applySelectionSpec.

public Map<String, Integer> applySelectionSpec() {
    MetaDataObject meta = query.getMeta();
    Map<String, Integer> selectionBindings = new HashMap<>();
    int index = 1;
    List<IncludeFieldSpec> includedFields = query.getIncludedFields();
    for (IncludeFieldSpec includedField : includedFields) {
        MetaAttributePath path = meta.resolvePath(includedField.getAttributePath(), attributeFinder);
        E attr = backend.getAttribute(path);
        backend.addSelection(attr, path.toString());
        selectionBindings.put(path.toString(), index++);
    }
    return selectionBindings;
}
Also used : HashMap(java.util.HashMap) MetaDataObject(io.crnk.meta.model.MetaDataObject) IncludeFieldSpec(io.crnk.core.queryspec.IncludeFieldSpec) MetaAttributePath(io.crnk.meta.model.MetaAttributePath)

Aggregations

IncludeFieldSpec (io.crnk.core.queryspec.IncludeFieldSpec)3 IncludedFieldsParams (io.crnk.legacy.queryParams.params.IncludedFieldsParams)2 MetaAttributePath (io.crnk.meta.model.MetaAttributePath)1 MetaDataObject (io.crnk.meta.model.MetaDataObject)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1