Search in sources :

Example 11 with MappingTarget

use of org.molgenis.semanticmapper.mapping.model.MappingTarget in project molgenis by molgenis.

the class MappingServiceImplTest method testIncompatibleMetaDataDifferentRefEntity.

@Test(expectedExceptions = MolgenisDataException.class, expectedExceptionsMessageRegExp = "In the mapping target, attribute COUNTRY of type XREF has " + "reference entity mapping_target_ref while in the target repository attribute COUNTRY of type XREF has reference entity target_repository_ref. " + "Please make sure the reference entities of your mapping target are pointing towards the same reference entities as your target repository")
public void testIncompatibleMetaDataDifferentRefEntity() {
    String targetRepositoryName = "target_repository";
    String targetRepositoryRefEntityName = "target_repository_ref";
    String mappingTargetRefEntityName = "mapping_target_ref";
    EntityType targetRefEntity = entityTypeFactory.create(targetRepositoryRefEntityName);
    @SuppressWarnings("unchecked") Repository<Entity> targetRepository = Mockito.mock(Repository.class);
    EntityType targetRepositoryMetaData = entityTypeFactory.create(targetRepositoryName);
    targetRepositoryMetaData.addAttribute(attrMetaFactory.create().setName("ID").setDataType(STRING), ROLE_ID);
    targetRepositoryMetaData.addAttribute(attrMetaFactory.create().setName("COUNTRY").setDataType(XREF).setRefEntity(targetRefEntity));
    targetRepositoryMetaData.setPackage(package_);
    when(dataService.hasRepository(targetRepositoryName)).thenReturn(true);
    when(dataService.getRepository(targetRepositoryName)).thenReturn(targetRepository);
    when(targetRepository.getEntityType()).thenReturn(targetRepositoryMetaData);
    EntityType mappingTargetRefEntity = entityTypeFactory.create(mappingTargetRefEntityName);
    EntityType mappingTargetMetaData = entityTypeFactory.create("mapping_target");
    mappingTargetMetaData.addAttribute(attrMetaFactory.create().setName("ID").setDataType(STRING), ROLE_ID);
    mappingTargetMetaData.addAttribute(attrMetaFactory.create().setName("COUNTRY").setDataType(XREF).setRefEntity(mappingTargetRefEntity));
    mappingTargetMetaData.setPackage(package_);
    when(metaDataService.createRepository(mappingTargetMetaData)).thenReturn(targetRepository);
    MappingTarget mappingTarget = new MappingTarget(mappingTargetMetaData);
    MappingProject mappingProject = Mockito.mock(MappingProject.class);
    when(mappingProject.getMappingTargets()).thenReturn(newArrayList(mappingTarget));
    when(mappingProjectRepo.getMappingProject("TestRun")).thenReturn(mappingProject);
    mappingService.applyMappings("TestRun", targetRepositoryName, false, "packageId", "label", progress);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test)

Example 12 with MappingTarget

use of org.molgenis.semanticmapper.mapping.model.MappingTarget in project molgenis by molgenis.

the class MappingServiceImplTest method createMetaWithNonNullParameters.

@Test
public void createMetaWithNonNullParameters() {
    MappingTarget mappingTarget = Mockito.mock(MappingTarget.class);
    when(mappingTarget.getTarget()).thenReturn(hopMetaData);
    Package targetPackage = Mockito.mock(Package.class);
    when(metaDataService.getPackage("targetPackage")).thenReturn(targetPackage);
    EntityType targetMetadata = mappingService.createTargetMetadata(mappingTarget, "test", "targetPackage", "target label", true);
    assertEquals(targetMetadata.getId(), "test");
    assertEquals(targetMetadata.getLabel(), "target label");
    assertEquals(targetMetadata.getPackage(), targetPackage);
    Assert.assertNotNull(targetMetadata.getAttribute(SOURCE));
}
Also used : DefaultPackage(org.molgenis.data.meta.DefaultPackage) Package(org.molgenis.data.meta.model.Package) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test)

Example 13 with MappingTarget

use of org.molgenis.semanticmapper.mapping.model.MappingTarget in project molgenis by molgenis.

the class MappingProjectRepositoryImpl method toMappingProject.

/**
 * Creates a fully reconstructed MappingProject from an Entity retrieved from the repository.
 *
 * @param mappingProjectEntity Entity with {@link MappingProjectMetaData} metadata
 * @return fully reconstructed MappingProject
 */
private MappingProject toMappingProject(Entity mappingProjectEntity) {
    String identifier = mappingProjectEntity.getString(MappingProjectMetaData.IDENTIFIER);
    String name = mappingProjectEntity.getString(MappingProjectMetaData.NAME);
    User owner = mappingProjectEntity.getEntity(MappingProjectMetaData.OWNER, User.class);
    List<Entity> mappingTargetEntities = Lists.newArrayList(mappingProjectEntity.getEntities(MappingProjectMetaData.MAPPING_TARGETS));
    List<MappingTarget> mappingTargets = mappingTargetRepo.toMappingTargets(mappingTargetEntities);
    return new MappingProject(identifier, name, owner, mappingTargets);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) User(org.molgenis.data.security.auth.User) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget)

Example 14 with MappingTarget

use of org.molgenis.semanticmapper.mapping.model.MappingTarget 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 MappingTarget

use of org.molgenis.semanticmapper.mapping.model.MappingTarget in project molgenis by molgenis.

the class MappingServiceImpl method applyMappings.

@Override
@Transactional
public long applyMappings(String mappingProjectId, String entityTypeId, Boolean addSourceAttribute, String packageId, String label, Progress progress) {
    MappingProject mappingProject = getMappingProject(mappingProjectId);
    MappingTarget mappingTarget = mappingProject.getMappingTargets().get(0);
    progress.setProgressMax(calculateMaxProgress(mappingTarget));
    progress.progress(0, format("Checking target repository [%s]...", entityTypeId));
    EntityType targetMetadata = createTargetMetadata(mappingTarget, entityTypeId, packageId, label, addSourceAttribute);
    Repository<Entity> targetRepo = getTargetRepository(entityTypeId, targetMetadata);
    return applyMappingsInternal(mappingTarget, targetRepo, progress);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

MappingTarget (org.molgenis.semanticmapper.mapping.model.MappingTarget)22 Test (org.testng.annotations.Test)16 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)12 MappingProject (org.molgenis.semanticmapper.mapping.model.MappingProject)12 DynamicEntity (org.molgenis.data.support.DynamicEntity)7 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)5 Menu (org.molgenis.core.ui.menu.Menu)4 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)4 Entity (org.molgenis.data.Entity)3 EntityType (org.molgenis.data.meta.model.EntityType)3 User (org.molgenis.data.security.auth.User)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 DefaultPackage (org.molgenis.data.meta.DefaultPackage)1 Attribute (org.molgenis.data.meta.model.Attribute)1 Package (org.molgenis.data.meta.model.Package)1 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1 Transactional (org.springframework.transaction.annotation.Transactional)1