Search in sources :

Example 11 with EntityMapping

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;
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping)

Example 12 with 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);
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test)

Example 13 with EntityMapping

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);
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) DynamicEntity(org.molgenis.data.support.DynamicEntity) Consumer(java.util.function.Consumer) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Test(org.testng.annotations.Test)

Example 14 with EntityMapping

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);
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget)

Example 15 with EntityMapping

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) UnknownEntityException(org.molgenis.data.UnknownEntityException) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping)

Aggregations

EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)22 Test (org.testng.annotations.Test)16 MappingTarget (org.molgenis.semanticmapper.mapping.model.MappingTarget)12 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)8 EntityType (org.molgenis.data.meta.model.EntityType)8 DynamicEntity (org.molgenis.data.support.DynamicEntity)8 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)8 MappingProject (org.molgenis.semanticmapper.mapping.model.MappingProject)7 Attribute (org.molgenis.data.meta.model.Attribute)6 Entity (org.molgenis.data.Entity)5 User (org.molgenis.data.security.auth.User)4 Menu (org.molgenis.core.ui.menu.Menu)3 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 Relation (org.molgenis.data.semantic.Relation)2 OntologyTerm (org.molgenis.ontology.core.model.OntologyTerm)2