Search in sources :

Example 31 with Selection

use of org.molgenis.api.model.Selection in project molgenis by molgenis.

the class EntityMapperImpl method mapRecursive.

private EntitiesResponse.Builder mapRecursive(EntityCollection entityCollection, Selection filter, Selection expand, int depth) {
    if (depth > MAX_DEPTH) {
        throw new IllegalArgumentException("max_depth exceeded: " + depth);
    }
    EntitiesResponse.Builder builder = EntitiesResponse.builder();
    if (filter.hasItems()) {
        List<EntityResponse> entityResponses = entityCollection.getEntities().stream().map(entity -> mapRecursive(entity, filter, expand, depth)).collect(toList());
        builder.setItems(entityResponses);
    }
    return builder;
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) AttributeType(org.molgenis.data.meta.AttributeType) Builder(org.molgenis.api.data.v3.model.EntitiesResponse.Builder) MolgenisServletUriComponentsBuilder(org.molgenis.api.support.MolgenisServletUriComponentsBuilder) IllegalAttributeTypeException(org.molgenis.data.meta.IllegalAttributeTypeException) Selection(org.molgenis.api.model.Selection) LinksUtils(org.molgenis.api.support.LinksUtils) LinksResponse(org.molgenis.api.model.response.LinksResponse) Attribute(org.molgenis.data.meta.model.Attribute) EntitiesResponse(org.molgenis.api.data.v3.model.EntitiesResponse) Streams.stream(com.google.common.collect.Streams.stream) LinkedHashMap(java.util.LinkedHashMap) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Component(org.springframework.stereotype.Component) EntityResponse(org.molgenis.api.data.v3.model.EntityResponse) Map(java.util.Map) PageUtils.getPageResponse(org.molgenis.api.support.PageUtils.getPageResponse) URI(java.net.URI) CheckForNull(javax.annotation.CheckForNull) Nullable(javax.annotation.Nullable) Page(org.molgenis.api.data.v3.EntityCollection.Page) Entity(org.molgenis.data.Entity) Builder(org.molgenis.api.data.v3.model.EntitiesResponse.Builder) EntityResponse(org.molgenis.api.data.v3.model.EntityResponse) EntitiesResponse(org.molgenis.api.data.v3.model.EntitiesResponse)

Example 32 with Selection

use of org.molgenis.api.model.Selection in project molgenis by molgenis.

the class EntityMapperImpl method mapReference.

@Nullable
@CheckForNull
private EntityResponse mapReference(Entity entity, Attribute attribute, Selection filter, Selection expand, int depth) {
    Entity refEntity = entity.getEntity(attribute.getName());
    if (refEntity == null) {
        // since the link would results in a 404 when requested.
        return null;
    }
    Selection refFilter = getReferenceFilter(attribute, filter, expand);
    Selection refExpand = getReferenceExpand(attribute, expand);
    return mapRecursive(refEntity, refFilter, refExpand, depth);
}
Also used : Entity(org.molgenis.data.Entity) Selection(org.molgenis.api.model.Selection) CheckForNull(javax.annotation.CheckForNull) Nullable(javax.annotation.Nullable)

Aggregations

Selection (org.molgenis.api.model.Selection)32 Test (org.junit.jupiter.api.Test)24 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)19 Entity (org.molgenis.data.Entity)18 Attribute (org.molgenis.data.meta.model.Attribute)15 EntityType (org.molgenis.data.meta.model.EntityType)13 Fetch (org.molgenis.data.Fetch)12 Sort (org.molgenis.api.model.Sort)11 Query (org.molgenis.api.model.Query)9 QueryImpl (org.molgenis.data.support.QueryImpl)7 URI (java.net.URI)5 EntityResponse (org.molgenis.api.data.v3.model.EntityResponse)5 CheckForNull (javax.annotation.CheckForNull)4 Nullable (javax.annotation.Nullable)4 EntitiesResponse (org.molgenis.api.data.v3.model.EntitiesResponse)4 HashMap (java.util.HashMap)3 Transactional (org.springframework.transaction.annotation.Transactional)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 Streams.stream (com.google.common.collect.Streams.stream)2 LinkedHashMap (java.util.LinkedHashMap)2