Search in sources :

Example 11 with MappingProject

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

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

the class MappingServiceImplTest method testAddExistingTarget.

@Test(expectedExceptions = IllegalStateException.class)
public void testAddExistingTarget() {
    MappingProject mappingProject = mappingService.addMappingProject("Test123", user, hopMetaData.getId());
    mappingProject.addTarget(hopMetaData);
}
Also used : MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) Test(org.testng.annotations.Test)

Example 13 with MappingProject

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

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

the class MappingServiceImpl method addMappingProject.

@Override
@RunAsSystem
@Transactional
public MappingProject addMappingProject(String projectName, User owner, String target) {
    MappingProject mappingProject = new MappingProject(projectName, owner);
    mappingProject.addTarget(dataService.getEntityType(target));
    mappingProjectRepository.add(mappingProject);
    return mappingProject;
}
Also used : MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with MappingProject

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

the class MappingProjectRepositoryImpl method update.

@Override
@Transactional
public void update(MappingProject mappingProject) {
    MappingProject existing = getMappingProject(mappingProject.getIdentifier());
    if (existing == null) {
        throw new MolgenisDataException("MappingProject does not exist");
    }
    Entity mappingProjectEntity = toEntity(mappingProject);
    dataService.update(MAPPING_PROJECT, mappingProjectEntity);
}
Also used : MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) MolgenisDataException(org.molgenis.data.MolgenisDataException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

MappingProject (org.molgenis.semanticmapper.mapping.model.MappingProject)26 Test (org.testng.annotations.Test)18 MappingTarget (org.molgenis.semanticmapper.mapping.model.MappingTarget)14 DynamicEntity (org.molgenis.data.support.DynamicEntity)9 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)9 User (org.molgenis.data.security.auth.User)7 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)6 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)6 EntityType (org.molgenis.data.meta.model.EntityType)5 BeforeMethod (org.testng.annotations.BeforeMethod)4 Menu (org.molgenis.core.ui.menu.Menu)3 Attribute (org.molgenis.data.meta.model.Attribute)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Lists (com.google.common.collect.Lists)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2