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