use of io.crnk.legacy.queryParams.params.IncludedRelationsParams in project crnk-framework by crnk-project.
the class QuerySpecAdapter method getIncludedRelations.
@Override
public TypedParams<IncludedRelationsParams> getIncludedRelations() {
Map<String, IncludedRelationsParams> params = new HashMap<>();
addRelations(params, querySpec);
for (QuerySpec relatedSpec : querySpec.getNestedSpecs()) {
addRelations(params, relatedSpec);
}
return new TypedParams<>(params);
}
use of io.crnk.legacy.queryParams.params.IncludedRelationsParams 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.params.IncludedRelationsParams 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.params.IncludedRelationsParams in project crnk-framework by crnk-project.
the class IncludeLookupUtil method isInclusionRequestedForQueryParams.
private boolean isInclusionRequestedForQueryParams(QueryAdapter queryAdapter, List<ResourceField> fieldPath) {
Map<String, IncludedRelationsParams> params = queryAdapter.getIncludedRelations().getParams();
// we have to possibilities for inclusion: by type or dot notation
for (int i = fieldPath.size() - 1; i >= 0; i--) {
String path = toPath(fieldPath, i);
ResourceInformation rootInformation = fieldPath.get(i).getParentResourceInformation();
IncludedRelationsParams includedRelationsParams = params.get(rootInformation.getResourceType());
if (includedRelationsParams != null && contains(includedRelationsParams, path)) {
return true;
}
}
return false;
}
use of io.crnk.legacy.queryParams.params.IncludedRelationsParams in project crnk-framework by crnk-project.
the class QuerySpecAdapterTest method test.
@Test
public void test() {
ModuleRegistry moduleRegistry = new ModuleRegistry();
ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
ResourceInformation resourceInformation = new ResourceInformation(moduleRegistry.getTypeParser(), Task.class, "tasks", null, null, new OffsetLimitPagingBehavior());
resourceRegistry.addEntry(new RegistryEntry(new DirectResponseResourceEntry(null, new ResourceRepositoryInformationImpl("tasks", resourceInformation, RepositoryMethodAccess.ALL))));
QuerySpec spec = new QuerySpec(Task.class);
spec.includeField(Arrays.asList("test"));
spec.includeRelation(Arrays.asList("relation"));
QuerySpecAdapter adapter = new QuerySpecAdapter(spec, resourceRegistry);
Assert.assertEquals(Task.class, adapter.getResourceInformation().getResourceClass());
Assert.assertEquals(spec, adapter.getQuerySpec());
TypedParams<IncludedFieldsParams> includedFields = adapter.getIncludedFields();
IncludedFieldsParams includedFieldsParams = includedFields.getParams().get("tasks");
Assert.assertEquals(1, includedFieldsParams.getParams().size());
Assert.assertEquals("test", includedFieldsParams.getParams().iterator().next());
TypedParams<IncludedRelationsParams> includedRelations = adapter.getIncludedRelations();
IncludedRelationsParams includedRelationsParams = includedRelations.getParams().get("tasks");
Assert.assertEquals(1, includedRelationsParams.getParams().size());
Assert.assertEquals("relation", includedRelationsParams.getParams().iterator().next().getPath());
Assert.assertEquals(new OffsetLimitPagingSpec(), adapter.getPagingSpec());
}
Aggregations