Search in sources :

Example 1 with MappingProject

use of org.molgenis.semanticmapper.mapping.model.MappingProject 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 MappingProject

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

the class MappingProjectRepositoryImplTest method testAddWithIdentifier.

@Test
public void testAddWithIdentifier() {
    MappingProject mappingProject = new MappingProject("My first mapping project", owner);
    mappingProject.setIdentifier("mappingProjectID");
    try {
        mappingProjectRepositoryImpl.add(mappingProject);
    } catch (MolgenisDataException mde) {
        assertEquals(mde.getMessage(), "MappingProject already exists");
    }
}
Also used : MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) Test(org.testng.annotations.Test)

Example 3 with MappingProject

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

the class MappingProjectRepositoryImplTest method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    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");
    EntityType target1 = entityTypeFactory.create("target1");
    target1.addAttribute(attrMetaFactory.create().setName("id"), ROLE_ID);
    EntityType target2 = entityTypeFactory.create("target2");
    target2.addAttribute(attrMetaFactory.create().setName("id"), ROLE_ID);
    mappingProject = new MappingProject("My first mapping project", owner);
    mappingTarget1 = mappingProject.addTarget(target1);
    mappingTarget2 = mappingProject.addTarget(target2);
    Entity mappingTargetEntity = new DynamicEntity(mappingTargetMeta);
    mappingTargetEntity.set(MappingTargetMetaData.TARGET, "target1");
    mappingTargetEntity.set(MappingTargetMetaData.IDENTIFIER, "mappingTargetID1");
    Entity mappingTargetEntity2 = new DynamicEntity(mappingTargetMeta);
    mappingTargetEntity2.set(MappingTargetMetaData.TARGET, "target2");
    mappingTargetEntity2.set(MappingTargetMetaData.IDENTIFIER, "mappingTargetID2");
    mappingTargetEntities = asList(mappingTargetEntity, mappingTargetEntity2);
    mappingProjectEntity = new DynamicEntity(mappingProjectMeta);
    mappingProjectEntity.set(IDENTIFIER, "mappingProjectID");
    mappingProjectEntity.set(MAPPING_TARGETS, mappingTargetEntities);
    mappingProjectEntity.set(OWNER, owner);
    mappingProjectEntity.set(NAME, "My first mapping project");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) DynamicEntity(org.molgenis.data.support.DynamicEntity) DynamicEntity(org.molgenis.data.support.DynamicEntity) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with MappingProject

use of org.molgenis.semanticmapper.mapping.model.MappingProject 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 5 with MappingProject

use of org.molgenis.semanticmapper.mapping.model.MappingProject 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)

Aggregations

MappingProject (org.molgenis.semanticmapper.mapping.model.MappingProject)26 Test (org.testng.annotations.Test)18 MappingTarget (org.molgenis.semanticmapper.mapping.model.MappingTarget)14 DynamicEntity (org.molgenis.data.support.DynamicEntity)9 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)9 User (org.molgenis.data.security.auth.User)7 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)6 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)6 EntityType (org.molgenis.data.meta.model.EntityType)5 BeforeMethod (org.testng.annotations.BeforeMethod)4 Menu (org.molgenis.core.ui.menu.Menu)3 Attribute (org.molgenis.data.meta.model.Attribute)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Lists (com.google.common.collect.Lists)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2