Search in sources :

Example 16 with AttributeMapping

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

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

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

the class AttributeMappingRepositoryImplTest method testUpdate.

@Test
public void testUpdate() {
    Attribute targetAttribute = attrMetaFactory.create().setName("targetAttribute");
    List<Attribute> sourceAttributes = newArrayList();
    targetAttribute.setDataType(STRING);
    Collection<AttributeMapping> attributeMappings = singletonList(new AttributeMapping("attributeMappingID", "targetAttribute", targetAttribute, "algorithm", sourceAttributes, CURATED.toString()));
    List<Entity> result = newArrayList();
    Entity attributeMappingEntity = new DynamicEntity(attrMappingMeta);
    attributeMappingEntity.set(IDENTIFIER, "attributeMappingID");
    attributeMappingEntity.set(TARGET_ATTRIBUTE, targetAttribute.getName());
    attributeMappingEntity.set(SOURCE_ATTRIBUTES, "");
    attributeMappingEntity.set(ALGORITHM, "algorithm");
    attributeMappingEntity.set(ALGORITHM_STATE, CURATED.toString());
    result.add(attributeMappingEntity);
    List<Entity> expectedAttrMappings = attributeMappingRepository.upsert(attributeMappings);
    assertEquals(expectedAttrMappings.size(), result.size());
    for (int i = 0; i < expectedAttrMappings.size(); ++i) {
        Assert.assertTrue(EntityUtils.equals(expectedAttrMappings.get(i), result.get(i)));
    }
}
Also used : 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 19 with AttributeMapping

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

the class AttributeMappingRepositoryImplTest method testInsert.

@Test
public void testInsert() {
    Attribute targetAttribute = attrMetaFactory.create().setName("targetAttribute");
    List<Attribute> sourceAttributes = newArrayList();
    targetAttribute.setDataType(STRING);
    Collection<AttributeMapping> attributeMappings = singletonList(new AttributeMapping(null, "targetAttribute", targetAttribute, "algorithm", sourceAttributes, CURATED.toString()));
    Mockito.when(idGenerator.generateId()).thenReturn("attributeMappingID");
    List<Entity> result = newArrayList();
    Entity attributeMappingEntity = new DynamicEntity(attrMappingMeta);
    attributeMappingEntity.set(IDENTIFIER, "attributeMappingID");
    attributeMappingEntity.set(TARGET_ATTRIBUTE, targetAttribute.getName());
    attributeMappingEntity.set(SOURCE_ATTRIBUTES, "");
    attributeMappingEntity.set(ALGORITHM, "algorithm");
    attributeMappingEntity.set(ALGORITHM_STATE, CURATED.toString());
    result.add(attributeMappingEntity);
    List<Entity> expectedAttrMappings = attributeMappingRepository.upsert(attributeMappings);
    assertEquals(expectedAttrMappings.size(), result.size());
    for (int i = 0; i < expectedAttrMappings.size(); ++i) {
        Assert.assertTrue(EntityUtils.equals(expectedAttrMappings.get(i), result.get(i)));
    }
}
Also used : 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 AttributeMapping

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

the class AttributeMappingRepositoryImplTest method testGetAttributeMappings.

@Test
public void testGetAttributeMappings() {
    Attribute targetAttribute = attrMetaFactory.create().setName("targetAttribute");
    List<Attribute> sourceAttributes = newArrayList();
    List<AttributeMapping> attributeMappings = newArrayList();
    attributeMappings.add(new AttributeMapping("attributeMappingID", "targetAttribute", targetAttribute, "algorithm", sourceAttributes));
    Entity attributeMappingEntity = new DynamicEntity(attrMappingMeta);
    attributeMappingEntity.set(IDENTIFIER, "attributeMappingID");
    attributeMappingEntity.set(TARGET_ATTRIBUTE, "targetAttribute");
    attributeMappingEntity.set(SOURCE_ATTRIBUTES, "sourceAttributes");
    attributeMappingEntity.set(ALGORITHM, "algorithm");
    List<Entity> attributeMappingEntities = newArrayList();
    attributeMappingEntities.add(attributeMappingEntity);
    EntityType sourceEntityType = entityTypeFactory.create("source");
    EntityType targetEntityType = entityTypeFactory.create("target");
    targetEntityType.addAttribute(targetAttribute);
    assertEquals(attributeMappingRepository.getAttributeMappings(attributeMappingEntities, sourceEntityType, targetEntityType), attributeMappings);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) 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

AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)22 Test (org.testng.annotations.Test)16 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)15 Entity (org.molgenis.data.Entity)15 Attribute (org.molgenis.data.meta.model.Attribute)15 DynamicEntity (org.molgenis.data.support.DynamicEntity)13 EntityType (org.molgenis.data.meta.model.EntityType)11 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)8 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)8 MappingTarget (org.molgenis.semanticmapper.mapping.model.MappingTarget)5 MappingProject (org.molgenis.semanticmapper.mapping.model.MappingProject)4 ExplainedQueryString (org.molgenis.semanticsearch.explain.bean.ExplainedQueryString)4 Menu (org.molgenis.core.ui.menu.Menu)3 UnknownEntityException (org.molgenis.data.UnknownEntityException)1 User (org.molgenis.data.security.auth.User)1 Relation (org.molgenis.data.semantic.Relation)1 OntologyTerm (org.molgenis.ontology.core.model.OntologyTerm)1 ScriptException (org.molgenis.script.core.ScriptException)1 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)1 GeneratedAlgorithm (org.molgenis.semanticmapper.algorithmgenerator.bean.GeneratedAlgorithm)1