use of org.molgenis.semanticmapper.mapping.model.EntityMapping 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);
}
use of org.molgenis.semanticmapper.mapping.model.EntityMapping 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();
}
use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.
the class AlgorithmServiceImplIT method testWhenSourceHasMultipleMatchesThenFirstMappingGetsCreated.
@Test
public void testWhenSourceHasMultipleMatchesThenFirstMappingGetsCreated() {
EntityType targetEntityType = entityTypeFactory.create("target");
Attribute targetAttribute = attrMetaFactory.create().setName("targetHeight");
targetAttribute.setDescription("height");
targetEntityType.addAttribute(targetAttribute);
EntityType sourceEntityType = entityTypeFactory.create("source");
Attribute sourceAttribute1 = attrMetaFactory.create().setName("sourceHeight1");
sourceAttribute1.setDescription("height");
Attribute sourceAttribute2 = attrMetaFactory.create().setName("sourceHeight2");
sourceAttribute2.setDescription("height");
sourceEntityType.addAttributes(Arrays.asList(sourceAttribute1, sourceAttribute2));
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> mappings = ImmutableMap.of(sourceAttribute1, ExplainedAttribute.create(sourceAttribute1), sourceAttribute2, ExplainedAttribute.create(sourceAttribute2));
LinkedHashMultimap<Relation, OntologyTerm> ontologyTermTags = LinkedHashMultimap.create();
when(semanticSearchService.decisionTreeToFindRelevantAttributes(sourceEntityType, targetAttribute, ontologyTermTags.values(), null)).thenReturn(mappings);
when(ontologyTagService.getTagsForAttribute(targetEntityType, targetAttribute)).thenReturn(ontologyTermTags);
algorithmService.autoGenerateAlgorithm(sourceEntityType, targetEntityType, mapping, targetAttribute);
assertEquals(mapping.getAttributeMapping("targetHeight").getSourceAttributes().get(0), sourceAttribute1);
}
use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.
the class EntityMappingRepositoryImplTest method testToEntityMappings.
@Test
public void testToEntityMappings() {
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));
List<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, "sourceAttributes");
attributeMappingEntity.set(AttributeMappingMetaData.ALGORITHM, "algorithm");
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.TARGET_ENTITY_TYPE, "targetAttribute");
entityMappingEntity.set(EntityMappingMetaData.ATTRIBUTE_MAPPINGS, attributeMappingEntities);
entityMappingEntities.add(entityMappingEntity);
when(dataService.getEntityType(entityMappingEntity.getString(EntityMappingMetaData.TARGET_ENTITY_TYPE))).thenReturn(targetEntityType);
when(dataService.getEntityType(entityMappingEntity.getString(EntityMappingMetaData.SOURCE_ENTITY_TYPE))).thenReturn(sourceEntityType);
assertEquals(entityMappingRepository.toEntityMappings(entityMappingEntities), entityMappings);
}
use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.
the class MappingServiceImplTest method createMappingProjectWithMappings.
private MappingProject createMappingProjectWithMappings() {
MappingProject mappingProject = mappingService.addMappingProject("TestRun", user, hopMetaData.getId());
MappingTarget target = mappingProject.getMappingTarget(hopMetaData.getId());
when(mappingProjectRepo.getMappingProject("TestRun")).thenReturn(mappingProject);
EntityMapping mapping = target.addSource(geneMetaData);
AttributeMapping idMapping = mapping.addAttributeMapping("identifier");
idMapping.setAlgorithm("$('id').value()");
AttributeMapping attrMapping = mapping.addAttributeMapping("height");
attrMapping.setAlgorithm("$('length').value()");
return mappingProject;
}
Aggregations