use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class DataServiceV3ImplTest method testFindAllUnknownRepositoryUnknownEntity.
@Test
void testFindAllUnknownRepositoryUnknownEntity() {
String entityTypeId = "MyEntityType";
Selection filter = Selection.FULL_SELECTION;
Selection expand = Selection.EMPTY_SELECTION;
when(metaDataService.getRepository(entityTypeId)).thenReturn(Optional.empty());
assertThrows(UnknownRepositoryException.class, () -> dataServiceV3Impl.findAll(entityTypeId, null, filter, expand, Sort.EMPTY_SORT, 1, 1));
}
use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class EntityControllerTest method testGetEntities.
@Test
void testGetEntities() {
String entityTypeId = "MyEntityTypeId";
Selection filter = Selection.FULL_SELECTION;
Selection expand = Selection.FULL_SELECTION;
Query query = Query.builder().setOperator(Operator.MATCHES).setValue("value").build();
Sort sort = Sort.create("field", Direction.ASC);
ReadEntitiesRequest entityRequest = new ReadEntitiesRequest();
entityRequest.setEntityTypeId(entityTypeId);
entityRequest.setQ(query);
entityRequest.setSort(sort);
entityRequest.setFilter(filter);
entityRequest.setExpand(expand);
entityRequest.setSize(10);
entityRequest.setPage(2);
Entities entities = Entities.create(emptyList(), 30);
when(dataServiceV3.findAll(entityTypeId, query, filter, expand, sort, 10, 2)).thenReturn(entities);
EntityCollection entityCollection = EntityCollection.builder().setEntityTypeId(entityTypeId).setEntities(emptyList()).setPage(Page.builder().setOffset(20).setPageSize(10).setTotal(30).build()).build();
EntitiesResponse entitiesResponse = mock(EntitiesResponse.class);
when(entityMapper.map(entityCollection, filter, expand, 10, 2, 30)).thenReturn(entitiesResponse);
assertEquals(entitiesResponse, entityController.getEntities(entityRequest));
}
use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class EntityMapperImplTest method testMapEntityExpandXref.
@Test
void testMapEntityExpandXref() throws URISyntaxException {
Entity refRefEntity = createMockEntity(XREF, "RefRefEntityType", "refRefId0");
Entity refEntity = createMockEntity(XREF, "RefEntityType", "refId0");
Entity entity = createMockEntity(XREF);
doReturn(refRefEntity).when(refEntity).getEntity("attr");
doReturn(refEntity).when(entity).getEntity("attr");
URI refRefSelf = new URI("http://localhost/api/data/RefRefEntityType/refRefId0");
EntityResponse expectedRefRefEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, refRefSelf, null)).build();
URI refSelf = new URI("http://localhost/api/data/RefEntityType/refId0");
EntityResponse expectedRefEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, refSelf, null)).setData(singletonMap("attr", expectedRefRefEntityResponse)).build();
URI self = new URI("http://localhost/api/data/EntityType/id0");
EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, self, null)).setData(singletonMap("attr", expectedRefEntityResponse)).build();
assertEquals(expectedEntityResponse, entityMapper.map(entity, FULL_SELECTION, new Selection(singletonMap("attr", null))));
}
use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class FetchMapperTest method testToFetch.
@Test
void testToFetch() {
EntityType entityType = mock(EntityType.class);
Attribute attribute = mock(Attribute.class);
when(attribute.getName()).thenReturn("test");
Attribute attributeXref = mock(Attribute.class);
when(attributeXref.getName()).thenReturn("xref");
when(attributeXref.getDataType()).thenReturn(AttributeType.XREF);
when(entityType.getAtomicAttributes()).thenReturn(Arrays.asList(attribute, attributeXref));
Selection expand = new Selection(Collections.singletonMap("xref", Selection.FULL_SELECTION));
Selection filter = Selection.FULL_SELECTION;
Fetch expected = new Fetch().field("xref").field("test");
assertEquals(expected, fetchMapper.toFetch(entityType, filter, expand));
}
use of org.molgenis.api.model.Selection 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());
}
Aggregations