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;
}
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));
}
Aggregations