Search in sources :

Example 1 with WithJsMagmaScriptContext

use of org.molgenis.js.magma.WithJsMagmaScriptContext in project molgenis by molgenis.

the class RestControllerV2 method updateAttribute.

/**
 * @param entityTypeId The name of the entity to update
 * @param attributeName The name of the attribute to update
 * @param request EntityCollectionBatchRequestV2
 * @param response HttpServletResponse
 */
// getEntities is guaranteed to be not empty
@SuppressWarnings("java:S2259")
@Transactional
@WithJsMagmaScriptContext
@PutMapping("/{entityTypeId}/{attributeName}")
@ResponseStatus(OK)
public synchronized void updateAttribute(@PathVariable("entityTypeId") String entityTypeId, @PathVariable("attributeName") String attributeName, @RequestBody @Valid EntityCollectionBatchRequestV2 request, HttpServletResponse response) {
    final EntityType meta = dataService.getEntityType(entityTypeId);
    try {
        Attribute attr = meta.getAttribute(attributeName);
        if (attr == null) {
            throw new UnknownAttributeException(meta, attributeName);
        }
        if (attr.isReadOnly()) {
            throw createMolgenisDataAccessExceptionReadOnlyAttribute(entityTypeId, attributeName);
        }
        // transform request entities to real Entity objects
        final List<Entity> entities = request.getEntities().stream().filter(e -> e.size() == 2).map(e -> this.restService.toEntity(meta, e)).collect(toList());
        if (entities.size() != request.getEntities().size()) {
            throw createMolgenisDataExceptionIdentifierAndValue();
        }
        // update original entities
        final List<Entity> updatedEntities = new ArrayList<>();
        int count = 0;
        for (Entity entity : entities) {
            Object id = checkForEntityId(entity, count);
            Entity originalEntity = dataService.findOneById(entityTypeId, id);
            if (originalEntity == null) {
                throw new UnknownEntityException(meta, id);
            }
            originalEntity.set(attributeName, entity.get(attributeName));
            updatedEntities.add(originalEntity);
            count++;
        }
        this.dataService.update(entityTypeId, updatedEntities.stream());
        response.setStatus(HttpServletResponse.SC_OK);
    } catch (Exception e) {
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        throw e;
    }
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) CREATED(org.springframework.http.HttpStatus.CREATED) RepositoryCapability(org.molgenis.data.RepositoryCapability) RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) PermissionSystemService(org.molgenis.data.security.permission.PermissionSystemService) Attribute(org.molgenis.data.meta.model.Attribute) TEXT_PLAIN_VALUE(org.springframework.http.MediaType.TEXT_PLAIN_VALUE) Valid(javax.validation.Valid) AttributeFilterToFetchConverter.createDefaultAttributeFetch(org.molgenis.api.data.v2.AttributeFilterToFetchConverter.createDefaultAttributeFetch) Map(java.util.Map) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) PostMapping(org.springframework.web.bind.annotation.PostMapping) Set(java.util.Set) RestController(org.springframework.web.bind.annotation.RestController) MEDIUM(java.time.format.FormatStyle.MEDIUM) EntityPager(org.molgenis.api.data.v1.EntityPager) Stream(java.util.stream.Stream) UserPermissionEvaluator(org.molgenis.security.core.UserPermissionEvaluator) UNAUTHORIZED(org.springframework.http.HttpStatus.UNAUTHORIZED) UnknownEntityException(org.molgenis.data.UnknownEntityException) Query(org.molgenis.data.Query) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) Timed(io.micrometer.core.annotation.Timed) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) WithJsMagmaScriptContext(org.molgenis.js.magma.WithJsMagmaScriptContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) ResourceBundle(java.util.ResourceBundle) MolgenisDataAccessException(org.molgenis.data.MolgenisDataAccessException) AggregateResult(org.molgenis.data.aggregation.AggregateResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) Properties(java.util.Properties) StringWriter(java.io.StringWriter) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) IOException(java.io.IOException) RepositoryAlreadyExistsException(org.molgenis.data.RepositoryAlreadyExistsException) MolgenisDataException(org.molgenis.data.MolgenisDataException) Entity(org.molgenis.data.Entity) ConversionFailedException(org.springframework.core.convert.ConversionFailedException) PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) NO_CONTENT(org.springframework.http.HttpStatus.NO_CONTENT) RepositoryCopier(org.molgenis.data.support.RepositoryCopier) ErrorMessageResponse(org.molgenis.web.ErrorMessageResponse) LoggerFactory(org.slf4j.LoggerFactory) Fetch(org.molgenis.data.Fetch) PutMapping(org.springframework.web.bind.annotation.PutMapping) Locale(java.util.Locale) ApiNamespace(org.molgenis.api.ApiNamespace) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) Collectors.toSet(java.util.stream.Collectors.toSet) RestService(org.molgenis.api.data.RestService) BAD_REQUEST(org.springframework.http.HttpStatus.BAD_REQUEST) Instant(java.time.Instant) EntityType(org.molgenis.data.meta.model.EntityType) String.format(java.lang.String.format) UnknownAttributeException(org.molgenis.data.UnknownAttributeException) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) LanguageService(org.molgenis.util.i18n.LanguageService) List(java.util.List) LocalDate(java.time.LocalDate) Repository(org.molgenis.data.Repository) EntityTypeUtils(org.molgenis.data.util.EntityTypeUtils) EntityTypePermissionDeniedException(org.molgenis.data.security.exception.EntityTypePermissionDeniedException) NameValidator(org.molgenis.data.validation.meta.NameValidator) LocalizationService(org.molgenis.data.i18n.LocalizationService) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) Lists.transform(com.google.common.collect.Lists.transform) QueryImpl(org.molgenis.data.support.QueryImpl) MolgenisQueryException(org.molgenis.data.MolgenisQueryException) RepositoryNotCapableException(org.molgenis.data.RepositoryNotCapableException) EntityUtils.getTypedValue(org.molgenis.data.util.EntityUtils.getTypedValue) Objects.requireNonNull(java.util.Objects.requireNonNull) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ATTRIBUTE_META_DATA(org.molgenis.data.meta.model.AttributeMetadata.ATTRIBUTE_META_DATA) AttributeType(org.molgenis.data.meta.AttributeType) Logger(org.slf4j.Logger) HttpServletResponse(javax.servlet.http.HttpServletResponse) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) ErrorMessage(org.molgenis.web.ErrorMessageResponse.ErrorMessage) ServletUriComponentsBuilder.fromCurrentServletMapping(org.springframework.web.servlet.support.ServletUriComponentsBuilder.fromCurrentServletMapping) Collectors.toList(java.util.stream.Collectors.toList) DateTimeFormatter(java.time.format.DateTimeFormatter) ZonedDateTime.now(java.time.ZonedDateTime.now) DataService(org.molgenis.data.DataService) OK(org.springframework.http.HttpStatus.OK) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) UnknownEntityException(org.molgenis.data.UnknownEntityException) ArrayList(java.util.ArrayList) UnknownAttributeException(org.molgenis.data.UnknownAttributeException) UnknownEntityException(org.molgenis.data.UnknownEntityException) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) MolgenisDataAccessException(org.molgenis.data.MolgenisDataAccessException) IOException(java.io.IOException) RepositoryAlreadyExistsException(org.molgenis.data.RepositoryAlreadyExistsException) MolgenisDataException(org.molgenis.data.MolgenisDataException) ConversionFailedException(org.springframework.core.convert.ConversionFailedException) UnknownAttributeException(org.molgenis.data.UnknownAttributeException) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) EntityTypePermissionDeniedException(org.molgenis.data.security.exception.EntityTypePermissionDeniedException) MolgenisQueryException(org.molgenis.data.MolgenisQueryException) RepositoryNotCapableException(org.molgenis.data.RepositoryNotCapableException) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) WithJsMagmaScriptContext(org.molgenis.js.magma.WithJsMagmaScriptContext) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PutMapping(org.springframework.web.bind.annotation.PutMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with WithJsMagmaScriptContext

use of org.molgenis.js.magma.WithJsMagmaScriptContext in project molgenis by molgenis.

the class CopyServiceImpl method copy.

@Override
@SuppressWarnings(// Exception types should not be tested using "instanceof" in catch blocks
"java:S1193")
@Transactional(isolation = Isolation.SERIALIZABLE)
@WithJsMagmaScriptContext
public Void copy(List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetPackageId, Progress progress) {
    try {
        ResourceCollection resourceCollection = resourceCollector.get(resources);
        Package targetPackage = getPackage(targetPackageId);
        CopyState state = CopyState.create(targetPackage, progress);
        copyResources(resourceCollection, state);
    } catch (RuntimeException e) {
        if (e instanceof ErrorCoded) {
            throw e;
        } else {
            throw new UnknownCopyFailedException(e);
        }
    }
    return null;
}
Also used : UnknownCopyFailedException(org.molgenis.navigator.copy.exception.UnknownCopyFailedException) ErrorCoded(org.molgenis.util.exception.ErrorCoded) Package(org.molgenis.data.meta.model.Package) ResourceCollection(org.molgenis.navigator.util.ResourceCollection) WithJsMagmaScriptContext(org.molgenis.js.magma.WithJsMagmaScriptContext) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with WithJsMagmaScriptContext

use of org.molgenis.js.magma.WithJsMagmaScriptContext in project molgenis by molgenis.

the class NegotiatorController method validateNegotiatorExport.

/**
 * Validates a {@link NegotiatorRequest}.
 *
 * <p>Used by the data explorer to verify the request. Since the data explorer does not allow
 * filtering on more than one repository, this endpoint does *NOT* support providing biobankRsql.
 *
 * <ul>
 *   <li>Checks if disabled collections are selected.
 *   <li>Checks if at least one collection is left after filtering out the disabled ones.
 * </ul>
 *
 * @param request the request to validate
 * @return ExportValidationResponse
 * @throws MolgenisDataException if the negotiator is not configured for this entity type
 */
@PostMapping("/validate")
@ResponseBody
@WithJsMagmaScriptContext
public ExportValidationResponse validateNegotiatorExport(@RequestBody NegotiatorRequest request) {
    if (request.getBiobankRsql() != null || request.getBiobankId() != null) {
        throw new IllegalArgumentException("Cannot verify requests with biobank filters.");
    }
    boolean isValidRequest = true;
    String message = "";
    List<String> enabledCollectionsLabels;
    List<String> disabledCollectionLabels;
    Optional<NegotiatorEntityConfig> entityConfigOptional = getNegotiatorEntityConfig(request.getEntityId());
    if (entityConfigOptional.isPresent()) {
        NegotiatorEntityConfig entityConfig = entityConfigOptional.get();
        LOG.info("Validating negotiator request\n\n{}", request);
        List<Entity> collectionEntities = getCollectionEntities(request);
        List<Entity> disabledCollections = getDisabledCollections(collectionEntities, entityConfig);
        Function<Entity, String> getLabel = entity -> entity.getLabelValue().toString();
        disabledCollectionLabels = disabledCollections.stream().map(getLabel).collect(toList());
        enabledCollectionsLabels = collectionEntities.stream().filter(e -> !disabledCollections.contains(e)).map(getLabel).collect(toList());
        if (!disabledCollections.isEmpty()) {
            message = messageSource.getMessage("dataexplorer_directory_disabled", new Object[] { disabledCollections.size(), collectionEntities.size() }, getLocale());
        }
        if (collectionEntities.isEmpty() || (collectionEntities.size() == disabledCollections.size())) {
            isValidRequest = false;
            message = messageSource.getMessage("dataexplorer_directory_no_rows", new Object[] {}, getLocale());
        }
    } else {
        throw new MolgenisDataException(messageSource.getMessage("dataexplorer_directory_no_config", new Object[] {}, getLocale()));
    }
    return ExportValidationResponse.create(isValidRequest, message, enabledCollectionsLabels, disabledCollectionLabels);
}
Also used : MissingLocationException(org.molgenis.dataexplorer.negotiator.exception.MissingLocationException) PluginController(org.molgenis.web.PluginController) NegotiatorConfig(org.molgenis.dataexplorer.negotiator.config.NegotiatorConfig) LoggerFactory(org.slf4j.LoggerFactory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) QueryImpl(org.molgenis.data.support.QueryImpl) Controller(org.springframework.stereotype.Controller) Function(java.util.function.Function) Attribute(org.molgenis.data.meta.model.Attribute) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem) QueryRsqlConverter(org.molgenis.web.rsql.QueryRsqlConverter) RequestBody(org.springframework.web.bind.annotation.RequestBody) WithJsMagmaScriptContext(org.molgenis.js.magma.WithJsMagmaScriptContext) PluginPermission(org.molgenis.data.plugin.model.PluginPermission) Objects.requireNonNull(java.util.Objects.requireNonNull) PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) JsMagmaScriptEvaluator(org.molgenis.js.magma.JsMagmaScriptEvaluator) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) RestTemplate(org.springframework.web.client.RestTemplate) MessageSource(org.springframework.context.MessageSource) RestClientException(org.springframework.web.client.RestClientException) PostMapping(org.springframework.web.bind.annotation.PostMapping) Logger(org.slf4j.Logger) LocaleContextHolder.getLocale(org.springframework.context.i18n.LocaleContextHolder.getLocale) UTF_8(java.nio.charset.StandardCharsets.UTF_8) HttpHeaders(org.springframework.http.HttpHeaders) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ENABLED_EXPRESSION(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfigMetadata.ENABLED_EXPRESSION) Collectors(java.util.stream.Collectors) NegotiatorEntityConfigMetadata(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfigMetadata) Collectors.toList(java.util.stream.Collectors.toList) Base64(java.util.Base64) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) UserPermissionEvaluator(org.molgenis.security.core.UserPermissionEvaluator) Repository(org.molgenis.data.Repository) EntityTypeUtils(org.molgenis.data.util.EntityTypeUtils) Optional(java.util.Optional) DataService(org.molgenis.data.DataService) Query(org.molgenis.data.Query) NegotiatorEntityConfig(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfig) MolgenisDataException(org.molgenis.data.MolgenisDataException) Entity(org.molgenis.data.Entity) NegotiatorEntityConfig(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfig) HttpEntity(org.springframework.http.HttpEntity) Entity(org.molgenis.data.Entity) MolgenisDataException(org.molgenis.data.MolgenisDataException) WithJsMagmaScriptContext(org.molgenis.js.magma.WithJsMagmaScriptContext) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with WithJsMagmaScriptContext

