use of org.molgenis.semanticmapper.mapping.model.MappingProject in project molgenis by molgenis.
the class AlgorithmServiceImplIT method testWhenSourceHasMultipleMatchesThenFirstMappingGetsCreated.
@Test
public void testWhenSourceHasMultipleMatchesThenFirstMappingGetsCreated() {
EntityType targetEntityType = entityTypeFactory.create("target");
Attribute targetAttribute = attrMetaFactory.create().setName("targetHeight");
targetAttribute.setDescription("height");
targetEntityType.addAttribute(targetAttribute);
EntityType sourceEntityType = entityTypeFactory.create("source");
Attribute sourceAttribute1 = attrMetaFactory.create().setName("sourceHeight1");
sourceAttribute1.setDescription("height");
Attribute sourceAttribute2 = attrMetaFactory.create().setName("sourceHeight2");
sourceAttribute2.setDescription("height");
sourceEntityType.addAttributes(Arrays.asList(sourceAttribute1, sourceAttribute2));
User owner = userFactory.create();
owner.setUsername("flup");
owner.setPassword("geheim");
owner.setId("12345");
owner.setActive(true);
owner.setEmail("flup@blah.com");
owner.setFirstName("Flup");
owner.setLastName("de Flap");
MappingProject project = new MappingProject("project", owner);
project.addTarget(targetEntityType);
EntityMapping mapping = project.getMappingTarget("target").addSource(sourceEntityType);
Map<Attribute, ExplainedAttribute> mappings = ImmutableMap.of(sourceAttribute1, ExplainedAttribute.create(sourceAttribute1), sourceAttribute2, ExplainedAttribute.create(sourceAttribute2));
LinkedHashMultimap<Relation, OntologyTerm> ontologyTermTags = LinkedHashMultimap.create();
when(semanticSearchService.decisionTreeToFindRelevantAttributes(sourceEntityType, targetAttribute, ontologyTermTags.values(), null)).thenReturn(mappings);
when(ontologyTagService.getTagsForAttribute(targetEntityType, targetAttribute)).thenReturn(ontologyTermTags);
algorithmService.autoGenerateAlgorithm(sourceEntityType, targetEntityType, mapping, targetAttribute);
assertEquals(mapping.getAttributeMapping("targetHeight").getSourceAttributes().get(0), sourceAttribute1);
}
use of org.molgenis.semanticmapper.mapping.model.MappingProject in project molgenis by molgenis.
the class MappingServiceImplTest method createMappingProjectWithMappings.
private MappingProject createMappingProjectWithMappings() {
MappingProject mappingProject = mappingService.addMappingProject("TestRun", user, hopMetaData.getId());
MappingTarget target = mappingProject.getMappingTarget(hopMetaData.getId());
when(mappingProjectRepo.getMappingProject("TestRun")).thenReturn(mappingProject);
EntityMapping mapping = target.addSource(geneMetaData);
AttributeMapping idMapping = mapping.addAttributeMapping("identifier");
idMapping.setAlgorithm("$('id').value()");
AttributeMapping attrMapping = mapping.addAttributeMapping("height");
attrMapping.setAlgorithm("$('length').value()");
return mappingProject;
}
use of org.molgenis.semanticmapper.mapping.model.MappingProject in project molgenis by molgenis.
the class MappingServiceImplTest method testUpdateMappingProject.
@Test
public void testUpdateMappingProject() {
MappingProject mappingProject = Mockito.mock(MappingProject.class);
mappingService.updateMappingProject(mappingProject);
Mockito.verifyZeroInteractions(mappingProject);
Mockito.verify(mappingProjectRepo).update(mappingProject);
}
use of org.molgenis.semanticmapper.mapping.model.MappingProject in project molgenis by molgenis.
the class MappingServiceImplTest method testApplyMappingsUpdate.
/**
* Applying a mapping multiple times to the same target should update the existing entities.
*/
@SuppressWarnings("unchecked")
@Test
public void testApplyMappingsUpdate() {
String entityTypeId = "updateEntity";
@SuppressWarnings("unchecked") Repository<Entity> updateEntityRepo = Mockito.mock(Repository.class);
when(updateEntityRepo.getName()).thenReturn(entityTypeId);
EntityType targetMeta = entityTypeFactory.create(TARGET_HOP_ENTITY).setPackage(package_);
targetMeta.addAttribute(attrMetaFactory.create().setName("identifier"), ROLE_ID);
targetMeta.addAttribute(attrMetaFactory.create().setName("height").setDataType(DECIMAL).setNillable(false));
targetMeta.addAttribute(attrMetaFactory.create().setName("source"));
when(dataService.hasRepository(entityTypeId)).thenReturn(true);
when(dataService.getRepository(entityTypeId)).thenReturn(updateEntityRepo);
when(updateEntityRepo.getEntityType()).thenReturn(targetMeta);
when(metaDataService.createRepository(argThat(obj -> obj.getLabel().equals(entityTypeId)))).thenReturn(updateEntityRepo);
// add an entity to the source
List<Entity> sourceGeneEntities = newArrayList();
List<Entity> expectedEntities = newArrayList();
createEntities(targetMeta, sourceGeneEntities, expectedEntities);
when(updateEntityRepo.count()).thenReturn(4L);
when(updateEntityRepo.findAll(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(expectedEntities.stream());
Mockito.doAnswer(invocationOnMock -> {
@SuppressWarnings("unchecked") Consumer<List<Entity>> consumer = (Consumer<List<Entity>>) invocationOnMock.<Consumer>getArgument(0);
consumer.accept(sourceGeneEntities);
return null;
}).when(geneRepo).forEachBatched(ArgumentMatchers.any(Consumer.class), ArgumentMatchers.eq(MAPPING_BATCH_SIZE));
// make project and apply mappings once
MappingProject project = createMappingProjectWithMappings();
when(entityManager.create(targetMeta, EntityManager.CreationMode.POPULATE)).thenAnswer(invocation -> new DynamicEntity(targetMeta));
// apply mapping again
assertEquals(mappingService.applyMappings("TestRun", entityTypeId, false, "packageId", "label", progress), 4);
Mockito.verify(geneRepo).forEachBatched(ArgumentMatchers.any(Consumer.class), ArgumentMatchers.any(Integer.class));
Mockito.verify(updateEntityRepo).upsertBatch(batchCaptor.capture());
Assert.assertTrue(EntityUtils.equalsEntities(batchCaptor.getValue(), expectedEntities));
Mockito.verify(progress).status("Applying mappings to repository [HopEntity]");
Mockito.verify(progress).status("Mapping source [Genes]...");
Mockito.verify(progress).increment(1);
Mockito.verify(progress).status("Mapped 4 [Genes] entities.");
Mockito.verify(progress).status("Done applying mappings to repository [HopEntity]");
Mockito.verifyZeroInteractions(permissionSystemService);
}
use of org.molgenis.semanticmapper.mapping.model.MappingProject in project molgenis by molgenis.
the class MappingServiceImplTest method testCloneMappingProjectString.
@Test
public void testCloneMappingProjectString() {
MappingProject mappingProject = Mockito.mock(MappingProject.class);
when(mappingProjectRepo.getMappingProject("0")).thenReturn(mappingProject);
mappingService.cloneMappingProject("0");
Mockito.verify(mappingProject).removeIdentifiers();
Mockito.verify(mappingProjectRepo).add(mappingProject);
}
Aggregations