Search in sources :

Example 6 with IncludedRelationsParams

use of io.crnk.legacy.queryParams.params.IncludedRelationsParams in project crnk-framework by crnk-project.

the class DocumentMapperUtil method computeRequestedFields.

private static List<ResourceField> computeRequestedFields(IncludedFieldsParams includedFields, boolean relation, QueryAdapter queryAdapter, ResourceInformation resourceInformation, List<ResourceField> fields) {
    Set<String> includedFieldNames = includedFields.getParams();
    if (relation) {
        // for relations consider both "include" and "fields"
        TypedParams<IncludedRelationsParams> includedRelationsSet = queryAdapter.getIncludedRelations();
        IncludedRelationsParams includedRelations = includedRelationsSet != null ? includedRelationsSet.getParams().get(resourceInformation.getResourceType()) : null;
        if (includedRelations != null) {
            includedFieldNames = new HashSet<>(includedFieldNames);
            for (Inclusion include : includedRelations.getParams()) {
                includedFieldNames.add(include.getPath());
            }
        }
    }
    List<ResourceField> results = new ArrayList<>();
    for (ResourceField field : fields) {
        if (includedFieldNames.contains(field.getJsonName())) {
            results.add(field);
        }
    }
    return results;
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) Inclusion(io.crnk.legacy.queryParams.include.Inclusion) ArrayList(java.util.ArrayList) IncludedRelationsParams(io.crnk.legacy.queryParams.params.IncludedRelationsParams)

Example 7 with IncludedRelationsParams

use of io.crnk.legacy.queryParams.params.IncludedRelationsParams in project crnk-framework by crnk-project.

the class JsonApiQueryParamsParser method parseIncludedRelationsParameters.

@Override
protected TypedParams<IncludedRelationsParams> parseIncludedRelationsParameters(QueryParamsParserContext context) {
    String includeKey = RestrictedQueryParamsMembers.include.name();
    Map<String, Set<String>> inclusions = filterQueryParamsByKey(context, includeKey);
    Map<String, IncludedRelationsParams> decodedInclusions = new LinkedHashMap<>();
    if (inclusions.containsKey(RestrictedQueryParamsMembers.include.name())) {
        Set<Inclusion> inclusionSet = new LinkedHashSet<>();
        for (String inclusion : inclusions.get(RestrictedQueryParamsMembers.include.name())) {
            inclusionSet.add(new Inclusion(inclusion));
        }
        decodedInclusions.put(context.getRequestedResourceInformation().getResourceType(), new IncludedRelationsParams(inclusionSet));
    }
    return new TypedParams<>(Collections.unmodifiableMap(decodedInclusions));
}
Also used : Inclusion(io.crnk.legacy.queryParams.include.Inclusion) TypedParams(io.crnk.legacy.queryParams.params.TypedParams) IncludedRelationsParams(io.crnk.legacy.queryParams.params.IncludedRelationsParams)

Aggregations

IncludedRelationsParams (io.crnk.legacy.queryParams.params.IncludedRelationsParams)7 Inclusion (io.crnk.legacy.queryParams.include.Inclusion)4 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)2 IncludeRelationSpec (io.crnk.core.queryspec.IncludeRelationSpec)2 TypedParams (io.crnk.legacy.queryParams.params.TypedParams)2 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceRepositoryInformationImpl (io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl)1 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)1 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)1 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)1 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)1 ModuleRegistry (io.crnk.core.module.ModuleRegistry)1 QuerySpec (io.crnk.core.queryspec.QuerySpec)1 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)1 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)1 OffsetLimitPagingSpec (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec)1 DirectResponseResourceEntry (io.crnk.legacy.internal.DirectResponseResourceEntry)1 IncludedFieldsParams (io.crnk.legacy.queryParams.params.IncludedFieldsParams)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1