Search in sources :

Example 1 with ArachneSystemRuntimeException

use of com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException in project ArachneCentralAPI by OHDSI.

the class AnalysisFilesSavingServiceImpl method saveFile.

@Override
@PreAuthorize("hasPermission(#analysis, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).UPLOAD_ANALYSIS_FILES)")
public AnalysisFile saveFile(MultipartFile multipartFile, IUser user, A analysis, String label, Boolean isExecutable, DataReference dataReference) throws AlreadyExistException {
    ensureLabelIsUnique(analysis.getId(), label);
    String originalFilename = multipartFile.getOriginalFilename();
    String fileNameLowerCase = UUID.randomUUID().toString();
    try {
        Path analysisPath = analysisHelper.getAnalysisPath(analysis);
        Path targetPath = Paths.get(analysisPath.toString(), fileNameLowerCase);
        Files.copy(multipartFile.getInputStream(), targetPath, REPLACE_EXISTING);
        final String contentType = CommonFileUtils.getContentType(originalFilename, targetPath.toString());
        AnalysisFile analysisFile = buildNewAnalysisFileEntry(user, analysis, label, isExecutable, originalFilename, fileNameLowerCase, contentType);
        analysisFile.setDataReference(dataReference);
        AnalysisFile saved = analysisFileRepository.save(analysisFile);
        analysis.getFiles().add(saved);
        preprocessorService.preprocessFile(analysis, analysisFile);
        eventPublisher.publishEvent(new AntivirusJobEvent(this, new AntivirusJob(saved.getId(), saved.getName(), new FileInputStream(targetPath.toString()), AntivirusJobFileType.ANALYSIS_FILE)));
        return saved;
    } catch (IOException | RuntimeException ex) {
        String message = "error save file to disk, filename=" + fileNameLowerCase + " ex=" + ex.toString();
        log.error(message, ex);
        throw new ArachneSystemRuntimeException(message);
    }
}
Also used : Path(java.nio.file.Path) ArachneSystemRuntimeException(com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) ArachneSystemRuntimeException(com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException) IORuntimeException(com.odysseusinc.arachne.portal.exception.IORuntimeException) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) AntivirusJobEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with ArachneSystemRuntimeException

use of com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException in project ArachneCentralAPI by OHDSI.

the class ToPdfConverter method recreateJodConverterWorkingFolderIfNoLongerExists.

private void recreateJodConverterWorkingFolderIfNoLongerExists() {
    if (officeManager != null) {
        final File tempFile = officeManager.makeTemporaryFile();
        final Path currentTempDir = tempFile.toPath().getParent();
        if (!currentTempDir.toFile().exists()) {
            log.info("Recreating JodConverter temp folder: {}", currentTempDir);
            try {
                Files.createDirectories(currentTempDir);
            } catch (IOException ex) {
                throw new ArachneSystemRuntimeException("Cannot restore officeManager temp folder: " + currentTempDir, ex);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) ArachneSystemRuntimeException(com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException) IOException(java.io.IOException) File(java.io.File)

Example 3 with ArachneSystemRuntimeException

use of com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException in project ArachneCentralAPI by OHDSI.

the class SearchIndexesRefresher method rebuildAllIndexes.

private void rebuildAllIndexes() {
    try {
        dataSourceService.indexAllBySolr();
        userService.indexAllBySolr();
        studyService.indexAllBySolr();
        analysisService.indexAllBySolr();
        paperService.indexAllBySolr();
    } catch (Exception ex) {
        throw new ArachneSystemRuntimeException(ex);
    }
}
Also used : ArachneSystemRuntimeException(com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException) ArachneSystemRuntimeException(com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException)

Example 4 with ArachneSystemRuntimeException

use of com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException 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)

Aggregations

ArachneSystemRuntimeException (com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException)4 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 IORuntimeException (com.odysseusinc.arachne.portal.exception.IORuntimeException)2 ValidationRuntimeException (com.odysseusinc.arachne.portal.exception.ValidationRuntimeException)2 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)2 AntivirusJob (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob)2 AntivirusJobEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent)2 FileInputStream (java.io.FileInputStream)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 CommonAnalysisType (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType)1 DBMSType (com.odysseusinc.arachne.commons.types.DBMSType)1 AnalysisArchiveUtils (com.odysseusinc.arachne.commons.utils.AnalysisArchiveUtils)1 CommonFileUtils (com.odysseusinc.arachne.commons.utils.CommonFileUtils)1 ANALYSIS_INFO_FILE_DESCRIPTION (com.odysseusinc.arachne.commons.utils.CommonFileUtils.ANALYSIS_INFO_FILE_DESCRIPTION)1 OHDSI_JSON_EXT (com.odysseusinc.arachne.commons.utils.CommonFileUtils.OHDSI_JSON_EXT)1 OHDSI_SQL_EXT (com.odysseusinc.arachne.commons.utils.CommonFileUtils.OHDSI_SQL_EXT)1 UploadFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO)1 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)1 Analysis (com.odysseusinc.arachne.portal.model.Analysis)1