Search in sources :

Example 16 with EntityMapping

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

the class MappingServiceControllerTest method itShouldCreateNewAttributeMappingWhenSavingIfNonePresent.

@Test
public void itShouldCreateNewAttributeMappingWhenSavingIfNonePresent() throws Exception {
    when(mappingService.getMappingProject("asdf")).thenReturn(mappingProject);
    Menu menu = mock(Menu.class);
    when(menuReaderService.getMenu()).thenReturn(menu);
    when(menu.findMenuItemPath(ID)).thenReturn("/menu/main/mappingservice");
    heightAttr = attrMetaFactory.create().setName("height").setDataType(INT);
    hop.addAttribute(heightAttr);
    mockMvc.perform(post(URI + "/saveattributemapping").param("mappingProjectId", "asdf").param("target", "HOP").param("source", "LifeLines").param("targetAttribute", "height").param("algorithm", "$('length').value()").param("algorithmState", "CURATED")).andExpect(redirectedUrl("/menu/main/mappingservice/mappingproject/asdf"));
    MappingProject expected = new MappingProject("hop hop hop", me);
    expected.setIdentifier("asdf");
    MappingTarget mappingTarget = expected.addTarget(hop);
    EntityMapping entityMapping = mappingTarget.addSource(lifeLines);
    AttributeMapping ageMapping = entityMapping.addAttributeMapping("age");
    ageMapping.setAlgorithm("$('dob').age()");
    AttributeMapping heightMapping = entityMapping.addAttributeMapping("height");
    heightMapping.setAlgorithm("$('length').value()");
    heightMapping.setAlgorithmState(AttributeMapping.AlgorithmState.CURATED);
    Mockito.verify(mappingService).updateMappingProject(expected);
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) Menu(org.molgenis.core.ui.menu.Menu) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 17 with EntityMapping

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

the class MappingServiceControllerTest method beforeTest.

@BeforeMethod
public void beforeTest() {
    me = mock(User.class);
    when(me.getUsername()).thenReturn("fdlk");
    TestingAuthenticationToken authentication = new TestingAuthenticationToken("fdlk", null);
    authentication.setAuthenticated(true);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    hop = entityTypeFactory.create("HOP");
    ageAttr = attrMetaFactory.create().setName("age").setDataType(INT);
    hop.addAttribute(ageAttr);
    dobAttr = attrMetaFactory.create().setName("dob").setDataType(DATE);
    hop.addAttribute(dobAttr);
    hop.setAbstract(true);
    lifeLines = entityTypeFactory.create("LifeLines");
    mappingProject = new MappingProject("hop hop hop", me);
    mappingProject.setIdentifier("asdf");
    MappingTarget mappingTarget = mappingProject.addTarget(hop);
    EntityMapping entityMapping = mappingTarget.addSource(lifeLines);
    AttributeMapping attributeMapping = entityMapping.addAttributeMapping("age");
    attributeMapping.setAlgorithm("$('dob').age()");
    when(dataService.getMeta()).thenReturn(metaDataService);
    mockMvc = MockMvcBuilders.standaloneSetup(controller).setMessageConverters(gsonHttpMessageConverter, new StringHttpMessageConverter()).build();
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) User(org.molgenis.data.security.auth.User) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 18 with EntityMapping

use of org.molgenis.semanticmapper.mapping.model.EntityMapping 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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) Relation(org.molgenis.data.semantic.Relation) User(org.molgenis.data.security.auth.User) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 19 with EntityMapping

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

the class EntityMappingRepositoryImplTest method testToEntityMappings.

@Test
public void testToEntityMappings() {
    Attribute targetAttribute = attrMetaFactory.create().setName("targetAttribute");
    List<Attribute> sourceAttributes = Lists.newArrayList();
    EntityType sourceEntityType = entityTypeFactory.create("source");
    EntityType targetEntityType = entityTypeFactory.create("target");
    targetEntityType.addAttribute(targetAttribute);
    List<AttributeMapping> attributeMappings = Lists.newArrayList();
    attributeMappings.add(new AttributeMapping("1", "targetAttribute", targetAttribute, "algorithm", sourceAttributes));
    List<EntityMapping> entityMappings = singletonList(new EntityMapping(AUTO_ID, sourceEntityType, targetEntityType, attributeMappings));
    Entity attributeMappingEntity = new DynamicEntity(attrMappingMeta);
    attributeMappingEntity.set(EntityMappingMetaData.IDENTIFIER, AUTO_ID);
    attributeMappingEntity.set(AttributeMappingMetaData.TARGET_ATTRIBUTE, "targetAttribute");
    attributeMappingEntity.set(AttributeMappingMetaData.SOURCE_ATTRIBUTES, "sourceAttributes");
    attributeMappingEntity.set(AttributeMappingMetaData.ALGORITHM, "algorithm");
    List<Entity> attributeMappingEntities = Lists.newArrayList();
    attributeMappingEntities.add(attributeMappingEntity);
    List<Entity> entityMappingEntities = Lists.newArrayList();
    Entity entityMappingEntity = new DynamicEntity(entityMappingMeta);
    entityMappingEntity.set(EntityMappingMetaData.IDENTIFIER, AUTO_ID);
    entityMappingEntity.set(EntityMappingMetaData.TARGET_ENTITY_TYPE, "targetAttribute");
    entityMappingEntity.set(EntityMappingMetaData.ATTRIBUTE_MAPPINGS, attributeMappingEntities);
    entityMappingEntities.add(entityMappingEntity);
    when(dataService.getEntityType(entityMappingEntity.getString(EntityMappingMetaData.TARGET_ENTITY_TYPE))).thenReturn(targetEntityType);
    when(dataService.getEntityType(entityMappingEntity.getString(EntityMappingMetaData.SOURCE_ENTITY_TYPE))).thenReturn(sourceEntityType);
    assertEquals(entityMappingRepository.toEntityMappings(entityMappingEntities), entityMappings);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) DynamicEntity(org.molgenis.data.support.DynamicEntity) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 20 with EntityMapping

use of org.molgenis.semanticmapper.mapping.model.EntityMapping 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;
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget)

Aggregations

EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)22 Test (org.testng.annotations.Test)16 MappingTarget (org.molgenis.semanticmapper.mapping.model.MappingTarget)12 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)8 EntityType (org.molgenis.data.meta.model.EntityType)8 DynamicEntity (org.molgenis.data.support.DynamicEntity)8 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)8 MappingProject (org.molgenis.semanticmapper.mapping.model.MappingProject)7 Attribute (org.molgenis.data.meta.model.Attribute)6 Entity (org.molgenis.data.Entity)5 User (org.molgenis.data.security.auth.User)4 Menu (org.molgenis.core.ui.menu.Menu)3 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 Relation (org.molgenis.data.semantic.Relation)2 OntologyTerm (org.molgenis.ontology.core.model.OntologyTerm)2