Search in sources :

Example 6 with Sort

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

the class EntityController method getReferencedEntities.

@Transactional(readOnly = true)
@GetMapping("/{entityTypeId}/{entityId}/{fieldId}")
public EntitiesResponse getReferencedEntities(@Valid ReadSubresourceRequest entitiesRequest) {
    String entityTypeId = entitiesRequest.getEntityTypeId();
    String entityId = entitiesRequest.getEntityId();
    String fieldId = entitiesRequest.getFieldId();
    Selection filter = entitiesRequest.getFilter();
    Selection expand = entitiesRequest.getExpand();
    int size = entitiesRequest.getSize();
    int page = entitiesRequest.getPage();
    Sort sort = entitiesRequest.getSort();
    Entities entities = dataServiceV3.findSubresources(entityTypeId, entityId, fieldId, 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());
}
Also used : Selection(org.molgenis.api.model.Selection) Sort(org.molgenis.api.model.Sort) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Sort

use of org.molgenis.api.model.Sort 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());
}
Also used : Selection(org.molgenis.api.model.Selection) Sort(org.molgenis.api.model.Sort) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Sort

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

the class AttributeRequestMapperImpl method mapOrderBy.

@SuppressWarnings({ "unchecked", "UnstableApiUsage" })
private Optional<org.molgenis.data.Sort> mapOrderBy(Object value) {
    List<Object> values = (List<Object>) value;
    ImmutableList<Order> orders = values.stream().map(item -> mapOrderByItem((Map<String, String>) item)).collect(toImmutableList());
    Sort sort = Sort.create(orders);
    return Optional.of(sortMapper.map(sort, attributeFactory.getAttributeMetadata()));
}
Also used : Order(org.molgenis.api.model.Order) Range(org.molgenis.api.metadata.v3.model.Range) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) EntityTypeMetadata(org.molgenis.data.meta.model.EntityTypeMetadata) InvalidKeyException(org.molgenis.api.metadata.v3.exception.InvalidKeyException) UnknownRepositoryException(org.molgenis.data.UnknownRepositoryException) HashMap(java.util.HashMap) Attribute(org.molgenis.data.meta.model.Attribute) MetaDataService(org.molgenis.data.meta.MetaDataService) ArrayList(java.util.ArrayList) CreateEntityTypeRequest(org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest) IS_READ_ONLY(org.molgenis.data.meta.model.AttributeMetadata.IS_READ_ONLY) I18nValue(org.molgenis.api.metadata.v3.model.I18nValue) Order(org.molgenis.api.model.Order) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SortMapper(org.molgenis.api.data.SortMapper) Objects.requireNonNull(java.util.Objects.requireNonNull) Map(java.util.Map) Sort(org.molgenis.api.model.Sort) AttributeMetadata(org.molgenis.data.meta.model.AttributeMetadata) MetadataUtils.setBooleanValue(org.molgenis.api.metadata.v3.MetadataUtils.setBooleanValue) Nullable(javax.annotation.Nullable) DataConverter(org.molgenis.data.DataConverter) MetadataUtils.setEnumOptions(org.molgenis.api.metadata.v3.MetadataUtils.setEnumOptions) IS_UNIQUE(org.molgenis.data.meta.model.AttributeMetadata.IS_UNIQUE) AttributeType(org.molgenis.data.meta.AttributeType) LanguageService.getLanguageCodes(org.molgenis.util.i18n.LanguageService.getLanguageCodes) AttributeFactory(org.molgenis.data.meta.model.AttributeFactory) MetadataUtils.setSequenceNumber(org.molgenis.api.metadata.v3.MetadataUtils.setSequenceNumber) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Maps(com.google.common.collect.Maps) EntityType(org.molgenis.data.meta.model.EntityType) MetadataUtils.getStringValue(org.molgenis.api.metadata.v3.MetadataUtils.getStringValue) UnknownAttributeException(org.molgenis.data.UnknownAttributeException) Builder(org.molgenis.api.model.Order.Builder) List(java.util.List) Component(org.springframework.stereotype.Component) Entry(java.util.Map.Entry) Direction(org.molgenis.api.model.Order.Direction) Repository(org.molgenis.data.Repository) Optional(java.util.Optional) UnsupportedFieldException(org.molgenis.api.metadata.v3.exception.UnsupportedFieldException) CreateAttributeRequest(org.molgenis.api.metadata.v3.model.CreateAttributeRequest) MetadataUtils.setAttributeType(org.molgenis.api.metadata.v3.MetadataUtils.setAttributeType) CheckForNull(javax.annotation.CheckForNull) EntityManager(org.molgenis.data.EntityManager) Sort(org.molgenis.api.model.Sort) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List)

Example 9 with Sort

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

the class MetadataApiControllerTest method testGetAttributes.

@Test
void testGetAttributes() {
    String entityTypeId = "MyEntityTypeId";
    Query query = mock(Query.class);
    Sort sort = mock(Sort.class);
    int size = 1;
    int page = 2;
    ReadAttributesRequest readAttributesRequest = new ReadAttributesRequest();
    readAttributesRequest.setQ(query);
    readAttributesRequest.setSort(sort);
    readAttributesRequest.setSize(size);
    readAttributesRequest.setPage(page);
    Attributes attributes = mock(Attributes.class);
    when(metadataApiService.findAttributes(entityTypeId, query, sort, size, page)).thenReturn(attributes);
    AttributesResponse attributesResponse = mock(AttributesResponse.class);
    when(attributeResponseMapper.toAttributesResponse(attributes, size, page)).thenReturn(attributesResponse);
    assertEquals(attributesResponse, metadataApiController.getAttributes(entityTypeId, readAttributesRequest));
}
Also used : AttributesResponse(org.molgenis.api.metadata.v3.model.AttributesResponse) Query(org.molgenis.api.model.Query) ReadAttributesRequest(org.molgenis.api.metadata.v3.model.ReadAttributesRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) Sort(org.molgenis.api.model.Sort) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 10 with Sort

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

the class MetadataApiController method getEntityTypes.

@Transactional(readOnly = true)
@GetMapping
public EntityTypesResponse getEntityTypes(@Valid ReadEntityTypesRequest entitiesRequest) {
    int size = entitiesRequest.getSize();
    int page = entitiesRequest.getPage();
    Sort sort = entitiesRequest.getSort();
    EntityTypes entityTypes = metadataApiService.findEntityTypes(entitiesRequest.getQ().orElse(null), sort, size, page);
    return entityTypeResponseMapper.toEntityTypesResponse(entityTypes, size, page);
}
Also used : Sort(org.molgenis.api.model.Sort) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Sort (org.molgenis.api.model.Sort)22 Test (org.junit.jupiter.api.Test)17 Query (org.molgenis.api.model.Query)14 EntityType (org.molgenis.data.meta.model.EntityType)14 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)14 Selection (org.molgenis.api.model.Selection)11 Attribute (org.molgenis.data.meta.model.Attribute)11 QueryImpl (org.molgenis.data.support.QueryImpl)8 Entity (org.molgenis.data.Entity)7 Fetch (org.molgenis.data.Fetch)7 Transactional (org.springframework.transaction.annotation.Transactional)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 AttributeMetadata (org.molgenis.data.meta.model.AttributeMetadata)3 EntitiesResponse (org.molgenis.api.data.v3.model.EntitiesResponse)2 QueryRule (org.molgenis.data.QueryRule)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Maps (com.google.common.collect.Maps)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1