use of org.molgenis.data.Entity in project molgenis by molgenis.
the class DataPersisterImplTest method testPersistMetaNoneDataUpsert.
@SuppressWarnings("unchecked")
@Test
public void testPersistMetaNoneDataUpsert() {
Repository<Entity> repository0 = mock(Repository.class);
when(dataService.getRepository(entityType0.getId())).thenReturn(repository0);
Repository<Entity> repository1 = mock(Repository.class);
when(dataService.getRepository(entityType1.getId())).thenReturn(repository1);
PersistResult persistResult = dataPersisterImpl.persist(dataProvider, MetadataMode.NONE, DataMode.UPSERT);
assertEquals(persistResult, PersistResult.create(ImmutableMap.of(entityType0.getId(), 2L, entityType1.getId(), 3L)));
InOrder inOrder = inOrder(metaDataService, repository0, repository1);
inOrder.verify(repository1).upsertBatch(anyList());
inOrder.verify(repository0).upsertBatch(anyList());
verifyNoMoreInteractions(metaDataService, repository0, repository1);
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class IndexActionRepositoryDecorator method registerRefEntityIndexActions.
/**
* Register index actions for the given entity for entity types with bidirectional attribute values.
*
* @param entity entity to add or delete
*/
private void registerRefEntityIndexActions(Entity entity) {
// bidirectional attribute: register indexing actions for other side
getEntityType().getMappedByAttributes().forEach(mappedByAttr -> {
EntityType mappedByAttrRefEntity = mappedByAttr.getRefEntity();
entity.getEntities(mappedByAttr.getName()).forEach(refEntity -> indexActionRegisterService.register(mappedByAttrRefEntity, refEntity.getIdValue()));
});
getEntityType().getInversedByAttributes().forEach(inversedByAttr -> {
Entity refEntity = entity.getEntity(inversedByAttr.getName());
if (refEntity != null) {
EntityType inversedByAttrRefEntity = inversedByAttr.getRefEntity();
indexActionRegisterService.register(inversedByAttrRefEntity, refEntity.getIdValue());
}
});
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class DataPersisterImpl method persistSecondPass.
private void persistSecondPass(DataProvider dataProvider, List<EntityType> topologicalSortedEntityTypes) {
topologicalSortedEntityTypes.forEach(entityType -> {
EntityType persistedEntityType = persistEntityTypeSecondPass(entityType);
if (dataProvider.hasEntities(entityType)) {
Stream<Entity> entities = dataProvider.getEntities(entityType);
persistEntitiesSecondPass(persistedEntityType, entities);
}
});
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class ExcelEntityTest method setEntity.
@Test
public void setEntity() {
Entity entity = new DynamicEntity(mock(EntityType.class)) {
@Override
protected void validateValueType(String attrName, Object value) {
// noop
}
};
entity.set("attr1", "test1");
entity.set("attr2", "test2");
excelEntity.set(entity);
assertEquals(excelEntity.get("attr1"), "test1");
assertNull(excelEntity.get("attr2"));
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class ExcelRepositoryTest method iterator.
@Test
public void iterator() {
Iterator<Entity> it = excelSheetReader.iterator();
assertTrue(it.hasNext());
Entity row1 = it.next();
assertEquals(row1.get("col1"), "val1");
assertEquals(row1.get("col2"), "val2");
assertTrue(it.hasNext());
Entity row2 = it.next();
assertEquals(row2.get("col1"), "val3");
assertEquals(row2.get("col2"), "val4");
assertTrue(it.hasNext());
Entity row3 = it.next();
assertEquals(row3.get("col1"), "XXX");
assertEquals(row3.get("col2"), "val6");
assertTrue(it.hasNext());
// test number cell (col1) and formula cell (col2)
Entity row4 = it.next();
assertEquals(row4.get("col1"), "1.2");
assertEquals(row4.get("col2"), "2.4");
assertFalse(it.hasNext());
}
Aggregations