Search in sources :

Example 6 with SubmissionFile

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

the class BaseSubmissionServiceImpl method createSubmissionGroup.

@Override
public SubmissionGroup createSubmissionGroup(IUser user, Analysis analysis) throws IOException, NoExecutableFileException {
    checkBeforeCreateSubmissionGroup(analysis);
    List<SubmissionFile> files = new LinkedList<>();
    SubmissionGroup submissionGroup = new SubmissionGroup();
    submissionGroup.setAnalysis(analysis);
    submissionGroup.setAnalysisType(analysis.getType());
    submissionGroup.setAuthor(user);
    Date now = new Date();
    submissionGroup.setCreated(now);
    submissionGroup.setUpdated(now);
    submissionGroup.setFiles(files);
    submissionGroup = submissionGroupRepository.save(submissionGroup);
    Path submissionGroupFolder = analysisHelper.getSubmissionGroupFolder(submissionGroup);
    if (Files.notExists(submissionGroupFolder)) {
        Files.createDirectories(submissionGroupFolder);
    }
    for (AnalysisFile analysisFile : analysis.getFiles()) {
        SubmissionFile submissionFile = new SubmissionFile();
        String storeFilesPath = fileStorePath + File.separator + "content";
        String uuid = UUID.randomUUID().toString();
        submissionFile.setSubmissionGroup(submissionGroup);
        submissionFile.setContentType(analysisFile.getContentType());
        submissionFile.setCreated(analysisFile.getCreated());
        submissionFile.setUpdated(analysisFile.getUpdated());
        submissionFile.setLabel(analysisFile.getLabel());
        submissionFile.setRealName(analysisFile.getRealName());
        submissionFile.setEntryPoint(analysisFile.getEntryPoint());
        submissionFile.setUuid(uuid);
        submissionFile.setAuthor(analysisFile.getAuthor());
        submissionFile.setVersion(analysisFile.getVersion());
        submissionFile.setAntivirusStatus(analysisFile.getAntivirusStatus());
        submissionFile.setAntivirusDescription(analysisFile.getAntivirusDescription());
        Boolean isExecutable = analysisFile.getExecutable();
        submissionFile.setExecutable(isExecutable != null && isExecutable);
        Path analysisFileContent = Paths.get(storeFilesPath, analysis.getStudy().getId().toString(), analysis.getId().toString(), analysisFile.getUuid());
        Path submissionFileContent = submissionGroupFolder.resolve(uuid);
        Path target = Files.copy(analysisFileContent, submissionFileContent, StandardCopyOption.REPLACE_EXISTING);
        try (InputStream in = Files.newInputStream(target)) {
            String checksum = DigestUtils.md5DigestAsHex(in);
            submissionFile.setChecksum(checksum);
        }
        files.add(submissionFile);
    }
    submissionFileRepository.save(files);
    submissionGroup.setChecksum(calculateMD5Hash(submissionGroupFolder, files));
    submissionGroupRepository.save(submissionGroup);
    return submissionGroup;
}
Also used : Path(java.nio.file.Path) SubmissionGroup(com.odysseusinc.arachne.portal.model.SubmissionGroup) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) LinkedList(java.util.LinkedList) Date(java.util.Date) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile)

Example 7 with SubmissionFile

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

the class BaseSubmissionServiceImpl method getSubmissionAllFiles.

@Override
public void getSubmissionAllFiles(Long submissionGroupId, String archiveName, OutputStream os) throws IOException {
    SubmissionGroup submissionGroup = submissionGroupRepository.findOne(submissionGroupId);
    Path storeFilesPath = analysisHelper.getSubmissionGroupFolder(submissionGroup);
    try (ZipOutputStream zos = new ZipOutputStream(os)) {
        for (SubmissionFile submissionFile : submissionGroup.getFiles()) {
            String realName = submissionFile.getRealName();
            Path file = storeFilesPath.resolve(submissionFile.getUuid());
            if (Files.notExists(file)) {
                file = legacyAnalysisHelper.getOldSubmissionFile(submissionFile).orElseThrow(FileNotFoundException::new);
            }
            if (Files.exists(file)) {
                ZipUtil.addZipEntry(zos, realName, file);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) SubmissionGroup(com.odysseusinc.arachne.portal.model.SubmissionGroup) ZipOutputStream(java.util.zip.ZipOutputStream) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile)

Aggregations

SubmissionFile (com.odysseusinc.arachne.portal.model.SubmissionFile)7 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)2 SubmissionGroup (com.odysseusinc.arachne.portal.model.SubmissionGroup)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Path (java.nio.file.Path)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 CommonAnalysisDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisDTO)1 CommonAnalysisFileDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisFileDTO)1 CommonArachneUserDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonArachneUserDTO)1 CommonStudyDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonStudyDTO)1 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)1 AnalysisFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO)1 CommentableSubmissionFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.CommentableSubmissionFileDTO)1 SubmissionFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO)1 UserInfoDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserInfoDTO)1 Analysis (com.odysseusinc.arachne.portal.model.Analysis)1 IUser (com.odysseusinc.arachne.portal.model.IUser)1 Study (com.odysseusinc.arachne.portal.model.Study)1 SubmissionInsightSubmissionFile (com.odysseusinc.arachne.portal.model.SubmissionInsightSubmissionFile)1 InputStream (java.io.InputStream)1