use of org.molgenis.js.magma.WithJsMagmaScriptContext in project molgenis by molgenis.

the class MappingServiceController method attributeMappingFeedback.

@WithJsMagmaScriptContext
@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(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));
    Stream<Entity> sourceEntities = dataService.findAll(source).limit(10);
    List<AlgorithmResult> algorithmResults = sourceEntities.map(sourceEntity -> {
        try {
            algorithmService.bind(sourceEntity);
            return AlgorithmResult.createSuccess(algorithmService.apply(algorithmTest), sourceEntity);
        } catch (Exception e) {
            return AlgorithmResult.createFailure(e, sourceEntity);
        }
    }).collect(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.findMenuItemPath(DataExplorerController.ID));
    return VIEW_ATTRIBUTE_MAPPING_FEEDBACK;
}
Also used : AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) PathVariable(org.springframework.web.bind.annotation.PathVariable) RepositoryCapability(org.molgenis.data.RepositoryCapability) PluginController(org.molgenis.web.PluginController) RequestParam(org.springframework.web.bind.annotation.RequestParam) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) 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) TEXT_PLAIN_VALUE(org.springframework.http.MediaType.TEXT_PLAIN_VALUE) AlgorithmState(org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState) Valid(javax.validation.Valid) Relation(org.molgenis.data.semantic.Relation) AttributeSearchResults(org.molgenis.semanticsearch.explain.bean.AttributeSearchResults) Model(org.springframework.ui.Model) Map(java.util.Map) RunAsSystemAspect(org.molgenis.security.core.runas.RunAsSystemAspect) URI(java.net.URI) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) PostMapping(org.springframework.web.bind.annotation.PostMapping) NameValidator.validateEntityName(org.molgenis.data.validation.meta.NameValidator.validateEntityName) DataExplorerController(org.molgenis.dataexplorer.controller.DataExplorerController) SecurityUtils.getCurrentUsername(org.molgenis.security.core.utils.SecurityUtils.getCurrentUsername) ImmutableMap(com.google.common.collect.ImmutableMap) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) MappingService(org.molgenis.semanticmapper.service.MappingService) Collection(java.util.Collection) JobsController(org.molgenis.core.ui.jobs.JobsController) Set(java.util.Set) Collectors(java.util.stream.Collectors) EntityType(org.molgenis.data.meta.model.EntityType) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) UnknownAttributeException(org.molgenis.data.UnknownAttributeException) OntologyTagService(org.molgenis.semanticsearch.service.OntologyTagService) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Stream(java.util.stream.Stream) SecurityUtils.currentUserIsSu(org.molgenis.security.core.utils.SecurityUtils.currentUserIsSu) Repository(org.molgenis.data.Repository) EntityTypeUtils(org.molgenis.data.util.EntityTypeUtils) MappingJobExecution(org.molgenis.semanticmapper.job.MappingJobExecution) Query(org.molgenis.data.Query) Iterables(com.google.common.collect.Iterables) JobExecutor(org.molgenis.jobs.JobExecutor) CategoryMapping.create(org.molgenis.semanticmapper.mapping.model.CategoryMapping.create) StringUtils.trim(org.apache.commons.lang3.StringUtils.trim) JobExecutionUriUtils(org.molgenis.jobs.JobExecutionUriUtils) SemanticSearchService(org.molgenis.semanticsearch.service.SemanticSearchService) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) QueryImpl(org.molgenis.data.support.QueryImpl) Controller(org.springframework.stereotype.Controller) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) RequestBody(org.springframework.web.bind.annotation.RequestBody) WithJsMagmaScriptContext(org.molgenis.js.magma.WithJsMagmaScriptContext) MessageFormat.format(java.text.MessageFormat.format) AggregateResult(org.molgenis.data.aggregation.AggregateResult) CategoryMapping(org.molgenis.semanticmapper.mapping.model.CategoryMapping) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) PackageUtils.isSystemPackage(org.molgenis.data.util.PackageUtils.isSystemPackage) GetMapping(org.springframework.web.bind.annotation.GetMapping) MappingJobExecutionFactory(org.molgenis.semanticmapper.job.MappingJobExecutionFactory) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) Hit(org.molgenis.semanticsearch.semantic.Hit) 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) ExplainedAttributeDto(org.molgenis.semanticsearch.explain.bean.ExplainedAttributeDto) ResponseEntity.ok(org.springframework.http.ResponseEntity.ok) TEXT_PLAIN(org.springframework.http.MediaType.TEXT_PLAIN) ResponseEntity.created(org.springframework.http.ResponseEntity.created) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Streams.stream(com.google.common.collect.Streams.stream) Collectors.toList(java.util.stream.Collectors.toList) COMPOUND(org.molgenis.data.meta.AttributeType.COMPOUND) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) AlgorithmResult(org.molgenis.semanticmapper.mapping.model.AlgorithmResult) DataService(org.molgenis.data.DataService) Package(org.molgenis.data.meta.model.Package) ResponseEntity(org.springframework.http.ResponseEntity) MenuReaderService(org.molgenis.web.menu.MenuReaderService) MolgenisDataException(org.molgenis.data.MolgenisDataException) Entity(org.molgenis.data.Entity) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) ResponseEntity(org.springframework.http.ResponseEntity) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) URISyntaxException(java.net.URISyntaxException) UnknownAttributeException(org.molgenis.data.UnknownAttributeException) MolgenisDataException(org.molgenis.data.MolgenisDataException) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) EntityType(org.molgenis.data.meta.model.EntityType) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) AlgorithmResult(org.molgenis.semanticmapper.mapping.model.AlgorithmResult) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) WithJsMagmaScriptContext(org.molgenis.js.magma.WithJsMagmaScriptContext) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 5 with WithJsMagmaScriptContext

use of org.molgenis.js.magma.WithJsMagmaScriptContext in project molgenis by molgenis.

the class MappingServiceImpl method applyMappings.

@Override
@Transactional
@WithJsMagmaScriptContext
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) Entity(org.molgenis.data.Entity) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) WithJsMagmaScriptContext(org.molgenis.js.magma.WithJsMagmaScriptContext) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

WithJsMagmaScriptContext (org.molgenis.js.magma.WithJsMagmaScriptContext)8 Entity (org.molgenis.data.Entity)7 Transactional (org.springframework.transaction.annotation.Transactional)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)6 List (java.util.List)5 Collectors.toList (java.util.stream.Collectors.toList)5 EntityType (org.molgenis.data.meta.model.EntityType)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 Set (java.util.Set)4 Stream (java.util.stream.Stream)4 Valid (javax.validation.Valid)4 DataService (org.molgenis.data.DataService)3 MolgenisDataException (org.molgenis.data.MolgenisDataException)3 Query (org.molgenis.data.Query)3 Repository (org.molgenis.data.Repository)3 RepositoryAlreadyExistsException (org.molgenis.data.RepositoryAlreadyExistsException)3