Search in sources :

Example 1 with IncludedRelationsParams

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

Example 2 with IncludedRelationsParams

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

Example 3 with IncludedRelationsParams

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

Example 4 with IncludedRelationsParams

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;
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) IncludedRelationsParams(io.crnk.legacy.queryParams.params.IncludedRelationsParams)

Example 5 with IncludedRelationsParams

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

Aggregations

IncludedRelationsParams (io.crnk.legacy.queryParams.params.IncludedRelationsParams)7 Inclusion (io.crnk.legacy.queryParams.include.Inclusion)4 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)2 IncludeRelationSpec (io.crnk.core.queryspec.IncludeRelationSpec)2 TypedParams (io.crnk.legacy.queryParams.params.TypedParams)2 ResourceField (io.crnk.core.engine.information.resource.ResourceField)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 IncludedFieldsParams (io.crnk.legacy.queryParams.params.IncludedFieldsParams)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1