Search in sources :

Example 1 with DataReference

use of com.odysseusinc.arachne.portal.model.DataReference in project ArachneCentralAPI by OHDSI.

the class BaseAnalysisController method addCommonEntityToAnalysis.

@ApiOperation("Add common entity to analysis")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/entities", method = POST)
public JsonResult addCommonEntityToAnalysis(@PathVariable("analysisId") Long analysisId, @RequestBody @Valid DataReferenceDTO entityReference, @RequestParam(value = "type", required = false, defaultValue = "COHORT") CommonAnalysisType analysisType, Principal principal) throws NotExistException, JMSException, IOException, PermissionDeniedException, URISyntaxException {
    if (!analysisModificationLock.add(analysisId)) {
        throw new ValidationRuntimeException("Analysis import rejected", Collections.singletonMap(entityReference.getEntityGuid(), Collections.singletonList("Another import into this analysis is in progress")));
    }
    try {
        LOGGER.debug("Started import into analysis {}", analysisId);
        final IUser user = getUser(principal);
        final DataNode dataNode = dataNodeService.getById(entityReference.getDataNodeId());
        final T analysis = analysisService.getById(analysisId);
        final DataReference dataReference = dataReferenceService.addOrUpdate(entityReference.getEntityGuid(), dataNode);
        final List<MultipartFile> entityFiles = getEntityFiles(entityReference, dataNode, analysisType);
        String description = doAddCommonEntityToAnalysis(analysis, dataReference, user, analysisType, entityFiles);
        return new JsonResult(NO_ERROR, description);
    } finally {
        analysisModificationLock.remove(analysisId);
        LOGGER.debug("Completed import into analysis {}", analysisId);
    }
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) DataNode(com.odysseusinc.arachne.portal.model.DataNode) IUser(com.odysseusinc.arachne.portal.model.IUser) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) DataReference(com.odysseusinc.arachne.portal.model.DataReference) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with DataReference

use of com.odysseusinc.arachne.portal.model.DataReference in project ArachneCentralAPI by OHDSI.

the class BaseAnalysisController method doAddCommonEntityToAnalysis.

