Search in sources :

Example 1 with AnalysisFile

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

the class BaseAnalysisController method uploadFile.

@ApiOperation("Upload file to attach to analysis.")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/upload", method = POST)
public JsonResult<List<AnalysisFileDTO>> uploadFile(Principal principal, @Valid UploadFileDTO uploadFileDTO, @PathVariable("analysisId") Long id) throws PermissionDeniedException, NotExistException, IOException {
    IUser user = getUser(principal);
    T analysis = analysisService.getById(id);
    JsonResult<List<AnalysisFileDTO>> result = new JsonResult<>(NO_ERROR);
    List<AnalysisFileDTO> createdFiles = new ArrayList<>();
    if (uploadFileDTO.getFile() != null) {
        AnalysisFile createdFile = analysisService.saveFile(uploadFileDTO.getFile(), user, analysis, uploadFileDTO.getLabel(), uploadFileDTO.getExecutable(), null);
        createdFiles.add(conversionService.convert(createdFile, AnalysisFileDTO.class));
    } else {
        if (StringUtils.hasText(uploadFileDTO.getLink())) {
            AnalysisFile createdFile = analysisService.saveFile(uploadFileDTO.getLink(), user, analysis, uploadFileDTO.getLabel(), uploadFileDTO.getExecutable());
            createdFiles.add(conversionService.convert(createdFile, AnalysisFileDTO.class));
        } else {
            result.setErrorCode(VALIDATION_ERROR.getCode());
        }
    }
    result.setResult(createdFiles);
    return result;
}
Also used : PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) ArrayList(java.util.ArrayList) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) IUser(com.odysseusinc.arachne.portal.model.IUser) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) AnalysisFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 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 3 with AnalysisFile

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

the class BaseAnalysisController method getFileContent.

@ApiOperation("Get analysis code file.")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/code-files/{fileUuid}", method = GET)
public JsonResult<AnalysisFileDTO> getFileContent(@PathVariable("analysisId") Long analysisId, @RequestParam(defaultValue = "true") Boolean withContent, @PathVariable("fileUuid") String uuid) throws PermissionDeniedException, NotExistException, IOException {
    AnalysisFile analysisFile = analysisService.getAnalysisFile(analysisId, uuid);
    AnalysisFileDTO analysisFileDTO = conversionService.convert(analysisFile, AnalysisFileDTO.class);
    if (withContent) {
        analysisFileDTO = (AnalysisFileDTO) FileDtoContentHandler.getInstance(analysisFileDTO, analysisService.getPath(analysisFile).toFile()).withPdfConverter(toPdfConverter::convert).handle();
    }
    return new JsonResult<>(NO_ERROR, analysisFileDTO);
}
Also used : AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) AnalysisFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with AnalysisFile

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

the class ArachnePermissionEvaluator method addPermissions.

