Search in sources :

Example 91 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class MappingTargetRepositoryImplTest method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    // POJOs
    EntityType sourceEntityType = entityTypeFactory.create("source");
    targetEntityType = entityTypeFactory.create("target");
    Attribute targetAttribute = attrMetaFactory.create().setName("targetAttribute");
    targetEntityType.addAttribute(targetAttribute);
    entityMappings = singletonList(new EntityMapping("entityMappingID", sourceEntityType, targetEntityType, emptyList()));
    mappingTargets = singletonList(new MappingTarget("mappingTargetID", targetEntityType, entityMappings));
    // Entities
    Entity entityMappingEntity = new DynamicEntity(entityMappingMeta);
    entityMappingEntity.set(EntityMappingMetaData.IDENTIFIER, "entityMappingID");
    entityMappingEntity.set(EntityMappingMetaData.SOURCE_ENTITY_TYPE, "source");
    entityMappingEntity.set(EntityMappingMetaData.TARGET_ENTITY_TYPE, "target");
    entityMappingEntity.set(EntityMappingMetaData.ATTRIBUTE_MAPPINGS, emptyList());
    Entity mappingTargetEntity = new DynamicEntity(mappingTargetMeta);
    mappingTargetEntity.set(IDENTIFIER, "mappingTargetID");
    mappingTargetEntity.set(TARGET, "target");
    entityMappingEntities = singletonList(entityMappingEntity);
    mappingTargetEntity.set(ENTITY_MAPPINGS, entityMappingEntities);
    mappingTargetEntities = singletonList(mappingTargetEntity);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) DynamicEntity(org.molgenis.data.support.DynamicEntity) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 92 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AlgorithmServiceImplTest method testApplyConvertException.

private void testApplyConvertException(String algorithmResult, AttributeType attributeType) {
    AttributeMapping attributeMapping = mock(AttributeMapping.class);
    String algorithm = "algorithm";
    when(attributeMapping.getAlgorithm()).thenReturn(algorithm);
    Attribute targetAttribute = when(mock(Attribute.class).getDataType()).thenReturn(attributeType).getMock();
    when(attributeMapping.getTargetAttribute()).thenReturn(targetAttribute);
    Entity sourceEntity = mock(Entity.class);
    when(jsMagmaScriptEvaluator.eval(algorithm, sourceEntity, 3)).thenReturn(algorithmResult);
    algorithmServiceImpl.apply(attributeMapping, sourceEntity, null);
}
Also used : Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping)

Example 93 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class MappingServiceController method getTagsForAttribute.

