Search in sources :

Example 96 with Attribute

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

the class MappingServiceController method getFirstAttributeMappingInfo.

/**
 * Find the firstattributeMapping skip the the algorithmStates that are given in the {@link AttributeMapping} to an
 * {@link EntityMapping}.
 *
 * @param mappingProjectId    ID of the mapping project
 * @param target              name of the target entity
 * @param skipAlgorithmStates the mapping algorithm states that should skip
 */
@PostMapping("/firstattributemapping")
@ResponseBody
public FirstAttributeMappingInfo getFirstAttributeMappingInfo(@RequestParam() String mappingProjectId, @RequestParam() String target, @RequestParam(value = "skipAlgorithmStates[]") List<AlgorithmState> skipAlgorithmStates, Model model) {
    MappingProject mappingProject = mappingService.getMappingProject(mappingProjectId);
    if (hasWritePermission(mappingProject)) {
        MappingTarget mappingTarget = mappingProject.getMappingTarget(target);
        List<String> sourceNames = mappingTarget.getEntityMappings().stream().map(i -> i.getSourceEntityType().getId()).collect(Collectors.toList());
        EntityType targetEntityMeta = mappingTarget.getTarget();
        for (Attribute attribute : targetEntityMeta.getAtomicAttributes()) {
            if (attribute.equals(targetEntityMeta.getIdAttribute())) {
                continue;
            }
            for (String source : sourceNames) {
                EntityMapping entityMapping = mappingTarget.getMappingForSource(source);
                AttributeMapping attributeMapping = entityMapping.getAttributeMapping(attribute.getName());
                if (null != attributeMapping) {
                    AlgorithmState algorithmState = attributeMapping.getAlgorithmState();
                    if (null != skipAlgorithmStates) {
                        if (skipAlgorithmStates.contains(algorithmState)) {
                            continue;
                        }
                    }
                }
                return FirstAttributeMappingInfo.create(mappingProjectId, target, source, attribute.getName());
            }
        }
    }
    return null;
}
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) EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) AlgorithmState(org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState)

Example 97 with Attribute

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

the class AttributeMappingRepositoryImpl method toAttributeMappingEntity.

private Entity toAttributeMappingEntity(AttributeMapping attributeMapping) {
    Entity attributeMappingEntity = new DynamicEntity(attributeMappingMetaData);
    attributeMappingEntity.set(IDENTIFIER, attributeMapping.getIdentifier());
    attributeMappingEntity.set(TARGET_ATTRIBUTE, attributeMapping.getTargetAttributeName());
    attributeMappingEntity.set(ALGORITHM, attributeMapping.getAlgorithm());
    attributeMappingEntity.set(SOURCE_ATTRIBUTES, attributeMapping.getSourceAttributes().stream().map(Attribute::getName).collect(Collectors.joining(",")));
    attributeMappingEntity.set(ALGORITHM_STATE, attributeMapping.getAlgorithmState().toString());
    return attributeMappingEntity;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Attribute(org.molgenis.data.meta.model.Attribute)

Example 98 with Attribute

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

the class AttributeMappingRepositoryImpl method toAttributeMapping.

private AttributeMapping toAttributeMapping(Entity attributeMappingEntity, EntityType sourceEntityType, EntityType targetEntityType) {
    String identifier = attributeMappingEntity.getString(IDENTIFIER);
    String targetAttributeName = attributeMappingEntity.getString(TARGET_ATTRIBUTE);
    Attribute targetAttribute = targetEntityType.getAttribute(targetAttributeName);
    String algorithm = attributeMappingEntity.getString(ALGORITHM);
    String algorithmState = attributeMappingEntity.getString(ALGORITHM_STATE);
    List<Attribute> sourceAttributes = retrieveAttributesFromAlgorithm(algorithm, sourceEntityType);
    return new AttributeMapping(identifier, targetAttributeName, targetAttribute, algorithm, sourceAttributes, algorithmState);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping)

Example 99 with Attribute

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

the class AttributeMappingRepositoryImpl method retrieveAttributesFromAlgorithm.

@Override
public List<Attribute> retrieveAttributesFromAlgorithm(String algorithm, EntityType sourceEntityType) {
    List<Attribute> sourceAttributes = Lists.newArrayList();
    Pattern pattern = Pattern.compile("\\$\\('([^']+)'\\)");
    Matcher matcher = pattern.matcher(algorithm);
    while (matcher.find()) {
        String sourceAttribute = matcher.group(1).split("\\.")[0];
        Attribute attribute = sourceEntityType.getAttribute(sourceAttribute);
        if (!sourceAttributes.contains(attribute)) {
            sourceAttributes.add(attribute);
        }
    }
    return sourceAttributes;
}
Also used : Pattern(java.util.regex.Pattern) Attribute(org.molgenis.data.meta.model.Attribute) Matcher(java.util.regex.Matcher)

Example 100 with Attribute

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

the class OneToManyCategoryAlgorithmGeneratorTest method createEntityType.

private EntityType createEntityType(String entityTypeId) {
    EntityType sourceRefEntityType = entityTypeFactory.create(entityTypeId);
    Attribute sourceCodeAttribute = attrMetaFactory.create().setName("code").setDataType(INT);
    Attribute sourceLabelAttribute = attrMetaFactory.create().setName("label");
    sourceRefEntityType.addAttribute(sourceCodeAttribute, ROLE_ID);
    sourceRefEntityType.addAttribute(sourceLabelAttribute, ROLE_LABEL);
    return sourceRefEntityType;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute)

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