use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.
the class MappingServiceImplTest method getMockEntityMapping.
private EntityMapping getMockEntityMapping(String id, long sourceRows) {
EntityMapping entityMapping = Mockito.mock(EntityMapping.class);
EntityType sourceEntityType = Mockito.mock(EntityType.class);
when(entityMapping.getSourceEntityType()).thenReturn(sourceEntityType);
when(sourceEntityType.getId()).thenReturn(id);
when(dataService.count(id)).thenReturn(sourceRows);
return entityMapping;
}
use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.
the class MappingServiceImplTest method testMaxProgressOneSourceOneBatch.
@Test
public void testMaxProgressOneSourceOneBatch() {
MappingTarget mappingTarget = Mockito.mock(MappingTarget.class);
EntityMapping entityMapping = getMockEntityMapping("a", MAPPING_BATCH_SIZE - 1);
List<EntityMapping> mappings = singletonList(entityMapping);
when(mappingTarget.getEntityMappings()).thenReturn(mappings);
assertEquals(mappingService.calculateMaxProgress(mappingTarget), 1);
}
use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.
the class MappingServiceImplTest method testApplyMappingsToRepoUpsert.
@Test
@SuppressWarnings("unchecked")
public void testApplyMappingsToRepoUpsert() {
Repository<Entity> targetRepo = Mockito.mock(Repository.class);
Repository<Entity> sourceRepo = Mockito.mock(Repository.class);
EntityMapping sourceMapping = Mockito.mock(EntityMapping.class);
when(sourceMapping.getLabel()).thenReturn("sourceMappingLabel");
when(sourceMapping.getName()).thenReturn("sourceMappingID");
when(dataService.getRepository("sourceMappingID")).thenReturn(sourceRepo);
when(targetRepo.count()).thenReturn(3L);
EntityType targetEntityType = Mockito.mock(EntityType.class);
when(targetEntityType.getId()).thenReturn("targetEntityType");
when(targetEntityType.getAtomicAttributes()).thenReturn(newArrayList());
Attribute targetID = Mockito.mock(Attribute.class);
when(targetID.getName()).thenReturn("targetID");
when(targetEntityType.getIdAttribute()).thenReturn(targetID);
when(targetRepo.getEntityType()).thenReturn(targetEntityType);
List<Entity> batch = newArrayList(Mockito.mock(Entity.class), Mockito.mock(Entity.class));
Mockito.doAnswer(invocationOnMock -> {
Consumer<List<Entity>> consumer = (Consumer<List<Entity>>) invocationOnMock.<Consumer>getArgument(0);
consumer.accept(batch);
consumer.accept(batch);
return null;
}).when(sourceRepo).forEachBatched(ArgumentMatchers.any(Consumer.class), ArgumentMatchers.eq(MAPPING_BATCH_SIZE));
mappingService.applyMappingToRepo(sourceMapping, targetRepo, progress);
Mockito.verify(targetRepo, Mockito.times(2)).upsertBatch(ArgumentMatchers.any(List.class));
Mockito.verify(progress, Mockito.times(2)).increment(1);
Mockito.verify(progress).status("Mapping source [sourceMappingLabel]...");
Mockito.verify(progress).status("Mapped 4 [sourceMappingLabel] entities.");
Mockito.verifyNoMoreInteractions(progress);
}
use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.
the class MappingTargetRepositoryImpl method toMappingTarget.
/**
* Creates a fully reconstructed MappingProject from an Entity retrieved from the repository.
*
* @param mappingTargetEntity Entity with {@link MappingProjectMetaData} metadata
* @return fully reconstructed MappingProject
*/
private MappingTarget toMappingTarget(Entity mappingTargetEntity) {
List<EntityMapping> entityMappings = Collections.emptyList();
String identifier = mappingTargetEntity.getString(MappingTargetMetaData.IDENTIFIER);
if (!dataService.hasRepository(mappingTargetEntity.getString(MappingTargetMetaData.TARGET))) {
return null;
}
EntityType target = dataService.getEntityType(mappingTargetEntity.getString(MappingTargetMetaData.TARGET));
if (mappingTargetEntity.getEntities(MappingTargetMetaData.ENTITY_MAPPINGS) != null) {
List<Entity> entityMappingEntities = Lists.newArrayList(mappingTargetEntity.getEntities(MappingTargetMetaData.ENTITY_MAPPINGS));
entityMappings = entityMappingRepository.toEntityMappings(entityMappingEntities);
}
return new MappingTarget(identifier, target, entityMappings);
}
use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.
the class EntityMappingRepositoryImpl method toEntityMapping.
private EntityMapping toEntityMapping(Entity entityMappingEntity) {
String identifier = entityMappingEntity.getString(EntityMappingMetaData.IDENTIFIER);
EntityType targetEntityType;
try {
targetEntityType = dataService.getEntityType(entityMappingEntity.getString(EntityMappingMetaData.TARGET_ENTITY_TYPE));
} catch (UnknownEntityException uee) {
LOG.error(uee.getMessage());
targetEntityType = null;
}
EntityType sourceEntityType;
try {
sourceEntityType = dataService.getEntityType(entityMappingEntity.getString(EntityMappingMetaData.SOURCE_ENTITY_TYPE));
} catch (UnknownEntityException uee) {
LOG.error(uee.getMessage());
sourceEntityType = null;
}
List<Entity> attributeMappingEntities = Lists.newArrayList(entityMappingEntity.getEntities(EntityMappingMetaData.ATTRIBUTE_MAPPINGS));
List<AttributeMapping> attributeMappings = attributeMappingRepository.getAttributeMappings(attributeMappingEntities, sourceEntityType, targetEntityType);
return new EntityMapping(identifier, sourceEntityType, targetEntityType, attributeMappings);
}
Aggregations