public boolean addPermissions(ArachneUser user, HasArachnePermissions hasPermissionsObj) {
    Set<ArachnePermission> allPermissions = getAllPermissions(hasPermissionsObj, user);
    hasPermissionsObj.setPermissions(allPermissions);
    if (hasPermissionsObj instanceof Analysis) {
        final Analysis analysis = (Analysis) hasPermissionsObj;
        final List<SubmissionGroup> submissionGroups = analysis.getSubmissionGroups();
        if (!CollectionUtils.isEmpty(submissionGroups)) {
            submissionGroups.forEach(submissionGroup -> submissionGroup.getSubmissions().forEach(submission -> {
                final Set<ArachnePermission> submissionPermissions = getAllPermissions(submission, user);
                submission.setPermissions(submissionPermissions);
            }));
        }
        final List<AnalysisFile> files = analysis.getFiles();
        if (!CollectionUtils.isEmpty(files)) {
            files.forEach(file -> {
                final Set<ArachnePermission> filePermissions = getAllPermissions(file, user);
                file.setPermissions(filePermissions);
            });
        }
    } else if (hasPermissionsObj instanceof Study) {
        final Study study = (Study) hasPermissionsObj;
        for (final Analysis analysis : study.getAnalyses()) {
            analysis.setPermissions(getAllPermissions(analysis, user));
        }
    }
    return true;
}
Also used : Arrays(java.util.Arrays) PermissionDslPredicates(com.odysseusinc.arachne.portal.component.PermissionDslPredicates) AnalysisPredicates.analysisAuthorIs(com.odysseusinc.arachne.portal.component.PermissionDslPredicates.AnalysisPredicates.analysisAuthorIs) DomainObjectLoaderFactory(com.odysseusinc.arachne.portal.service.domain.DomainObjectLoaderFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Paper(com.odysseusinc.arachne.portal.model.Paper) IDataSource(com.odysseusinc.arachne.portal.model.IDataSource) BaseArachneSecureService(com.odysseusinc.arachne.portal.service.BaseArachneSecureService) Analysis(com.odysseusinc.arachne.portal.model.Analysis) Map(java.util.Map) DELETE_ANALYSIS_FILES(com.odysseusinc.arachne.portal.security.ArachnePermission.DELETE_ANALYSIS_FILES) User(com.odysseusinc.arachne.portal.model.User) AnalysisFilePredicates.analysisFileAuthorIs(com.odysseusinc.arachne.portal.component.PermissionDslPredicates.AnalysisFilePredicates.analysisFileAuthorIs) PublishState(com.odysseusinc.arachne.portal.model.PublishState) Set(java.util.Set) DELETE_DATASOURCE(com.odysseusinc.arachne.portal.security.ArachnePermission.DELETE_DATASOURCE) RawUser(com.odysseusinc.arachne.portal.model.RawUser) Page(org.springframework.data.domain.Page) IUser(com.odysseusinc.arachne.portal.model.IUser) Serializable(java.io.Serializable) Objects(java.util.Objects) List(java.util.List) RawDataSource(com.odysseusinc.arachne.portal.model.RawDataSource) CollectionUtils(org.springframework.util.CollectionUtils) Authentication(org.springframework.security.core.Authentication) Study(com.odysseusinc.arachne.portal.model.Study) HashMap(java.util.HashMap) PermissionDsl.domainObject(com.odysseusinc.arachne.portal.component.PermissionDsl.domainObject) Organization(com.odysseusinc.arachne.portal.model.Organization) Submission(com.odysseusinc.arachne.portal.model.Submission) HashSet(java.util.HashSet) DataSource(com.odysseusinc.arachne.portal.model.DataSource) ParticipantRole(com.odysseusinc.arachne.portal.model.ParticipantRole) ObjectUtils(org.apache.commons.lang3.ObjectUtils) ArachneUser(com.odysseusinc.arachne.portal.model.security.ArachneUser) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) LinkedList(java.util.LinkedList) HasArachnePermissions(com.odysseusinc.arachne.portal.security.HasArachnePermissions) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) UserStudyGrouped(com.odysseusinc.arachne.portal.model.UserStudyGrouped) PermissionEvaluator(org.springframework.security.access.PermissionEvaluator) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) Component(org.springframework.stereotype.Component) DataNode(com.odysseusinc.arachne.portal.model.DataNode) PermissionDslPredicates.hasRole(com.odysseusinc.arachne.portal.component.PermissionDslPredicates.hasRole) PermissionDslPredicates.instanceOf(com.odysseusinc.arachne.portal.component.PermissionDslPredicates.instanceOf) SubmissionGroup(com.odysseusinc.arachne.portal.model.SubmissionGroup) ArachnePermission(com.odysseusinc.arachne.portal.security.ArachnePermission) Collections(java.util.Collections) Study(com.odysseusinc.arachne.portal.model.Study) Set(java.util.Set) HashSet(java.util.HashSet) SubmissionGroup(com.odysseusinc.arachne.portal.model.SubmissionGroup) Analysis(com.odysseusinc.arachne.portal.model.Analysis) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) ArachnePermission(com.odysseusinc.arachne.portal.security.ArachnePermission)

Example 5 with AnalysisFile

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

the class ArachneFileToFileContentDTOConverter method convert.

@Override
public AnalysisFileDTO convert(ArachneFile source) {
    AnalysisFileDTO fileContentDTO = new AnalysisFileDTO();
    fileContentDTO.setUuid(source.getUuid());
    fileContentDTO.setName(source.getRealName());
    fileContentDTO.setCreated(source.getCreated());
    fileContentDTO.setLabel(source.getLabel());
    if (source instanceof AnalysisFile && ((AnalysisFile) source).getAnalysis() != null) {
        fileContentDTO.setAnalysisId(((AnalysisFile) source).getAnalysis().getId());
    }
    if (source instanceof SubmissionFile) {
        fileContentDTO.setDocType(source.getContentType());
    }
    return fileContentDTO;
}
Also used : AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) AnalysisFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile)

Aggregations

AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)26 Path (java.nio.file.Path)11 IOException (java.io.IOException)9 Date (java.util.Date)8 IORuntimeException (com.odysseusinc.arachne.portal.exception.IORuntimeException)6 Analysis (com.odysseusinc.arachne.portal.model.Analysis)6 ApiOperation (io.swagger.annotations.ApiOperation)6 IUser (com.odysseusinc.arachne.portal.model.IUser)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)4 AnalysisFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO)4 AntivirusJob (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob)4 AntivirusJobEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent)4 FileInputStream (java.io.FileInputStream)4 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)3 ValidationRuntimeException (com.odysseusinc.arachne.portal.exception.ValidationRuntimeException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3