use of io.crnk.legacy.queryParams.params.IncludedFieldsParams in project crnk-framework by crnk-project.
the class QuerySpecAdapter method addFields.
private void addFields(Map<String, IncludedFieldsParams> params, QuerySpec spec) {
if (!spec.getIncludedFields().isEmpty()) {
Set<String> set = new HashSet<>();
for (IncludeFieldSpec relation : spec.getIncludedFields()) {
set.add(StringUtils.join(".", relation.getAttributePath()));
}
params.put(getResourceType(spec), new IncludedFieldsParams(set));
}
}
use of io.crnk.legacy.queryParams.params.IncludedFieldsParams in project crnk-framework by crnk-project.
the class DocumentMapperUtil method getRequestedFields.
protected static List<ResourceField> getRequestedFields(ResourceInformation resourceInformation, QueryAdapter queryAdapter, List<ResourceField> fields, boolean relation) {
TypedParams<IncludedFieldsParams> includedFieldsSet = queryAdapter != null ? queryAdapter.getIncludedFields() : null;
IncludedFieldsParams includedFields = includedFieldsSet != null ? includedFieldsSet.getParams().get(resourceInformation.getResourceType()) : null;
if (noResourceIncludedFieldsSpecified(includedFields)) {
return fields;
} else {
return computeRequestedFields(includedFields, relation, queryAdapter, resourceInformation, fields);
}
}
use of io.crnk.legacy.queryParams.params.IncludedFieldsParams 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());
}
use of io.crnk.legacy.queryParams.params.IncludedFieldsParams in project crnk-framework by crnk-project.
the class QuerySpecAdapter method getIncludedFields.
@Override
public TypedParams<IncludedFieldsParams> getIncludedFields() {
Map<String, IncludedFieldsParams> params = new HashMap<>();
addFields(params, querySpec);
for (QuerySpec relatedSpec : querySpec.getNestedSpecs()) {
addFields(params, relatedSpec);
}
return new TypedParams<>(params);
}
use of io.crnk.legacy.queryParams.params.IncludedFieldsParams in project crnk-framework by crnk-project.
the class DefaultQueryParamsConverter method applyIncludedFields.
protected void applyIncludedFields(QuerySpec spec, QueryParams queryParams) {
List<IncludeFieldSpec> includedFields = spec.getIncludedFields();
Map<String, IncludedFieldsParams> decodedSparseMap = new LinkedHashMap<>();
if (includedFields != null && !includedFields.isEmpty()) {
String resourceType = getResourceType(spec.getResourceClass());
Set<String> pathSet = new LinkedHashSet<>();
for (IncludeFieldSpec includedField : includedFields) {
String path = joinPath(includedField.getAttributePath());
pathSet.add(path);
}
IncludedFieldsParams includedFieldsParams = new IncludedFieldsParams(pathSet);
decodedSparseMap.put(resourceType, includedFieldsParams);
}
queryParams.setIncludedFields(new TypedParams<>(Collections.unmodifiableMap(decodedSparseMap)));
}
Aggregations