Search in sources :

Example 1 with EntityMapping

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

the class MappingServiceControllerTest method itShouldUpdateExistingAttributeMappingWhenSaving.

@Test
public void itShouldUpdateExistingAttributeMappingWhenSaving() 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");
    mockMvc.perform(post(URI + "/saveattributemapping").param("mappingProjectId", "asdf").param("target", "HOP").param("source", "LifeLines").param("targetAttribute", "age").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("$('length').value()");
    ageMapping.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 2 with EntityMapping

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

the class MappingServiceControllerTest method getFirstAttributeMappingInfo_none.

@Test
public void getFirstAttributeMappingInfo_none() 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");
    mappingProject.getMappingTarget("HOP").getMappingForSource("LifeLines").getAttributeMapping("age").setAlgorithmState(AttributeMapping.AlgorithmState.DISCUSS);
    MappingTarget mappingTarget = mappingProject.getMappingTarget("HOP");
    EntityMapping entityMapping = mappingTarget.getMappingForSource("LifeLines");
    AttributeMapping attributeMapping = entityMapping.addAttributeMapping("dob");
    attributeMapping.setAlgorithm("$('dob').age()");
    attributeMapping.setAlgorithmState(AttributeMapping.AlgorithmState.DISCUSS);
    MvcResult result3 = mockMvc.perform(post(URI + "/firstattributemapping").param("mappingProjectId", "asdf").param("target", "HOP").param("source", "LifeLines").param("skipAlgorithmStates[]", "CURATED", "DISCUSS").accept(MediaType.APPLICATION_JSON)).andReturn();
    String actual3 = result3.getResponse().getContentAsString();
    assertEquals(actual3, "");
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) Menu(org.molgenis.core.ui.menu.Menu) MvcResult(org.springframework.test.web.servlet.MvcResult) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 3 with EntityMapping

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

the class AlgorithmServiceImplIT method testCreateAttributeMappingIfOnlyOneMatch.

@Test
public void testCreateAttributeMappingIfOnlyOneMatch() {
    EntityType targetEntityType = entityTypeFactory.create("target");
    Attribute targetAttribute = attrMetaFactory.create().setName("targetHeight");
    targetAttribute.setDescription("height");
    targetEntityType.addAttribute(targetAttribute);
    EntityType sourceEntityType = entityTypeFactory.create("source");
    Attribute sourceAttribute = attrMetaFactory.create().setName("sourceHeight");
    sourceAttribute.setDescription("height");
    sourceEntityType.addAttribute(sourceAttribute);
    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> matches = ImmutableMap.of(sourceAttribute, ExplainedAttribute.create(sourceAttribute, singletonList(ExplainedQueryString.create("height", "height", "height", 100)), true));
    LinkedHashMultimap<Relation, OntologyTerm> ontologyTermTags = LinkedHashMultimap.create();
    when(semanticSearchService.decisionTreeToFindRelevantAttributes(sourceEntityType, targetAttribute, ontologyTermTags.values(), null)).thenReturn(matches);
    when(ontologyTagService.getTagsForAttribute(targetEntityType, targetAttribute)).thenReturn(ontologyTermTags);
    algorithmService.autoGenerateAlgorithm(sourceEntityType, targetEntityType, mapping, targetAttribute);
    assertEquals(mapping.getAttributeMapping("targetHeight").getAlgorithm(), "$('sourceHeight').value();");
}
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 4 with EntityMapping

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

the class AlgorithmServiceImplIT method testWhenSourceDoesNotMatchThenNoMappingGetsCreated.

@Test
public void testWhenSourceDoesNotMatchThenNoMappingGetsCreated() {
    EntityType targetEntityType = entityTypeFactory.create("target");
    Attribute targetAttribute = attrMetaFactory.create().setName("targetHeight");
    targetAttribute.setDescription("height");
    targetEntityType.addAttribute(targetAttribute);
    EntityType sourceEntityType = entityTypeFactory.create("source");
    Attribute sourceAttribute = attrMetaFactory.create().setName("sourceHeight");
    sourceAttribute.setDescription("weight");
    sourceEntityType.addAttribute(sourceAttribute);
    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);
    when(semanticSearchService.findAttributes(sourceEntityType, Sets.newHashSet("targetHeight", "height"), Collections.emptyList())).thenReturn(emptyMap());
    when(ontologyTagService.getTagsForAttribute(targetEntityType, targetAttribute)).thenReturn(LinkedHashMultimap.create());
    algorithmService.autoGenerateAlgorithm(sourceEntityType, targetEntityType, mapping, targetAttribute);
    assertNull(mapping.getAttributeMapping("targetHeight"));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) User(org.molgenis.data.security.auth.User) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 5 with EntityMapping

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

the class EntityMappingRepositoryImplTest method testUpsert.

@Test
public void testUpsert() {
    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, CURATED.toString()));
    Collection<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, "");
    attributeMappingEntity.set(AttributeMappingMetaData.ALGORITHM, "algorithm");
    attributeMappingEntity.set(AttributeMappingMetaData.ALGORITHM_STATE, CURATED.toString());
    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.SOURCE_ENTITY_TYPE, "source");
    entityMappingEntity.set(EntityMappingMetaData.TARGET_ENTITY_TYPE, "target");
    entityMappingEntity.set(EntityMappingMetaData.ATTRIBUTE_MAPPINGS, attributeMappingEntities);
    entityMappingEntities.add(entityMappingEntity);
    Assert.assertTrue(EntityUtils.equals(entityMappingRepository.upsert(entityMappings).get(0), entityMappingEntities.get(0)));
}
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)

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