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);
}
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, "");
}
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();");
}
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"));
}
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)));
}
Aggregations