use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class EntityController method getEntity.
@Transactional(readOnly = true)
@GetMapping("/{entityTypeId}/{entityId}")
public EntityResponse getEntity(@Valid ReadEntityRequest entityRequest) {
Selection filter = entityRequest.getFilter();
Selection expand = entityRequest.getExpand();
Entity entity = dataServiceV3.find(entityRequest.getEntityTypeId(), entityRequest.getEntityId(), filter, expand);
return entityMapper.map(entity, filter, expand);
}
use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class EntityController method getEntities.
@Transactional(readOnly = true)
@GetMapping("/{entityTypeId}")
public EntitiesResponse getEntities(@Valid ReadEntitiesRequest entitiesRequest) {
String entityTypeId = entitiesRequest.getEntityTypeId();
Selection filter = entitiesRequest.getFilter();
Selection expand = entitiesRequest.getExpand();
int size = entitiesRequest.getSize();
int page = entitiesRequest.getPage();
Sort sort = entitiesRequest.getSort();
Entities entities = dataServiceV3.findAll(entityTypeId, entitiesRequest.getQ().orElse(null), filter, expand, sort, size, page);
EntityCollection entityCollection = EntityCollection.builder().setEntityTypeId(entityTypeId).setEntities(entities.getEntities()).setPage(Page.builder().setOffset(size * page).setPageSize(size).setTotal(entities.getTotal()).build()).build();
return entityMapper.map(entityCollection, filter, expand, size, page, entities.getTotal());
}
use of org.molgenis.api.model.Selection 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();
}
use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class FetchMapper method toFetch.
@CheckForNull
@Nullable
public Fetch toFetch(EntityType entityType, Selection filter, Selection expand) {
if (!filter.hasItems()) {
return null;
}
Fetch fetch = new Fetch();
Iterable<Attribute> attributes = entityType.getAtomicAttributes();
attributes.forEach(attribute -> {
String attributeName = attribute.getName();
if (filter.hasItem(attributeName)) {
Fetch subFetch;
if (expand.hasItem(attributeName) && EntityTypeUtils.isReferenceType(attribute)) {
Selection subFilter = filter.getSelection(attributeName).orElse(EMPTY_SELECTION);
Selection subExpand = expand.getSelection(attributeName).orElse(EMPTY_SELECTION);
subFetch = toFetch(attribute.getRefEntity(), subFilter, subExpand);
} else {
subFetch = null;
}
fetch.field(attributeName, subFetch);
}
});
return fetch;
}
use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class SelectionParserTest method testMultipleItemsSubSelection.
@Test
void testMultipleItemsSubSelection() throws ParseException {
Map<String, Selection> itemSelections = new HashMap<>();
itemSelections.put("abc", new Selection(Collections.singletonMap("def", null)));
itemSelections.put("ghi", new Selection(Collections.singletonMap("jkl", null)));
assertEquals(new Selection(itemSelections), new SelectionParser("abc(def),ghi(jkl)").parse());
}
Aggregations