Search in sources :

Example 1 with AttributeMapping

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

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

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

the class AlgorithmServiceImplIT method testGetXrefScript.

@Test
public void testGetXrefScript() throws ParseException {
    // xref entities
    EntityType entityTypeXref = entityTypeFactory.create("xrefEntity1");
    entityTypeXref.addAttribute(attrMetaFactory.create().setName("id").setDataType(INT), ROLE_ID);
    entityTypeXref.addAttribute(attrMetaFactory.create().setName("field1"));
    Entity xref1a = new DynamicEntity(entityTypeXref);
    xref1a.set("id", 1);
    xref1a.set("field1", "Test");
    EntityType entityTypeXref2 = entityTypeFactory.create("xrefEntity2");
    entityTypeXref2.addAttribute(attrMetaFactory.create().setName("id").setDataType(INT), ROLE_ID);
    entityTypeXref2.addAttribute(attrMetaFactory.create().setName("field2"));
    Entity xref2a = new DynamicEntity(entityTypeXref2);
    xref2a.set("id", 2);
    xref2a.set("field2", "Test");
    // source Entity
    EntityType entityTypeSource = entityTypeFactory.create("Source");
    entityTypeSource.addAttribute(attrMetaFactory.create().setName("id").setDataType(INT), ROLE_ID);
    entityTypeSource.addAttribute(attrMetaFactory.create().setName("xref").setDataType(XREF));
    Entity source = new DynamicEntity(entityTypeSource);
    source.set("id", 1);
    source.set("xref", xref2a);
    Attribute targetAttribute = attrMetaFactory.create().setName("field1");
    targetAttribute.setDataType(XREF);
    targetAttribute.setRefEntity(entityTypeXref);
    AttributeMapping attributeMapping = new AttributeMapping(targetAttribute);
    attributeMapping.setAlgorithm("$('xref').map({'1':'2', '2':'1'}).value();");
    when(entityManager.getReference(entityTypeXref, 1)).thenReturn(xref1a);
    Entity result = (Entity) algorithmService.apply(attributeMapping, source, entityTypeSource);
    assertEquals(result.get("field1"), xref2a.get("field2"));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 4 with AttributeMapping

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

the class AlgorithmServiceImplIT method testApply.

@Test(dataProvider = "testApplyProvider")
public void testApply(AttributeType sourceAttributeType, Object sourceAttributeValue, String algorithm, AttributeType targetAttributeType, Object expected, String message) {
    String idAttrName = "id";
    EntityType entityType = entityTypeFactory.create("LL");
    entityType.addAttribute(attrMetaFactory.create().setName(idAttrName).setDataType(INT), ROLE_ID);
    entityType.addAttribute(attrMetaFactory.create().setName("source").setDataType(sourceAttributeType));
    Entity source = new DynamicEntity(entityType);
    source.set(idAttrName, 1);
    source.set("source", sourceAttributeValue);
    Attribute targetAttribute = attrMetaFactory.create().setName("target");
    targetAttribute.setDataType(targetAttributeType);
    AttributeMapping attributeMapping = new AttributeMapping(targetAttribute);
    attributeMapping.setAlgorithm(algorithm);
    Object result = algorithmService.apply(attributeMapping, source, entityType);
    assertEquals(result, expected, message);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) ExplainedQueryString(org.molgenis.semanticsearch.explain.bean.ExplainedQueryString) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 5 with AttributeMapping

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

the class AlgorithmServiceImplIT method testDotAnnotationWithXref.

@Test
public void testDotAnnotationWithXref() throws ParseException {
    EntityType referenceEntityType = entityTypeFactory.create("reference");
    referenceEntityType.addAttribute(attrMetaFactory.create().setName("id"), ROLE_ID);
    referenceEntityType.addAttribute(attrMetaFactory.create().setName("label"));
    Entity referenceEntity = new DynamicEntity(referenceEntityType);
    referenceEntity.set("id", "1");
    referenceEntity.set("label", "label 1");
    EntityType sourceEntityType = entityTypeFactory.create("source");
    sourceEntityType.addAttribute(attrMetaFactory.create().setName("id"), ROLE_ID);
    sourceEntityType.addAttribute(attrMetaFactory.create().setName("source_xref").setDataType(XREF));
    Entity sourceEntity = new DynamicEntity(sourceEntityType);
    sourceEntity.set("id", "1");
    sourceEntity.set("source_xref", referenceEntity);
    Attribute targetAttribute = attrMetaFactory.create().setName("target_label");
    AttributeMapping attributeMapping = new AttributeMapping(targetAttribute);
    attributeMapping.setAlgorithm("$('source_xref.label').value()");
    Object result = algorithmService.apply(attributeMapping, sourceEntity, sourceEntityType);
    assertEquals(result, "label 1");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) 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