protected void doAddCommonEntityToAnalysis(T analysis, DataReference dataReference, IUser user, CommonAnalysisType analysisType, List<MultipartFile> files) throws IOException {
    files.stream().filter(f -> !CommonAnalysisType.COHORT.equals(analysisType) || !f.getName().endsWith(CommonFileUtils.OHDSI_JSON_EXT)).forEach(f -> {
        try {
            analysisService.saveFile(f, user, analysis, f.getName(), detectExecutable(analysisType, f), dataReference);
        } catch (IOException e) {
            LOGGER.error("Failed to save file", e);
        }
    });
    if (analysisType.equals(CommonAnalysisType.COHORT)) {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        class StringContainer {

            String value = CommonAnalysisType.COHORT.getTitle();
        }
        final StringContainer generatedFileName = new StringContainer();
        try (final ZipOutputStream zos = new ZipOutputStream(out)) {
            files.forEach(file -> {
                try {
                    if (file.getName().endsWith(CommonFileUtils.OHDSI_SQL_EXT)) {
                        String statement = org.apache.commons.io.IOUtils.toString(file.getInputStream(), "UTF-8");
                        String renderedSql = SqlRender.renderSql(statement, null, null);
                        DBMSType[] dbTypes = new DBMSType[] { DBMSType.POSTGRESQL, DBMSType.ORACLE, DBMSType.MS_SQL_SERVER, DBMSType.REDSHIFT, DBMSType.PDW };
                        String baseName = FilenameUtils.getBaseName(file.getOriginalFilename());
                        String extension = FilenameUtils.getExtension(file.getOriginalFilename());
                        for (final DBMSType dialect : dbTypes) {
                            final String sql = SqlTranslate.translateSql(renderedSql, DBMSType.MS_SQL_SERVER.getOhdsiDB(), dialect.getOhdsiDB());
                            final String fileName = baseName + "." + dialect.getLabel().replaceAll(" ", "-") + "." + extension;
                            ZipUtil.addZipEntry(zos, fileName, new ByteArrayInputStream(sql.getBytes("UTF-8")));
                        }
                        final String shortBaseName = baseName.replaceAll("\\.ohdsi", "");
                        if (!generatedFileName.value.contains(shortBaseName)) {
                            generatedFileName.value += "_" + shortBaseName;
                        }
                    } else {
                        String fileName = file.getName();
                        ZipUtil.addZipEntry(zos, fileName, file.getInputStream());
                    }
                } catch (IOException e) {
                    LOGGER.error("Failed to add file to archive", e);
                    throw new RuntimeIOException(e.getMessage(), e);
                }
            });
        }
        String fileName = generatedFileName.value + ".zip";
        final MultipartFile sqlArchive = new MockMultipartFile(fileName, fileName, "application/zip", out.toByteArray());
        analysisService.saveFile(sqlArchive, user, analysis, fileName, false, dataReference);
    }
}
Also used : Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) SqlTranslate(org.ohdsi.sql.SqlTranslate) Valid(javax.validation.Valid) CommentUtils.getRecentCommentables(com.odysseusinc.arachne.portal.util.CommentUtils.getRecentCommentables) AnalysisLockDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisLockDTO) BaseDataSourceService(com.odysseusinc.arachne.portal.service.BaseDataSourceService) Analysis(com.odysseusinc.arachne.portal.model.Analysis) Map(java.util.Map) Commentable(com.odysseusinc.arachne.portal.api.v1.dto.Commentable) Sort(org.springframework.data.domain.Sort) ImportedFile(com.odysseusinc.arachne.portal.util.ImportedFile) Resource(org.springframework.core.io.Resource) MessagingUtils(com.odysseusinc.arachne.portal.service.messaging.MessagingUtils) FieldError(org.springframework.validation.FieldError) SqlRender(org.ohdsi.sql.SqlRender) Set(java.util.Set) AnalysisFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO) Page(org.springframework.data.domain.Page) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) IUser(com.odysseusinc.arachne.portal.model.IUser) IOUtils(org.apache.commons.io.IOUtils) SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) RuntimeIOException(org.assertj.core.api.exception.RuntimeIOException) VALIDATION_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataReference(com.odysseusinc.arachne.portal.model.DataReference) BindingResult(org.springframework.validation.BindingResult) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) ZipUtil(com.odysseusinc.arachne.portal.util.ZipUtil) SubmissionInsightDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO) NO_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR) StreamSupport(java.util.stream.StreamSupport) CommonEntityRequestDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO) IOException(java.io.IOException) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) HttpUtils.putFileContentToResponse(com.odysseusinc.arachne.portal.util.HttpUtils.putFileContentToResponse) SubmissionInsightUpdateDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightUpdateDTO) DataReferenceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataReferenceDTO) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) AnalysisUpdateDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUpdateDTO) PathVariable(org.springframework.web.bind.annotation.PathVariable) AnalysisUnlockRequestDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUnlockRequestDTO) Date(java.util.Date) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) ApiOperation(io.swagger.annotations.ApiOperation) ByteArrayInputStream(java.io.ByteArrayInputStream) PERMISSION_DENIED(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.PERMISSION_DENIED) AnalysisUnlockRequest(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest) ToPdfConverter(com.odysseusinc.arachne.portal.service.ToPdfConverter) BaseSubmissionService(com.odysseusinc.arachne.portal.service.submission.BaseSubmissionService) BaseAnalysisService(com.odysseusinc.arachne.portal.service.analysis.BaseAnalysisService) AnalysisDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisDTO) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) CommonAnalysisType(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType) UUID(java.util.UUID) ShortBaseAnalysisDTO(com.odysseusinc.arachne.portal.api.v1.dto.ShortBaseAnalysisDTO) Collectors(java.util.stream.Collectors) JMSException(javax.jms.JMSException) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) CommonFileUtils(com.odysseusinc.arachne.commons.utils.CommonFileUtils) List(java.util.List) Principal(java.security.Principal) DataReferenceService(com.odysseusinc.arachne.portal.service.DataReferenceService) AnalysisCreateDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisCreateDTO) AnalysisUnlockRequestStatus(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequestStatus) FilenameUtils(org.apache.commons.io.FilenameUtils) SubmissionGroupDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionGroupDTO) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) FileDtoContentHandler(com.odysseusinc.arachne.portal.api.v1.dto.converters.FileDtoContentHandler) ClassPathResource(org.springframework.core.io.ClassPathResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) ObjectMessage(javax.jms.ObjectMessage) GET(org.springframework.web.bind.annotation.RequestMethod.GET) Submission(com.odysseusinc.arachne.portal.model.Submission) SubmissionGroupSearch(com.odysseusinc.arachne.portal.model.search.SubmissionGroupSearch) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) JmsTemplate(org.springframework.jms.core.JmsTemplate) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) POST(org.springframework.web.bind.annotation.RequestMethod.POST) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) LinkedList(java.util.LinkedList) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) ServiceNotAvailableException(com.odysseusinc.arachne.portal.exception.ServiceNotAvailableException) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) Logger(org.slf4j.Logger) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) DBMSType(com.odysseusinc.arachne.commons.types.DBMSType) HttpServletResponse(javax.servlet.http.HttpServletResponse) BaseDataNodeService(com.odysseusinc.arachne.portal.service.BaseDataNodeService) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) OptionDTO(com.odysseusinc.arachne.commons.api.v1.dto.OptionDTO) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) DataNode(com.odysseusinc.arachne.portal.model.DataNode) MultipartFile(org.springframework.web.multipart.MultipartFile) ImportService(com.odysseusinc.arachne.portal.service.ImportService) NotEmptyException(com.odysseusinc.arachne.portal.exception.NotEmptyException) SubmissionInsightService(com.odysseusinc.arachne.portal.service.submission.SubmissionInsightService) InputStream(java.io.InputStream) StringUtils(org.springframework.util.StringUtils) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) RuntimeIOException(org.assertj.core.api.exception.RuntimeIOException) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) DBMSType(com.odysseusinc.arachne.commons.types.DBMSType) RuntimeIOException(org.assertj.core.api.exception.RuntimeIOException) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with DataReference

