Search in sources :

Example 1 with IncludeRelationSpec

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

the class QuerySpecAdapter method addRelations.

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

Example 2 with IncludeRelationSpec

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

the class DefaultQueryParamsConverter method applyRelatedFields.

protected void applyRelatedFields(QuerySpec spec, QueryParams queryParams) {
    List<IncludeRelationSpec> includedRelations = spec.getIncludedRelations();
    Map<String, IncludedRelationsParams> decodedSparseMap = new LinkedHashMap<>();
    if (includedRelations != null && !includedRelations.isEmpty()) {
        String resourceType = spec.getResourceType() != null ? spec.getResourceType() : getResourceType(spec.getResourceClass());
        Set<Inclusion> inclusions = new LinkedHashSet<>();
        for (IncludeRelationSpec relationSpec : includedRelations) {
            for (String attrPath : relationSpec.getAttributePath()) {
                Inclusion inclusion = new Inclusion(attrPath);
                inclusions.add(inclusion);
            }
        }
        IncludedRelationsParams includedRelationsParams = new IncludedRelationsParams(Collections.unmodifiableSet(inclusions));
        decodedSparseMap.put(resourceType, includedRelationsParams);
    }
    queryParams.setIncludedRelations(new TypedParams<>(Collections.unmodifiableMap(decodedSparseMap)));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IncludeRelationSpec(io.crnk.core.queryspec.IncludeRelationSpec) Inclusion(io.crnk.legacy.queryParams.include.Inclusion) IncludedRelationsParams(io.crnk.legacy.queryParams.params.IncludedRelationsParams) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

IncludeRelationSpec (io.crnk.core.queryspec.IncludeRelationSpec)2 Inclusion (io.crnk.legacy.queryParams.include.Inclusion)2 IncludedRelationsParams (io.crnk.legacy.queryParams.params.IncludedRelationsParams)2 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1