Search in sources :

Example 6 with ResultFile

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

the class BaseSubmissionInsightServiceImpl method createSubmissionInsight.

@Override
@PreAuthorize("hasPermission(#submissionId,  'Submission', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_ANALYSIS)")
public SubmissionInsight createSubmissionInsight(Long submissionId, SubmissionInsight insight) throws AlreadyExistException, NotExistException {
    LOGGER.info(CREATING_INSIGHT_LOG, submissionId);
    final SubmissionInsight submissionInsight = submissionInsightRepository.findOneBySubmissionId(submissionId);
    if (submissionInsight != null) {
        final String message = String.format(INSIGHT_ALREADY_EXISTS_EXCEPTION, submissionId);
        throw new AlreadyExistException(message);
    }
    final List<SubmissionStatus> allowedStatuses = Arrays.asList(EXECUTED_PUBLISHED, FAILED_PUBLISHED);
    final Submission submission = submissionService.getSubmissionByIdAndStatus(submissionId, allowedStatuses);
    throwNotExistExceptionIfNull(submission, submissionId);
    insight.setId(null);
    insight.setCreated(new Date());
    insight.setSubmission(submission);
    final SubmissionInsight savedInsight = submissionInsightRepository.save(insight);
    final List<SubmissionInsightSubmissionFile> submissionInsightSubmissionFiles = submission.getSubmissionGroup().getFiles().stream().map(sf -> new SubmissionInsightSubmissionFile(savedInsight, sf, new CommentTopic())).collect(Collectors.toList());
    submissionInsightSubmissionFileRepository.save(submissionInsightSubmissionFiles);
    final List<ResultFile> resultFiles = submission.getResultFiles();
    resultFiles.forEach(resultFile -> resultFile.setCommentTopic(new CommentTopic()));
    submissionResultFileRepository.save(resultFiles);
    return savedInsight;
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) EntityGraphUtils(com.cosium.spring.data.jpa.entity.graph.domain.EntityGraphUtils) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EXECUTED_PUBLISHED(com.odysseusinc.arachne.portal.model.SubmissionStatus.EXECUTED_PUBLISHED) Submission(com.odysseusinc.arachne.portal.model.Submission) FAILED_PUBLISHED(com.odysseusinc.arachne.portal.model.SubmissionStatus.FAILED_PUBLISHED) Map(java.util.Map) BigInteger(java.math.BigInteger) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) LinkedList(java.util.LinkedList) CommentService(com.odysseusinc.arachne.portal.service.CommentService) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) Logger(org.slf4j.Logger) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) SubmissionResultFileRepository(com.odysseusinc.arachne.portal.repository.SubmissionResultFileRepository) Set(java.util.Set) PostAuthorize(org.springframework.security.access.prepost.PostAuthorize) SubmissionInsightSubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionInsightSubmissionFile) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) SubmissionInsightRepository(com.odysseusinc.arachne.portal.repository.SubmissionInsightRepository) SubmissionService(com.odysseusinc.arachne.portal.service.submission.SubmissionService) List(java.util.List) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) EntityUtils(com.odysseusinc.arachne.portal.util.EntityUtils) Stream(java.util.stream.Stream) SubmissionInsightService(com.odysseusinc.arachne.portal.service.submission.SubmissionInsightService) SubmissionInsightSubmissionFileRepository(com.odysseusinc.arachne.portal.repository.SubmissionInsightSubmissionFileRepository) SubmissionStatus(com.odysseusinc.arachne.portal.model.SubmissionStatus) Submission(com.odysseusinc.arachne.portal.model.Submission) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) Date(java.util.Date) SubmissionStatus(com.odysseusinc.arachne.portal.model.SubmissionStatus) SubmissionInsightSubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionInsightSubmissionFile) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with ResultFile

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

the class BaseSubmissionServiceImpl method createResultFilesBatch.