use of com.odysseusinc.arachne.portal.model.DataReference in project ArachneCentralAPI by OHDSI.

the class AnalysisFilesSavingServiceImpl method saveFiles.

@PreAuthorize("hasPermission(#analysis, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).UPLOAD_ANALYSIS_FILES)")
protected List<AnalysisFile> saveFiles(List<MultipartFile> multipartFiles, IUser user, A analysis, DataReference dataReference, BiPredicate<String, CommonAnalysisType> checkFileExecutabilityPredicate) {
    List<MultipartFile> filteredFiles = multipartFiles.stream().filter(file -> !(CommonAnalysisType.COHORT.equals(analysis.getType()) && file.getName().endsWith(OHDSI_JSON_EXT))).filter(file -> !file.getName().startsWith(ANALYSIS_INFO_FILE_DESCRIPTION)).collect(Collectors.toList());
    List<AnalysisFile> savedFiles = new ArrayList<>();
    List<String> errorFileMessages = new ArrayList<>();
    for (MultipartFile file : filteredFiles) {
        try {
            final boolean isExecutable = checkFileExecutabilityPredicate.test(file.getOriginalFilename(), analysis.getType());
            savedFiles.add(saveFile(file, user, analysis, file.getName(), isExecutable, dataReference));
        } catch (AlreadyExistException e) {
            errorFileMessages.add(e.getMessage());
        }
    }
    if (!errorFileMessages.isEmpty()) {
        throw new ValidationRuntimeException("Failed to save files", ImmutableMap.of(dataReference.getGuid(), errorFileMessages));
    }
    return savedFiles;
}
Also used : AnalysisHelper(com.odysseusinc.arachne.portal.util.AnalysisHelper) AnalysisArchiveUtils(com.odysseusinc.arachne.commons.utils.AnalysisArchiveUtils) URL(java.net.URL) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) SqlTranslate(org.ohdsi.sql.SqlTranslate) StringUtils(org.apache.commons.lang3.StringUtils) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) OHDSI_SQL_EXT(com.odysseusinc.arachne.commons.utils.CommonFileUtils.OHDSI_SQL_EXT) ByteArrayInputStream(java.io.ByteArrayInputStream) Analysis(com.odysseusinc.arachne.portal.model.Analysis) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Path(java.nio.file.Path) RestTemplate(org.springframework.web.client.RestTemplate) ImmutableMap(com.google.common.collect.ImmutableMap) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) HttpHeaders(org.springframework.http.HttpHeaders) Collection(java.util.Collection) MediaType(org.springframework.http.MediaType) SqlRender(org.ohdsi.sql.SqlRender) CommonAnalysisType(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) IUser(com.odysseusinc.arachne.portal.model.IUser) IOUtils(org.apache.commons.io.IOUtils) CommonFileUtils(com.odysseusinc.arachne.commons.utils.CommonFileUtils) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) AnalysisFilesSavingService(com.odysseusinc.arachne.portal.service.analysis.AnalysisFilesSavingService) NotNull(org.jetbrains.annotations.NotNull) FilenameUtils(org.apache.commons.io.FilenameUtils) ZipOutputStream(java.util.zip.ZipOutputStream) ANALYSIS_INFO_FILE_DESCRIPTION(com.odysseusinc.arachne.commons.utils.CommonFileUtils.ANALYSIS_INFO_FILE_DESCRIPTION) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OHDSI_JSON_EXT(com.odysseusinc.arachne.commons.utils.CommonFileUtils.OHDSI_JSON_EXT) DataReference(com.odysseusinc.arachne.portal.model.DataReference) ArachneSystemRuntimeException(com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException) ArrayList(java.util.ArrayList) AntivirusJobEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent) BiPredicate(java.util.function.BiPredicate) IORuntimeException(com.odysseusinc.arachne.portal.exception.IORuntimeException) ZipUtil(com.odysseusinc.arachne.portal.util.ZipUtil) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Service(org.springframework.stereotype.Service) AnalysisFileRepository(com.odysseusinc.arachne.portal.repository.AnalysisFileRepository) AnalysisPreprocessorService(com.odysseusinc.arachne.portal.service.impl.AnalysisPreprocessorService) AnalysisUtils.throwAccessDeniedExceptionIfLocked(com.odysseusinc.arachne.portal.service.analysis.impl.AnalysisUtils.throwAccessDeniedExceptionIfLocked) REPLACE_EXISTING(java.nio.file.StandardCopyOption.REPLACE_EXISTING) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) Logger(org.slf4j.Logger) DBMSType(com.odysseusinc.arachne.commons.types.DBMSType) Files(java.nio.file.Files) AntivirusJobFileType(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType) HttpMethod(org.springframework.http.HttpMethod) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) HttpStatus(org.springframework.http.HttpStatus) Paths(java.nio.file.Paths) MultipartFile(org.springframework.web.multipart.MultipartFile) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) ArrayList(java.util.ArrayList) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with DataReference

