Search in sources :

Example 16 with MappingProject

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

the class MappingServiceImpl method cloneMappingProject.

@Override
@PreAuthorize("hasAnyRole('ROLE_SYSTEM, ROLE_SU, ROLE_PLUGIN_WRITE_menumanager')")
@Transactional
public MappingProject cloneMappingProject(String mappingProjectId) {
    MappingProject mappingProject = mappingProjectRepository.getMappingProject(mappingProjectId);
    if (mappingProject == null) {
        throw new UnknownEntityException("Mapping project [" + mappingProjectId + "] does not exist");
    }
    String mappingProjectName = mappingProject.getName();
    // determine cloned mapping project name (use Windows 7 naming strategy):
    String clonedMappingProjectName;
    for (int i = 1; ; ++i) {
        if (i == 1) {
            clonedMappingProjectName = mappingProjectName + " - Copy";
        } else {
            clonedMappingProjectName = mappingProjectName + " - Copy (" + i + ")";
        }
        if (mappingProjectRepository.getMappingProjects(new QueryImpl<>().eq(NAME, clonedMappingProjectName)).isEmpty()) {
            break;
        }
    }
    return cloneMappingProject(mappingProject, clonedMappingProjectName);
}
Also used : MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with MappingProject

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

the class MappingServiceImpl method applyMappings.

@Override
@Transactional
public long applyMappings(String mappingProjectId, String entityTypeId, Boolean addSourceAttribute, String packageId, String label, Progress progress) {
    MappingProject mappingProject = getMappingProject(mappingProjectId);
    MappingTarget mappingTarget = mappingProject.getMappingTargets().get(0);
    progress.setProgressMax(calculateMaxProgress(mappingTarget));
    progress.progress(0, format("Checking target repository [%s]...", entityTypeId));
    EntityType targetMetadata = createTargetMetadata(mappingTarget, entityTypeId, packageId, label, addSourceAttribute);
    Repository<Entity> targetRepo = getTargetRepository(entityTypeId, targetMetadata);
    return applyMappingsInternal(mappingTarget, targetRepo, progress);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with MappingProject

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

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

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

the class MappingServiceControllerTest method itShouldRemoveEmptyAttributeMappingsWhenSaving.

@Test
public void itShouldRemoveEmptyAttributeMappingsWhenSaving() 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", "").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);
    mappingTarget.addSource(lifeLines);
    Mockito.verify(mappingService).updateMappingProject(expected);
}
Also used : MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) Menu(org.molgenis.core.ui.menu.Menu) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

MappingProject (org.molgenis.semanticmapper.mapping.model.MappingProject)26 Test (org.testng.annotations.Test)18 MappingTarget (org.molgenis.semanticmapper.mapping.model.MappingTarget)14 DynamicEntity (org.molgenis.data.support.DynamicEntity)9 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)9 User (org.molgenis.data.security.auth.User)7 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)6 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)6 EntityType (org.molgenis.data.meta.model.EntityType)5 BeforeMethod (org.testng.annotations.BeforeMethod)4 Menu (org.molgenis.core.ui.menu.Menu)3 Attribute (org.molgenis.data.meta.model.Attribute)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Lists (com.google.common.collect.Lists)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2