Search in sources :

Example 6 with AnalysisFile

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

the class BaseAnalysisServiceImpl method saveFile.

@Override
public AnalysisFile saveFile(MultipartFile multipartFile, IUser user, A analysis, String label, Boolean isExecutable, DataReference dataReference) throws IOException {
    String originalFilename = multipartFile.getOriginalFilename();
    String fileNameLowerCase = UUID.randomUUID().toString();
    try {
        Path analysisPath = getAnalysisPath(analysis);
        Path targetPath = Paths.get(analysisPath.toString(), fileNameLowerCase);
        Files.copy(multipartFile.getInputStream(), targetPath, REPLACE_EXISTING);
        AnalysisFile analysisFile = new AnalysisFile();
        analysisFile.setDataReference(dataReference);
        analysisFile.setUuid(fileNameLowerCase);
        analysisFile.setAnalysis(analysis);
        analysisFile.setContentType(CommonFileUtils.getContentType(originalFilename, targetPath.toString()));
        analysisFile.setLabel(label);
        analysisFile.setAuthor(user);
        analysisFile.setUpdatedBy(user);
        analysisFile.setExecutable(false);
        analysisFile.setRealName(originalFilename);
        Date created = new Date();
        analysisFile.setCreated(created);
        analysisFile.setUpdated(created);
        analysisFile.setVersion(1);
        beforeSaveAnalysisFile(analysisFile);
        AnalysisFile saved = analysisFileRepository.save(analysisFile);
        analysis.getFiles().add(saved);
        afterSaveAnalysisFile(saved);
        if (Boolean.TRUE.equals(isExecutable)) {
            setIsExecutable(saved.getUuid());
        }
        preprocessorService.preprocessFile(analysis, analysisFile);
        eventPublisher.publishEvent(new AntivirusJobEvent(this, new AntivirusJob(saved.getId(), saved.getRealName(), 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();
        LOGGER.error(message, ex);
        throw new IOException(message);
    }
}
Also used : Path(java.nio.file.Path) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) 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) Date(java.util.Date) FileInputStream(java.io.FileInputStream)

Example 7 with AnalysisFile

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

the class BaseAnalysisServiceImpl method updateFile.

@Override
public void updateFile(String uuid, MultipartFile file, Long analysisId, Boolean isExecutable) throws IOException {
    A analysis = analysisRepository.findOne(analysisId);
    throwAccessDeniedExceptionIfLocked(analysis);
    Study study = analysis.getStudy();
    try {
        AnalysisFile analysisFile = analysisFileRepository.findByUuid(uuid);
        if (file != null) {
            analysisFile.setRealName(file.getOriginalFilename());
            Path analysisFolder = analysisHelper.getAnalysisFolder(analysis);
            if (Files.notExists(analysisFolder)) {
                Files.createDirectories(analysisFolder);
            }
            Path targetPath = analysisFolder.resolve(uuid);
            Files.copy(file.getInputStream(), targetPath, REPLACE_EXISTING);
            String contentType = CommonFileUtils.getContentType(file.getOriginalFilename(), targetPath.toString());
            analysisFile.setContentType(contentType);
        }
        Date updated = new Date();
        analysisFile.setUpdated(updated);
        analysisFile.incrementVersion();
        analysisFile.setExecutable(isExecutable != null && isExecutable);
        analysisFileRepository.save(analysisFile);
    } catch (IOException | RuntimeException ex) {
        String message = "error save file to disk, filename=" + uuid + " ex=" + ex.toString();
        LOGGER.error(message, ex);
        throw new IOException(message);
    }
}
Also used : Path(java.nio.file.Path) Study(com.odysseusinc.arachne.portal.model.Study) IORuntimeException(com.odysseusinc.arachne.portal.exception.IORuntimeException) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) IOException(java.io.IOException) Date(java.util.Date)

Example 8 with AnalysisFile

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

the class BaseAnalysisServiceImpl method getAnalysisAllFiles.

@Override
public void getAnalysisAllFiles(Long analysisId, String archiveName, OutputStream os) throws IOException {
    Analysis analysis = analysisRepository.findOne(analysisId);
    Path storeFilesPath = analysisHelper.getAnalysisFolder(analysis);
    try (ZipOutputStream zos = new ZipOutputStream(os)) {
        for (AnalysisFile analysisFile : analysis.getFiles()) {
            String realName = analysisFile.getRealName();
            Path file = storeFilesPath.resolve(analysisFile.getUuid());
            ZipUtil.addZipEntry(zos, realName, file);
        }
    }
}
Also used : Path(java.nio.file.Path) Analysis(com.odysseusinc.arachne.portal.model.Analysis) ZipOutputStream(java.util.zip.ZipOutputStream) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile)

Example 9 with AnalysisFile

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

the class BaseAnalysisServiceImpl method processAntivirusResponse.

@EventListener
@Transactional
@Override
public void processAntivirusResponse(AntivirusJobAnalysisFileResponseEvent event) {
    final AntivirusJobResponse antivirusJobResponse = event.getAntivirusJobResponse();
    final AnalysisFile analysisFile = analysisFileRepository.findOne(antivirusJobResponse.getFileId());
    if (analysisFile != null) {
        analysisFile.setAntivirusStatus(antivirusJobResponse.getStatus());
        analysisFile.setAntivirusDescription(antivirusJobResponse.getDescription());
        analysisFileRepository.save(analysisFile);
    }
}
Also used : AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) AntivirusJobResponse(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponse) EventListener(org.springframework.context.event.EventListener) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with AnalysisFile

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

the class AnalysisPreprocessorService method preprocessFile.

public void preprocessFile(Analysis analysis, AnalysisFile file) {
    Path analysisFolder = analysisHelper.getAnalysisFolder(analysis);
    File target = analysisFolder.resolve(file.getRealName()).toFile();
    getPreprocessorRegistry().getPreprocessor(file.getContentType()).preprocess(analysis, target);
}
Also used : Path(java.nio.file.Path) File(java.io.File) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) ArachneFile(com.odysseusinc.arachne.portal.model.ArachneFile)

Aggregations

AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)21 Path (java.nio.file.Path)8 ApiOperation (io.swagger.annotations.ApiOperation)6 IOException (java.io.IOException)6 Date (java.util.Date)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Analysis (com.odysseusinc.arachne.portal.model.Analysis)5 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)4 AnalysisFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO)4 IORuntimeException (com.odysseusinc.arachne.portal.exception.IORuntimeException)4 Study (com.odysseusinc.arachne.portal.model.Study)4 IUser (com.odysseusinc.arachne.portal.model.IUser)3 LinkedList (java.util.LinkedList)3 SubmissionFile (com.odysseusinc.arachne.portal.model.SubmissionFile)2 SubmissionGroup (com.odysseusinc.arachne.portal.model.SubmissionGroup)2 ArachnePermission (com.odysseusinc.arachne.portal.security.ArachnePermission)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 List (java.util.List)2