Search in sources :

Example 1 with Builder

use of org.molgenis.api.data.v3.model.EntitiesResponse.Builder in project molgenis by molgenis.

the class EntityMapperImpl method mapRecursive.

private EntityResponse mapRecursive(Entity entity, Selection filter, Selection expand, int depth) {
    if (depth > MAX_DEPTH) {
        throw new IllegalArgumentException("max_depth exceeded: " + depth);
    }
    EntityResponse.Builder builder = EntityResponse.builder();
    if (filter.hasItems()) {
        Map<String, Object> dataMap = new LinkedHashMap<>();
        stream(entity.getEntityType().getAtomicAttributes()).filter(attribute -> filter.hasItem(attribute.getName())).forEach(attribute -> dataMap.put(attribute.getName(), mapRecursive(entity, attribute, filter, expand, depth)));
        builder.setData(dataMap);
    }
    URI uri = createEntityResponseUri(entity);
    return builder.setLinks(LinksResponse.create(null, uri, null)).build();
}
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) EntityResponse(org.molgenis.api.data.v3.model.EntityResponse) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Builder

use of org.molgenis.api.data.v3.model.EntitiesResponse.Builder in project molgenis by molgenis.

the class EntityMapperImpl method map.

@Override
public EntitiesResponse map(EntityCollection entityCollection, Selection filter, Selection expand, int size, int number, int total) {
    EntitiesResponse.Builder builder = mapRecursive(entityCollection, filter, expand, 0);
    LinksResponse linksResponse = LinksUtils.createLinksResponse(number, size, total);
    setPageResponse(entityCollection, builder);
    return builder.setLinks(linksResponse).build();
}
Also used : Builder(org.molgenis.api.data.v3.model.EntitiesResponse.Builder) LinksResponse(org.molgenis.api.model.response.LinksResponse) EntitiesResponse(org.molgenis.api.data.v3.model.EntitiesResponse)

Example 3 with Builder

use of org.molgenis.api.data.v3.model.EntitiesResponse.Builder 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)

Aggregations

EntitiesResponse (org.molgenis.api.data.v3.model.EntitiesResponse)3 Builder (org.molgenis.api.data.v3.model.EntitiesResponse.Builder)3 LinksResponse (org.molgenis.api.model.response.LinksResponse)3 Streams.stream (com.google.common.collect.Streams.stream)2 URI (java.net.URI)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors.toList (java.util.stream.Collectors.toList)2 CheckForNull (javax.annotation.CheckForNull)2 Nullable (javax.annotation.Nullable)2 Page (org.molgenis.api.data.v3.EntityCollection.Page)2 EntityResponse (org.molgenis.api.data.v3.model.EntityResponse)2 Selection (org.molgenis.api.model.Selection)2 LinksUtils (org.molgenis.api.support.LinksUtils)2 MolgenisServletUriComponentsBuilder (org.molgenis.api.support.MolgenisServletUriComponentsBuilder)2 PageUtils.getPageResponse (org.molgenis.api.support.PageUtils.getPageResponse)2 Entity (org.molgenis.data.Entity)2 AttributeType (org.molgenis.data.meta.AttributeType)2 IllegalAttributeTypeException (org.molgenis.data.meta.IllegalAttributeTypeException)2