use of com.odysseusinc.arachne.portal.model.DataReference in project ArachneCentralAPI by OHDSI.

the class AnalysisFilesSavingServiceImpl method saveCohortAnalysisArchive.

@PreAuthorize("hasPermission(#analysis, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).UPLOAD_ANALYSIS_FILES)")
public void saveCohortAnalysisArchive(A analysis, DataReference dataReference, IUser user, List<MultipartFile> files) {
    MultipartFile genericSqlFile = files.stream().filter(file -> file.getName().endsWith(OHDSI_SQL_EXT)).findAny().orElseThrow(() -> new ArachneSystemRuntimeException(String.format("There is no sql file for %s analysis.", analysis.getId())));
    Collection<MultipartFile> filesForArchive = files.stream().filter(file -> ObjectUtils.notEqual(file, genericSqlFile)).filter(file -> !StringUtils.equals(ANALYSIS_INFO_FILE_DESCRIPTION, file.getName())).collect(Collectors.toList());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (ZipOutputStream zos = new ZipOutputStream(out)) {
        generateFilesForEachDialectAndAddToZip(zos, genericSqlFile);
        ZipUtil.addZipEntries(zos, filesForArchive);
    } catch (IOException e) {
        log.error("Failed to create zip file for {} analysis", analysis.getId(), e);
        throw new ArachneSystemRuntimeException(e);
    }
    String fileName = AnalysisArchiveUtils.getArchiveFileName(CommonAnalysisType.COHORT, getAnalysisName(genericSqlFile));
    MultipartFile sqlArchive = new MockMultipartFile(fileName, fileName, "application/zip", out.toByteArray());
    try {
        saveFile(sqlArchive, user, analysis, fileName, false, dataReference);
    } catch (Exception e) {
        log.error("Failed to save zip file for {} analysis", analysis.getId(), e);
        throw new ArachneSystemRuntimeException(e);
    }
}
Also used : ArachneSystemRuntimeException(com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException) AnalysisHelper(com.odysseusinc.arachne.portal.util.AnalysisHelper) AnalysisArchiveUtils(com.odysseusinc.arachne.commons.utils.AnalysisArchiveUtils) URL(java.net.URL) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) SqlTranslate(org.ohdsi.sql.SqlTranslate) StringUtils(org.apache.commons.lang3.StringUtils) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) OHDSI_SQL_EXT(com.odysseusinc.arachne.commons.utils.CommonFileUtils.OHDSI_SQL_EXT) ByteArrayInputStream(java.io.ByteArrayInputStream) Analysis(com.odysseusinc.arachne.portal.model.Analysis) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Path(java.nio.file.Path) RestTemplate(org.springframework.web.client.RestTemplate) ImmutableMap(com.google.common.collect.ImmutableMap) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) HttpHeaders(org.springframework.http.HttpHeaders) Collection(java.util.Collection) MediaType(org.springframework.http.MediaType) SqlRender(org.ohdsi.sql.SqlRender) CommonAnalysisType(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) IUser(com.odysseusinc.arachne.portal.model.IUser) IOUtils(org.apache.commons.io.IOUtils) CommonFileUtils(com.odysseusinc.arachne.commons.utils.CommonFileUtils) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) AnalysisFilesSavingService(com.odysseusinc.arachne.portal.service.analysis.AnalysisFilesSavingService) NotNull(org.jetbrains.annotations.NotNull) FilenameUtils(org.apache.commons.io.FilenameUtils) ZipOutputStream(java.util.zip.ZipOutputStream) ANALYSIS_INFO_FILE_DESCRIPTION(com.odysseusinc.arachne.commons.utils.CommonFileUtils.ANALYSIS_INFO_FILE_DESCRIPTION) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OHDSI_JSON_EXT(com.odysseusinc.arachne.commons.utils.CommonFileUtils.OHDSI_JSON_EXT) DataReference(com.odysseusinc.arachne.portal.model.DataReference) ArachneSystemRuntimeException(com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException) ArrayList(java.util.ArrayList) AntivirusJobEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent) BiPredicate(java.util.function.BiPredicate) IORuntimeException(com.odysseusinc.arachne.portal.exception.IORuntimeException) ZipUtil(com.odysseusinc.arachne.portal.util.ZipUtil) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Service(org.springframework.stereotype.Service) AnalysisFileRepository(com.odysseusinc.arachne.portal.repository.AnalysisFileRepository) AnalysisPreprocessorService(com.odysseusinc.arachne.portal.service.impl.AnalysisPreprocessorService) AnalysisUtils.throwAccessDeniedExceptionIfLocked(com.odysseusinc.arachne.portal.service.analysis.impl.AnalysisUtils.throwAccessDeniedExceptionIfLocked) REPLACE_EXISTING(java.nio.file.StandardCopyOption.REPLACE_EXISTING) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) Logger(org.slf4j.Logger) DBMSType(com.odysseusinc.arachne.commons.types.DBMSType) Files(java.nio.file.Files) AntivirusJobFileType(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType) HttpMethod(org.springframework.http.HttpMethod) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) HttpStatus(org.springframework.http.HttpStatus) Paths(java.nio.file.Paths) MultipartFile(org.springframework.web.multipart.MultipartFile) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) ArachneSystemRuntimeException(com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException) IORuntimeException(com.odysseusinc.arachne.portal.exception.IORuntimeException) IOException(java.io.IOException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with DataReference

use of com.odysseusinc.arachne.portal.model.DataReference in project ArachneCentralAPI by OHDSI.

the class BaseAnalysisController method updateCommonEntityInAnalysis.

@ApiOperation("update common entity in analysis")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/entities/{fileUuid}", method = PUT)
public JsonResult updateCommonEntityInAnalysis(@PathVariable("analysisId") Long analysisId, @PathVariable("fileUuid") String fileUuid, @RequestParam(value = "type", required = false, defaultValue = "COHORT") CommonAnalysisType analysisType, Principal principal) throws IOException, JMSException, PermissionDeniedException, URISyntaxException {
    final IUser user = getUser(principal);
    final AnalysisFile analysisFile = analysisService.getAnalysisFile(analysisId, fileUuid);
    T analysis = (T) analysisFile.getAnalysis();
    final DataReference dataReference = analysisFile.getDataReference();
    final DataReferenceDTO entityReference = new DataReferenceDTO(dataReference.getDataNode().getId(), dataReference.getGuid());
    final List<MultipartFile> entityFiles = getEntityFiles(entityReference, dataReference.getDataNode(), analysisType);
    analysisService.findAnalysisFilesByDataReference(analysis, dataReference).forEach(existingAnalysisFile -> {
        analysisService.deleteAnalysisFile(analysis, existingAnalysisFile);
        analysis.getFiles().remove(existingAnalysisFile);
    });
    final String description = doAddCommonEntityToAnalysis(analysis, dataReference, user, analysisType, entityFiles);
    return new JsonResult(NO_ERROR, description);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) DataReferenceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataReferenceDTO) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) IUser(com.odysseusinc.arachne.portal.model.IUser) DataReference(com.odysseusinc.arachne.portal.model.DataReference) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataReference (com.odysseusinc.arachne.portal.model.DataReference)5 IUser (com.odysseusinc.arachne.portal.model.IUser)5 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)5 MultipartFile (org.springframework.web.multipart.MultipartFile)5 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)4 CommonAnalysisType (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType)3 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)3 DBMSType (com.odysseusinc.arachne.commons.types.DBMSType)3 CommonFileUtils (com.odysseusinc.arachne.commons.utils.CommonFileUtils)3 UploadFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO)3 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)3 ValidationRuntimeException (com.odysseusinc.arachne.portal.exception.ValidationRuntimeException)3 Analysis (com.odysseusinc.arachne.portal.model.Analysis)3 ZipUtil (com.odysseusinc.arachne.portal.util.ZipUtil)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 List (java.util.List)3