Search in sources :

Example 16 with AnalysisFile

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

the class BaseAnalysisController method updateCommonEntityInAnalysis.

@ApiOperation("update common entity in analysis")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/entities/{fileUuid}", method = PUT)
public JsonResult updateCommonEntityInAnalysis(@PathVariable("analysisId") Long analysisId, @PathVariable("fileUuid") String fileUuid, @RequestParam(value = "type", required = false, defaultValue = "COHORT") CommonAnalysisType analysisType, Principal principal) throws IOException, JMSException, PermissionDeniedException, URISyntaxException {
    final IUser user = getUser(principal);
    final AnalysisFile analysisFile = analysisService.getAnalysisFile(analysisId, fileUuid);
    T analysis = (T) analysisFile.getAnalysis();
    final DataReference dataReference = analysisFile.getDataReference();
    final DataReferenceDTO entityReference = new DataReferenceDTO(dataReference.getDataNode().getId(), dataReference.getGuid());
    final List<MultipartFile> entityFiles = getEntityFiles(entityReference, dataReference.getDataNode(), analysisType);
    analysisService.findAnalysisFilesByDataReference(analysis, dataReference).forEach(af -> {
        analysisService.deleteAnalysisFile(analysis, af);
        analysis.getFiles().remove(af);
    });
    doAddCommonEntityToAnalysis(analysis, dataReference, user, analysisType, entityFiles);
    return new JsonResult(NO_ERROR);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) DataReferenceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataReferenceDTO) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) IUser(com.odysseusinc.arachne.portal.model.IUser) DataReference(com.odysseusinc.arachne.portal.model.DataReference) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with AnalysisFile

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

the class BaseAnalysisController method getFile.

@ApiOperation("Get code file of the submission.")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/code-files/{fileUuid}/download", method = GET)
public void getFile(@PathVariable("analysisId") Long analysisId, @PathVariable("fileUuid") String uuid, HttpServletResponse response) throws PermissionDeniedException, NotExistException, IOException {
    try {
        AnalysisFile analysisFile = analysisService.getAnalysisFile(analysisId, uuid);
        putFileContentToResponse(response, analysisFile.getContentType(), StringUtils.getFilename(analysisFile.getRealName()), analysisService.getAnalysisFile(analysisFile));
    } catch (IOException ex) {
        LOGGER.info("Error writing file to output stream. Filename was '{}'", uuid, ex);
        throw new IOException("Error writing file to output stream. Filename was " + uuid, ex);
    }
}
Also used : AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) RuntimeIOException(org.assertj.core.api.exception.RuntimeIOException) IOException(java.io.IOException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with AnalysisFile

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

the class BaseAnalysisController method putFileContent.

@ApiOperation("Write content of the code file.")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/code-files/{fileUuid}", method = PUT)
public JsonResult<Boolean> putFileContent(Principal principal, @RequestBody FileDTO fileContentDTO, @PathVariable("analysisId") Long analysisId, @PathVariable("fileUuid") String uuid) throws PermissionDeniedException, NotExistException, IOException, URISyntaxException {
    final IUser user = getUser(principal);
    AnalysisFile analysisFile = analysisService.getAnalysisFile(analysisId, uuid);
    analysisService.writeToFile(analysisFile, fileContentDTO, user);
    JsonResult<Boolean> result = new JsonResult<>(NO_ERROR);
    result.setResult(Boolean.TRUE);
    return result;
}
Also used : AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) IUser(com.odysseusinc.arachne.portal.model.IUser) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with AnalysisFile

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

the class EstimationPreprocessor method attachRunner.

private void attachRunner(Analysis analysis, File file) {
    try {
        String runnerContent = template.apply(prepareParameters(analysis, file));
        final MultipartFile analysisFile = new MockMultipartFile(ANALYSIS_RUNNER_FILENAME, ANALYSIS_RUNNER_FILENAME, "text/x-r-source", runnerContent.getBytes());
        AnalysisFile createdFile = analysisService.saveFile(analysisFile, analysis.getAuthor(), analysis, ANALYSIS_RUNNER_FILENAME, true, null);
        String fileUuid = createdFile.getUuid();
        // Set via service function to unselect all other files
        analysisService.setIsExecutable(fileUuid);
    } catch (IOException e) {
        LOGGER.error("Failed to generate estimation R execution", e);
        throw new UncheckedIOException(e);
    }
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 20 with AnalysisFile

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

Aggregations

AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)21 Path (java.nio.file.Path)8 ApiOperation (io.swagger.annotations.ApiOperation)6 IOException (java.io.IOException)6 Date (java.util.Date)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Analysis (com.odysseusinc.arachne.portal.model.Analysis)5 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)4 AnalysisFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO)4 IORuntimeException (com.odysseusinc.arachne.portal.exception.IORuntimeException)4 Study (com.odysseusinc.arachne.portal.model.Study)4 IUser (com.odysseusinc.arachne.portal.model.IUser)3 LinkedList (java.util.LinkedList)3 SubmissionFile (com.odysseusinc.arachne.portal.model.SubmissionFile)2 SubmissionGroup (com.odysseusinc.arachne.portal.model.SubmissionGroup)2 ArachnePermission (com.odysseusinc.arachne.portal.security.ArachnePermission)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 List (java.util.List)2