@Override
@Transactional
public List<ResultFile> createResultFilesBatch(List<FileSaveRequest> fileSaveRequests, Submission submission, Long createById) throws IOException {
    fileSaveRequests.forEach(entry -> entry.setDestinationFilepath(contentStorageHelper.getResultFilesDir(submission, entry.getDestinationFilepath())));
    List<ArachneFileMeta> metaList = contentStorageService.saveBatch(fileSaveRequests, createById);
    return metaList.stream().map(fm -> {
        ResultFile resultFile = new ResultFile();
        resultFile.setSubmission(submission);
        resultFile.setPath(fm.getPath());
        return resultFile;
    }).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) FileSaveRequest(com.odysseusinc.arachne.storage.util.FileSaveRequest) FAILED_PUBLISHED(com.odysseusinc.arachne.portal.model.SubmissionStatus.FAILED_PUBLISHED) BaseDataSourceService(com.odysseusinc.arachne.portal.service.BaseDataSourceService) Analysis(com.odysseusinc.arachne.portal.model.Analysis) Map(java.util.Map) Sort(org.springframework.data.domain.Sort) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Path(java.nio.file.Path) SubmissionStatusHistoryElement(com.odysseusinc.arachne.portal.model.SubmissionStatusHistoryElement) SubmissionHelper(com.odysseusinc.arachne.portal.util.SubmissionHelper) EXECUTE(com.odysseusinc.arachne.portal.service.impl.submission.SubmissionActionType.EXECUTE) ArachneMailSender(com.odysseusinc.arachne.portal.service.mail.ArachneMailSender) BaseSubmissionRepository(com.odysseusinc.arachne.portal.repository.submission.BaseSubmissionRepository) Transactional(javax.transaction.Transactional) SubmissionGroupRepository(com.odysseusinc.arachne.portal.repository.SubmissionGroupRepository) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) IUser(com.odysseusinc.arachne.portal.model.IUser) SubmissionInsightRepository(com.odysseusinc.arachne.portal.repository.SubmissionInsightRepository) SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) Stream(java.util.stream.Stream) CollectionUtils(org.springframework.util.CollectionUtils) SubmissionStatus(com.odysseusinc.arachne.portal.model.SubmissionStatus) ZipOutputStream(java.util.zip.ZipOutputStream) PENDING(com.odysseusinc.arachne.portal.model.SubmissionStatus.PENDING) FAILED_REJECTED(com.odysseusinc.arachne.portal.model.SubmissionStatus.FAILED_REJECTED) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) InvitationApprovalSubmissionArachneMailMessage(com.odysseusinc.arachne.portal.service.mail.InvitationApprovalSubmissionArachneMailMessage) ApproveDTO(com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO) ZipUtil(com.odysseusinc.arachne.portal.util.ZipUtil) UserService(com.odysseusinc.arachne.portal.service.UserService) SubmissionFileRepository(com.odysseusinc.arachne.portal.repository.SubmissionFileRepository) Files(java.nio.file.Files) SubmissionGroupSpecification(com.odysseusinc.arachne.portal.model.search.SubmissionGroupSpecification) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) DataNodeUtils(com.odysseusinc.arachne.portal.util.DataNodeUtils) File(java.io.File) ContentStorageHelper(com.odysseusinc.arachne.portal.util.ContentStorageHelper) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) QuerySpec(com.odysseusinc.arachne.storage.model.QuerySpec) Paths(java.nio.file.Paths) FAILED(com.odysseusinc.arachne.portal.model.SubmissionStatus.FAILED) PUBLISH(com.odysseusinc.arachne.portal.service.impl.submission.SubmissionActionType.PUBLISH) DataNodeUtils.isDataNodeOwner(com.odysseusinc.arachne.portal.util.DataNodeUtils.isDataNodeOwner) UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) AnalysisHelper(com.odysseusinc.arachne.portal.util.AnalysisHelper) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) EXECUTED_PUBLISHED(com.odysseusinc.arachne.portal.model.SubmissionStatus.EXECUTED_PUBLISHED) IDataSource(com.odysseusinc.arachne.portal.model.IDataSource) ResultFileSearch(com.odysseusinc.arachne.portal.model.search.ResultFileSearch) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile) SubmissionStatusHistoryRepository(com.odysseusinc.arachne.portal.repository.SubmissionStatusHistoryRepository) BaseSubmissionService(com.odysseusinc.arachne.portal.service.submission.BaseSubmissionService) ContentStorageService(com.odysseusinc.arachne.storage.service.ContentStorageService) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) PostAuthorize(org.springframework.security.access.prepost.PostAuthorize) UUIDGenerator(com.odysseusinc.arachne.portal.util.UUIDGenerator) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) Objects(java.util.Objects) SubmissionSpecification(com.odysseusinc.arachne.portal.model.search.SubmissionSpecification) List(java.util.List) Optional(java.util.Optional) SubmissionActionType(com.odysseusinc.arachne.portal.service.impl.submission.SubmissionActionType) NOT_APPROVED(com.odysseusinc.arachne.portal.model.SubmissionStatus.NOT_APPROVED) EntityGraph(com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph) SubmissionStatus.valueOf(com.odysseusinc.arachne.portal.model.SubmissionStatus.valueOf) DigestUtils(org.springframework.util.DigestUtils) EntityGraphUtils(com.cosium.spring.data.jpa.entity.graph.domain.EntityGraphUtils) LegacyAnalysisHelper(com.odysseusinc.arachne.portal.util.LegacyAnalysisHelper) Submission(com.odysseusinc.arachne.portal.model.Submission) SubmissionGroupSearch(com.odysseusinc.arachne.portal.model.search.SubmissionGroupSearch) ResultFileRepository(com.odysseusinc.arachne.portal.repository.ResultFileRepository) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) EXECUTED_REJECTED(com.odysseusinc.arachne.portal.model.SubmissionStatus.EXECUTED_REJECTED) NoExecutableFileException(com.odysseusinc.arachne.portal.exception.NoExecutableFileException) ObjectUtils(org.apache.commons.lang3.ObjectUtils) EXECUTED(com.odysseusinc.arachne.portal.model.SubmissionStatus.EXECUTED) UserDetails(org.springframework.security.core.userdetails.UserDetails) LinkedList(java.util.LinkedList) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) SubmissionResultFileRepository(com.odysseusinc.arachne.portal.repository.SubmissionResultFileRepository) SequenceInputStream(java.io.SequenceInputStream) SubmissionAction(com.odysseusinc.arachne.portal.service.impl.submission.SubmissionAction) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) WebSecurityConfig(com.odysseusinc.arachne.portal.config.WebSecurityConfig) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) EntityUtils(com.odysseusinc.arachne.portal.util.EntityUtils) MultipartFile(org.springframework.web.multipart.MultipartFile) IN_PROGRESS(com.odysseusinc.arachne.portal.model.SubmissionStatus.IN_PROGRESS) SubmissionGroup(com.odysseusinc.arachne.portal.model.SubmissionGroup) Collections(java.util.Collections) InputStream(java.io.InputStream) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) Transactional(javax.transaction.Transactional)