private Map<String, List<OntologyTerm>> getTagsForAttribute(String target, MappingProject project) {
    Map<String, List<OntologyTerm>> attributeTagMap = new HashMap<>();
    for (Attribute amd : project.getMappingTarget(target).getTarget().getAtomicAttributes()) {
        EntityType targetMetaData = RunAsSystemAspect.runAsSystem(() -> dataService.getEntityType(target));
        attributeTagMap.put(amd.getName(), newArrayList(ontologyTagService.getTagsForAttribute(targetMetaData, amd).values()));
    }
    return attributeTagMap;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Collectors.toList(java.util.stream.Collectors.toList)

Example 94 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class MappingServiceController method addEntityMapping.

/**
 * Adds a new {@link EntityMapping} to an existing {@link MappingTarget}
 *
 * @param target           the name of the {@link MappingTarget}'s entity to add a source entity to
 * @param source           the name of the source entity of the newly added {@link EntityMapping}
 * @param mappingProjectId the ID of the {@link MappingTarget}'s {@link MappingProject}
 * @return redirect URL for the mapping project
 */
@PostMapping("/addEntityMapping")
public String addEntityMapping(@RequestParam String mappingProjectId, String target, String source) {
    EntityType sourceEntityType = dataService.getEntityType(source);
    EntityType targetEntityType = dataService.getEntityType(target);
    Iterable<Attribute> attributes = targetEntityType.getAtomicAttributes();
    MappingProject project = mappingService.getMappingProject(mappingProjectId);
    if (hasWritePermission(project)) {
        EntityMapping mapping = project.getMappingTarget(target).addSource(sourceEntityType);
        mappingService.updateMappingProject(project);
        autoGenerateAlgorithms(mapping, sourceEntityType, targetEntityType, attributes, project);
    }
    return "redirect:" + getMappingServiceMenuUrl() + "/mappingproject/" + mappingProjectId;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)

Example 95 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class MappingServiceController method attributeMappingFeedback.

@PostMapping("/attributemappingfeedback")
public String attributeMappingFeedback(@RequestParam() String mappingProjectId, @RequestParam() String target, @RequestParam() String source, @RequestParam() String targetAttribute, @RequestParam() String algorithm, Model model) {
    MappingProject project = mappingService.getMappingProject(mappingProjectId);
    MappingTarget mappingTarget = project.getMappingTarget(target);
    EntityMapping entityMapping = mappingTarget.getMappingForSource(source);
    AttributeMapping algorithmTest;
    if (entityMapping.getAttributeMapping(targetAttribute) == null) {
        algorithmTest = entityMapping.addAttributeMapping(targetAttribute);
        algorithmTest.setAlgorithm(algorithm);
    } else {
        algorithmTest = entityMapping.getAttributeMapping(targetAttribute);
        algorithmTest.setAlgorithm(algorithm);
    }
    try {
        Collection<String> sourceAttributeNames = algorithmService.getSourceAttributeNames(algorithm);
        if (!sourceAttributeNames.isEmpty()) {
            List<Attribute> sourceAttributes = sourceAttributeNames.stream().map(attributeName -> {
                EntityType sourceEntityType = entityMapping.getSourceEntityType();
                return sourceEntityType.getAttribute(attributeName);
            }).filter(Objects::nonNull).collect(Collectors.toList());
            model.addAttribute("sourceAttributes", sourceAttributes);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    model.addAttribute("mappingProjectId", mappingProjectId);
    model.addAttribute("target", target);
    model.addAttribute("source", source);
    model.addAttribute("targetAttribute", dataService.getEntityType(target).getAttribute(targetAttribute));
    FluentIterable<Entity> sourceEntities = FluentIterable.from(() -> dataService.findAll(source).iterator()).limit(10);
    ImmutableList<AlgorithmResult> algorithmResults = sourceEntities.transform(sourceEntity -> {
        try {
            return AlgorithmResult.createSuccess(algorithmService.apply(algorithmTest, sourceEntity, sourceEntity.getEntityType()), sourceEntity);
        } catch (Exception e) {
            return AlgorithmResult.createFailure(e, sourceEntity);
        }
    }).toList();
    model.addAttribute("feedbackRows", algorithmResults);
    long missing = algorithmResults.stream().filter(r -> r.isSuccess() && r.getValue() == null).count();
    long success = algorithmResults.stream().filter(AlgorithmResult::isSuccess).count() - missing;
    long error = algorithmResults.size() - success - missing;
    model.addAttribute("success", success);
    model.addAttribute("missing", missing);
    model.addAttribute("error", error);
    model.addAttribute("dataexplorerUri", menuReaderService.getMenu().findMenuItemPath(DataExplorerController.ID));
    return VIEW_ATTRIBUTE_MAPPING_FEEDBACK;
}
Also used : AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) PluginController(org.molgenis.web.PluginController) MenuReaderService(org.molgenis.core.ui.menu.MenuReaderService) URISyntaxException(java.net.URISyntaxException) org.molgenis.semanticmapper.mapping.model(org.molgenis.semanticmapper.mapping.model) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AlgorithmService(org.molgenis.semanticmapper.service.AlgorithmService) CategoryMapping.createEmpty(org.molgenis.semanticmapper.mapping.model.CategoryMapping.createEmpty) StringUtils(org.apache.commons.lang3.StringUtils) Attribute(org.molgenis.data.meta.model.Attribute) AlgorithmState(org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState) Relation(org.molgenis.data.semantic.Relation) Valid(javax.validation.Valid) Href.concatEntityHref(org.molgenis.core.ui.data.support.Href.concatEntityHref) User(org.molgenis.data.security.auth.User) Model(org.springframework.ui.Model) RunAsSystemAspect(org.molgenis.security.core.runas.RunAsSystemAspect) MetaUtils.isSystemPackage(org.molgenis.data.meta.MetaUtils.isSystemPackage) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) URI(java.net.URI) com.google.common.collect(com.google.common.collect) org.molgenis.data(org.molgenis.data) DataExplorerController(org.molgenis.dataexplorer.controller.DataExplorerController) NameValidator.validateEntityName(org.molgenis.data.validation.meta.NameValidator.validateEntityName) SecurityUtils.getCurrentUsername(org.molgenis.security.core.utils.SecurityUtils.getCurrentUsername) MappingService(org.molgenis.semanticmapper.service.MappingService) JobsController(org.molgenis.core.ui.jobs.JobsController) MediaType(org.springframework.http.MediaType) UserAccountService(org.molgenis.security.user.UserAccountService) EntityTypeUtils(org.molgenis.data.support.EntityTypeUtils) EntityType(org.molgenis.data.meta.model.EntityType) Collectors(java.util.stream.Collectors) OntologyTagService(org.molgenis.semanticsearch.service.OntologyTagService) Stream(java.util.stream.Stream) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SecurityUtils.currentUserIsSu(org.molgenis.security.core.utils.SecurityUtils.currentUserIsSu) MappingJobExecution(org.molgenis.semanticmapper.job.MappingJobExecution) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) JobExecutor(org.molgenis.jobs.JobExecutor) java.util(java.util) CategoryMapping.create(org.molgenis.semanticmapper.mapping.model.CategoryMapping.create) StringUtils.trim(org.apache.commons.lang3.StringUtils.trim) SemanticSearchService(org.molgenis.semanticsearch.service.SemanticSearchService) UserService(org.molgenis.data.security.user.UserService) QueryImpl(org.molgenis.data.support.QueryImpl) Controller(org.springframework.stereotype.Controller) MessageFormat.format(java.text.MessageFormat.format) AggregateResult(org.molgenis.data.aggregation.AggregateResult) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) StreamSupport(java.util.stream.StreamSupport) MappingJobExecutionFactory(org.molgenis.semanticmapper.job.MappingJobExecutionFactory) ImportWizardController(org.molgenis.core.ui.data.importer.wizard.ImportWizardController) GenerateAlgorithmRequest(org.molgenis.semanticmapper.data.request.GenerateAlgorithmRequest) AlgorithmEvaluation(org.molgenis.semanticmapper.service.impl.AlgorithmEvaluation) Logger(org.slf4j.Logger) MappingServiceRequest(org.molgenis.semanticmapper.data.request.MappingServiceRequest) URI(org.molgenis.semanticmapper.controller.MappingServiceController.URI) ResponseEntity.created(org.springframework.http.ResponseEntity.created) Streams.stream(com.google.common.collect.Streams.stream) Collectors.toList(java.util.stream.Collectors.toList) Package(org.molgenis.data.meta.model.Package) ResponseEntity(org.springframework.http.ResponseEntity) ResponseEntity(org.springframework.http.ResponseEntity) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) URISyntaxException(java.net.URISyntaxException) EntityType(org.molgenis.data.meta.model.EntityType)

Aggregations

Attribute (org.molgenis.data.meta.model.Attribute)600 Test (org.testng.annotations.Test)351 EntityType (org.molgenis.data.meta.model.EntityType)321 Entity (org.molgenis.data.Entity)109 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)54 DynamicEntity (org.molgenis.data.support.DynamicEntity)53 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)47 Stream (java.util.stream.Stream)39 AttributeType (org.molgenis.data.meta.AttributeType)34 QueryImpl (org.molgenis.data.support.QueryImpl)29 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)29 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)28 BeforeMethod (org.testng.annotations.BeforeMethod)20 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)18 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 Collectors.toList (java.util.stream.Collectors.toList)17 Relation (org.molgenis.data.semantic.Relation)17 Objects.requireNonNull (java.util.Objects.requireNonNull)16 MolgenisDataException (org.molgenis.data.MolgenisDataException)16 Package (org.molgenis.data.meta.model.Package)16