Search in sources :

Example 6 with Analysis

use of com.odysseusinc.arachne.portal.model.Analysis 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 7 with Analysis

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

the class BaseArachneSecureServiceImpl method getRolesByAnalysis.

@Override
public List<ParticipantRole> getRolesByAnalysis(ArachneUser user, Analysis analysis) {
    List<ParticipantRole> result = new LinkedList<>();
    if (analysis != null) {
        if (analysis.getStudy() != null) {
            result = getRolesByStudy(user, analysis.getStudy());
        } else {
            Analysis byId = analysisRepository.findOne(analysis.getId());
            result = byId != null ? getRolesByStudy(user, byId.getStudy()) : result;
        }
        if (analysis.getAuthor().getId().equals(user.getId())) {
            result.add(ParticipantRole.ANALYSIS_OWNER);
        }
    }
    return result;
}
Also used : Analysis(com.odysseusinc.arachne.portal.model.Analysis) LinkedList(java.util.LinkedList) ParticipantRole(com.odysseusinc.arachne.portal.model.ParticipantRole)

Example 8 with Analysis

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

the class BaseArachneSecureServiceImpl method getRolesBySubmissionGroup.

@Override
public List<ParticipantRole> getRolesBySubmissionGroup(ArachneUser user, SubmissionGroup submissionGroup) {
    List<ParticipantRole> result = new LinkedList<>();
    Optional.ofNullable(submissionGroup).ifPresent(sg -> {
        Analysis analysis = submissionGroup.getAnalysis();
        if (analysis != null && analysis.getStudy() != null) {
            result.addAll(getRolesByStudy(user, analysis.getStudy()));
        }
    });
    return result;
}
Also used : Analysis(com.odysseusinc.arachne.portal.model.Analysis) LinkedList(java.util.LinkedList) ParticipantRole(com.odysseusinc.arachne.portal.model.ParticipantRole)

Example 9 with Analysis

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

the class BaseAnalysisServiceImpl method writeToFile.

@Override
@PreAuthorize("hasPermission(#analysisFile, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).DELETE_ANALYSIS_FILES)")
public void writeToFile(AnalysisFile analysisFile, FileDTO fileContentDTO, IUser updatedBy) throws IOException {
    Analysis analysis = analysisFile.getAnalysis();
    throwAccessDeniedExceptionIfLocked(analysis);
    Study study = analysis.getStudy();
    try {
        Path analysisFolder = analysisHelper.getAnalysisFolder(analysis);
        if (Files.notExists(analysisFolder)) {
            Files.createDirectories(analysisFolder);
        }
        Path targetPath = analysisFolder.resolve(analysisFile.getUuid());
        byte[] content = fileContentDTO.getContent().getBytes(StandardCharsets.UTF_8);
        try (final InputStream stream = new ByteArrayInputStream(content)) {
            Files.copy(stream, targetPath, REPLACE_EXISTING);
        }
        analysisFile.setUpdated(new Date());
        analysisFile.setEntryPoint(analysisFile.getEntryPoint());
        analysisFile.setUpdatedBy(updatedBy);
        analysisFile.setContentType(CommonFileUtils.getContentType(analysisFile.getRealName(), targetPath.toString()));
        analysisFile.incrementVersion();
        analysisFile.setAntivirusStatus(AntivirusStatus.SCANNING);
        analysisFile.setAntivirusDescription(null);
        final AnalysisFile saved = analysisFileRepository.save(analysisFile);
        eventPublisher.publishEvent(new AntivirusJobEvent(this, new AntivirusJob(saved.getId(), saved.getRealName(), new FileInputStream(targetPath.toString()), AntivirusJobFileType.ANALYSIS_FILE)));
    } catch (IOException | RuntimeException ex) {
        String message = "error save file to disk, filename=" + analysisFile.getUuid() + " 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) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) IOException(java.io.IOException) Date(java.util.Date) FileInputStream(java.io.FileInputStream) IORuntimeException(com.odysseusinc.arachne.portal.exception.IORuntimeException) ByteArrayInputStream(java.io.ByteArrayInputStream) Analysis(com.odysseusinc.arachne.portal.model.Analysis) AntivirusJobEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 10 with Analysis

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

the class BaseAnalysisServiceImpl method moveAnalysis.

@Override
public Boolean moveAnalysis(Long id, Integer index) {
    A analysis = analysisRepository.findOne(id);
    Study study = analysis.getStudy();
    List<A> list = list(study);
    list.remove(analysis);
    list.add(index, analysis);
    int ind = 0;
    for (Analysis an : list) {
        an.setOrd(ind++);
    }
    return true;
}
Also used : Study(com.odysseusinc.arachne.portal.model.Study) Analysis(com.odysseusinc.arachne.portal.model.Analysis)

Aggregations

Analysis (com.odysseusinc.arachne.portal.model.Analysis)20 LinkedList (java.util.LinkedList)9 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)8 IUser (com.odysseusinc.arachne.portal.model.IUser)8 Study (com.odysseusinc.arachne.portal.model.Study)7 Submission (com.odysseusinc.arachne.portal.model.Submission)7 Date (java.util.Date)7 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)6 Path (java.nio.file.Path)6 List (java.util.List)6 IOException (java.io.IOException)5 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)4 NO_ERROR (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR)4 FileDTO (com.odysseusinc.arachne.portal.api.v1.dto.FileDTO)4 UploadFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO)4 FileDtoContentHandler (com.odysseusinc.arachne.portal.api.v1.dto.converters.FileDtoContentHandler)4 PermissionDeniedException (com.odysseusinc.arachne.portal.exception.PermissionDeniedException)4 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)4 BaseSubmissionService (com.odysseusinc.arachne.portal.service.submission.BaseSubmissionService)4 InputStream (java.io.InputStream)4