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);
}
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));
}
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);
}
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);
}
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);
}
Aggregations