use of io.crnk.legacy.queryParams.include.Inclusion 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));
}
}
use of io.crnk.legacy.queryParams.include.Inclusion 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)));
}
use of io.crnk.legacy.queryParams.include.Inclusion in project crnk-framework by crnk-project.
the class DefaultQueryParamsSerializer method serializeIncludedRelations.
@Override
public Map<String, Set<String>> serializeIncludedRelations(QueryParams queryParams) {
Map<String, Set<String>> map = new HashMap<>();
TypedParams<IncludedRelationsParams> includedRelations = queryParams.getIncludedRelations();
if (includedRelations != null) {
Map<String, IncludedRelationsParams> includedRelationsParamsMap = includedRelations.getParams();
for (Entry<String, IncludedRelationsParams> entry : includedRelationsParamsMap.entrySet()) {
String type = entry.getKey();
Set<Inclusion> inclusions = entry.getValue().getParams();
Set<String> strInclusions = new HashSet<>();
for (Inclusion inclusion : inclusions) {
strInclusions.add(inclusion.getPath());
}
String paramName = RestrictedQueryParamsMembers.include.name() + "[" + type + "]";
map.put(paramName, strInclusions);
}
}
return map;
}
use of io.crnk.legacy.queryParams.include.Inclusion in project crnk-framework by crnk-project.
the class QueryParamsBuilderTest method onGivenIncludedRelationsBuilderShouldReturnRequestParamsWithIncludedRelations.
@Test
public void onGivenIncludedRelationsBuilderShouldReturnRequestParamsWithIncludedRelations() throws ParametersDeserializationException {
// GIVEN
queryParams.put("include[special-users]", new LinkedHashSet<>(Arrays.asList("friends", "foes")));
// WHEN
QueryParams result = sut.buildQueryParams(queryParams);
// THEN
assertThat(result.getIncludedRelations().getParams().get("special-users")).isNotNull();
assertThat(result.getIncludedRelations().getParams().get("special-users").getParams()).containsExactly(new Inclusion("friends"), new Inclusion("foes"));
}
use of io.crnk.legacy.queryParams.include.Inclusion in project crnk-framework by crnk-project.
the class DefaultQueryParamsParserTest method onGivenIncludedRelationsParserShouldReturnOnlyRequestParamsWithIncludedRelations.
@Test
public void onGivenIncludedRelationsParserShouldReturnOnlyRequestParamsWithIncludedRelations() {
// GIVEN
queryParams.put("include[user]", Collections.singleton("name"));
queryParams.put("random[user]", Collections.singleton("surname"));
// WHEN
QueryParams result = parseQueryParams();
// THEN
assertThat(result.getIncludedRelations().getParams().size()).isEqualTo(1);
assertThat(result.getIncludedRelations().getParams().get("user").getParams()).containsOnly(new Inclusion("name"));
}
Aggregations