Search in sources :

Example 1 with IncludedFieldsParams

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));
    }
}
Also used : IncludedFieldsParams(io.crnk.legacy.queryParams.params.IncludedFieldsParams) IncludeFieldSpec(io.crnk.core.queryspec.IncludeFieldSpec) HashSet(java.util.HashSet)

Example 2 with IncludedFieldsParams

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);
    }
}
Also used : IncludedFieldsParams(io.crnk.legacy.queryParams.params.IncludedFieldsParams)

Example 3 with IncludedFieldsParams

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());
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) OffsetLimitPagingSpec(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) IncludedRelationsParams(io.crnk.legacy.queryParams.params.IncludedRelationsParams) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) IncludedFieldsParams(io.crnk.legacy.queryParams.params.IncludedFieldsParams) ResourceRepositoryInformationImpl(io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) Test(org.junit.Test)

Example 4 with IncludedFieldsParams

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);
}
Also used : IncludedFieldsParams(io.crnk.legacy.queryParams.params.IncludedFieldsParams) HashMap(java.util.HashMap) TypedParams(io.crnk.legacy.queryParams.params.TypedParams) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 5 with IncludedFieldsParams

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)));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IncludedFieldsParams(io.crnk.legacy.queryParams.params.IncludedFieldsParams) IncludeFieldSpec(io.crnk.core.queryspec.IncludeFieldSpec) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

IncludedFieldsParams (io.crnk.legacy.queryParams.params.IncludedFieldsParams)5 IncludeFieldSpec (io.crnk.core.queryspec.IncludeFieldSpec)2 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)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 IncludedRelationsParams (io.crnk.legacy.queryParams.params.IncludedRelationsParams)1 TypedParams (io.crnk.legacy.queryParams.params.TypedParams)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1