Example 8 with ResultFile

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

the class BaseSubmissionServiceImpl method getSubmissionResultAllFiles.

@Override
public void getSubmissionResultAllFiles(IUser user, Long analysisId, Long submissionId, String archiveName, OutputStream os) throws IOException, PermissionDeniedException {
    Submission submission = submissionRepository.findOne(submissionId);
    checkSubmissionPermission(user, submission);
    Path resultFilesPath = Paths.get(contentStorageHelper.getResultFilesDir(submission));
    try (ZipOutputStream zos = new ZipOutputStream(os)) {
        for (ResultFile resultFile : submission.getResultFiles()) {
            Path relativePath = resultFilesPath.relativize(Paths.get(resultFile.getPath()));
            ZipUtil.addZipEntry(zos, relativePath.toString(), contentStorageService.getContentByFilepath(resultFile.getPath()));
        }
    }
}
Also used : Path(java.nio.file.Path) Submission(com.odysseusinc.arachne.portal.model.Submission) ZipOutputStream(java.util.zip.ZipOutputStream) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile)

Example 9 with ResultFile

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

the class BaseSubmissionServiceImpl method deleteSubmissionResultFile.

@Override
public boolean deleteSubmissionResultFile(Long submissionId, ResultFile resultFile) throws NotExistException, ValidationException {
    final T submission = submissionRepository.findByIdAndStatusIn(submissionId, Collections.singletonList(IN_PROGRESS.name()));
    throwNotExistExceptionIfNull(submission, submissionId);
    Optional.ofNullable(resultFile).orElseThrow(() -> new NotExistException(String.format(RESULT_FILE_NOT_EXISTS_EXCEPTION, resultFile.getId(), submission.getId()), ResultFile.class));
    ArachneFileMeta fileMeta = contentStorageService.getFileByPath(resultFile.getPath());
    if (fileMeta.getCreatedBy() == null) {
        // not manually uploaded
        throw new ValidationException(String.format(FILE_NOT_UPLOADED_MANUALLY_EXCEPTION, resultFile.getId()));
    }
    deleteSubmissionResultFile(resultFile);
    submission.getResultFiles().remove(resultFile);
    submission.setUpdated(new Date());
    saveSubmission(submission);
    return true;
}
Also used : ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) Date(java.util.Date)

Example 10 with ResultFile

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

the class BaseSubmissionServiceImpl method createResultFile.

@Override
@Transactional
public ResultFile createResultFile(Path filePath, String name, Submission submission, Long createById) throws IOException {
    ResultFile resultFile = new ResultFile();
    resultFile.setSubmission(submission);
    ArachneFileMeta fileMeta = contentStorageService.saveFile(filePath.toFile(), contentStorageHelper.getResultFilesDir(submission, name), createById);
    resultFile.setPath(fileMeta.getPath());
    return resultFile;
}
Also used : ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) Transactional(javax.transaction.Transactional)

Aggregations

ResultFile (com.odysseusinc.arachne.portal.model.ResultFile)10 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)5 Submission (com.odysseusinc.arachne.portal.model.Submission)5 Date (java.util.Date)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 EntityGraphUtils (com.cosium.spring.data.jpa.entity.graph.domain.EntityGraphUtils)3 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)3 SubmissionInsight (com.odysseusinc.arachne.portal.model.SubmissionInsight)3 SubmissionInsightSubmissionFile (com.odysseusinc.arachne.portal.model.SubmissionInsightSubmissionFile)3 SubmissionStatus (com.odysseusinc.arachne.portal.model.SubmissionStatus)3 EXECUTED_PUBLISHED (com.odysseusinc.arachne.portal.model.SubmissionStatus.EXECUTED_PUBLISHED)3 FAILED_PUBLISHED (com.odysseusinc.arachne.portal.model.SubmissionStatus.FAILED_PUBLISHED)3 SubmissionInsightRepository (com.odysseusinc.arachne.portal.repository.SubmissionInsightRepository)3 SubmissionResultFileRepository (com.odysseusinc.arachne.portal.repository.SubmissionResultFileRepository)3 EntityUtils (com.odysseusinc.arachne.portal.util.EntityUtils)3 ArachneFileMeta (com.odysseusinc.arachne.storage.model.ArachneFileMeta)3 Arrays (java.util.Arrays)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Map (java.util.Map)3