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