Search in sources :

Example 11 with ArachneFileMeta

use of com.odysseusinc.arachne.storage.model.ArachneFileMeta in project ArachneCentralAPI by OHDSI.

the class BaseSubmissionServiceImpl method storeExtractedFiles.

private void storeExtractedFiles(Submission submission, Path unzipDir, long uploadedBy) {
    List<ResultFile> resultFiles = new ArrayList<>();
    for (File extractedFile : CommonFileUtils.getFiles(unzipDir.toFile())) {
        String relativeFilepath = unzipDir.relativize(extractedFile.toPath()).toString().replace('\\', '/');
        String destinationPath = contentStorageHelper.getResultFilesDir(submission, relativeFilepath);
        ArachneFileMeta arachneFileMeta = contentStorageService.saveFile(extractedFile, destinationPath, uploadedBy);
        ResultFile resultFile = new ResultFile();
        resultFile.setSubmission(submission);
        resultFile.setPath(arachneFileMeta.getPath());
        resultFiles.add(resultFile);
    }
    submissionResultFileRepository.saveAll(resultFiles);
}
Also used : ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) ArrayList(java.util.ArrayList) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) File(java.io.File) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile) ZipFile(net.lingala.zip4j.ZipFile) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 12 with ArachneFileMeta

use of com.odysseusinc.arachne.storage.model.ArachneFileMeta 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) Triple(org.apache.commons.lang3.tuple.Triple) 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) SubmissionGroupRepository(com.odysseusinc.arachne.portal.repository.SubmissionGroupRepository) PageRequest(org.springframework.data.domain.PageRequest) Set(java.util.Set) 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) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) 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) FileHeader(net.lingala.zip4j.model.FileHeader) SubmissionFileRepository(com.odysseusinc.arachne.portal.repository.SubmissionFileRepository) Files(java.nio.file.Files) SubmissionGroupSpecification(com.odysseusinc.arachne.portal.model.search.SubmissionGroupSpecification) FileUtils(org.apache.commons.io.FileUtils) 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) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) Objects(java.util.Objects) CommonFileUtils(com.odysseusinc.arachne.commons.utils.CommonFileUtils) SubmissionSpecification(com.odysseusinc.arachne.portal.model.search.SubmissionSpecification) List(java.util.List) ZipFile(net.lingala.zip4j.ZipFile) Optional(java.util.Optional) SubmissionActionType(com.odysseusinc.arachne.portal.service.impl.submission.SubmissionActionType) Queue(java.util.Queue) FilenameUtils(org.apache.commons.io.FilenameUtils) NOT_APPROVED(com.odysseusinc.arachne.portal.model.SubmissionStatus.NOT_APPROVED) EntityGraph(com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph) DigestUtils(org.springframework.util.DigestUtils) 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) HashSet(java.util.HashSet) NoExecutableFileException(com.odysseusinc.arachne.portal.exception.NoExecutableFileException) EXECUTED(com.odysseusinc.arachne.portal.model.SubmissionStatus.EXECUTED) UserDetails(org.springframework.security.core.userdetails.UserDetails) LinkedList(java.util.LinkedList) UUIDGenerator(com.odysseusinc.arachne.commons.utils.UUIDGenerator) 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) Transactional(org.springframework.transaction.annotation.Transactional) InputStream(java.io.InputStream) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with ArachneFileMeta

use of com.odysseusinc.arachne.storage.model.ArachneFileMeta in project ArachneCentralAPI by OHDSI.

the class BaseSubmissionServiceImpl method getResultFileAndCheckPermission.

@Override
public ArachneFileMeta getResultFileAndCheckPermission(IUser user, Submission submission, Long analysisId, String fileUuid) throws PermissionDeniedException {
    ArachneFileMeta byFileUuid = contentStorageService.getFileByIdentifier(fileUuid);
    checkSubmissionPermission(user, submission);
    return byFileUuid;
}
Also used : ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta)

Example 14 with ArachneFileMeta

use of com.odysseusinc.arachne.storage.model.ArachneFileMeta 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)

Aggregations

ArachneFileMeta (com.odysseusinc.arachne.storage.model.ArachneFileMeta)14 ResultFile (com.odysseusinc.arachne.portal.model.ResultFile)6 ApiOperation (io.swagger.annotations.ApiOperation)4 File (java.io.File)4 IOException (java.io.IOException)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)3 FileDTO (com.odysseusinc.arachne.portal.api.v1.dto.FileDTO)3 ResultFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.ResultFileDTO)3 SubmissionFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO)3 UploadFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO)3 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)3 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)3 IUser (com.odysseusinc.arachne.portal.model.IUser)3 SubmissionFile (com.odysseusinc.arachne.portal.model.SubmissionFile)3 ResultFileSearch (com.odysseusinc.arachne.portal.model.search.ResultFileSearch)3 ArrayList (java.util.ArrayList)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)2 NoExecutableFileException (com.odysseusinc.arachne.portal.exception.NoExecutableFileException)2