Search in sources :

Example 1 with ArachneFileMeta

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

the class V20171219232521__ResultFilesToJcr method migrate.

@Override
public void migrate() throws Exception {
    String queryNotMigratedFilesSql = "SELECT rf.id, \n" + "rf.legacy_uuid, \n" + "rf.submission_id, \n" + "rf.legacy_real_name, \n" + "rf.legacy_manual_upload, \n" + "'" + legacyFilesDir + "' || '/content/' || s.id || '/' || a.id || '/sg_' || sg.id || '/' || sm.id || '/result/' || rf.legacy_uuid AS legacy_path \n" + "FROM result_files rf \n" + "   JOIN submissions sm ON sm.id = rf.submission_id \n" + "   JOIN submission_groups sg ON sg.id = sm.submission_group_id \n" + "   JOIN analyses a ON a.id = sg.analysis_id \n" + "   JOIN studies s ON s.id = a.study_id \n" + "WHERE rf.legacy_real_name IS NOT NULL \n" + "AND rf.path IS NULL";
    List<LegacyResultFile> resultList = new ArrayList<>();
    jdbcTemplate.query(queryNotMigratedFilesSql, rs -> {
        LegacyResultFile lrf = new LegacyResultFile();
        lrf.setId(rs.getLong("id"));
        lrf.setUuid(rs.getString("legacy_uuid"));
        lrf.setSubmissionId(rs.getLong("submission_id"));
        lrf.setRelativeFilename(rs.getString("legacy_real_name"));
        lrf.setManualUpload(rs.getBoolean("legacy_manual_upload"));
        lrf.setLegacyPath(rs.getString("legacy_path"));
        resultList.add(lrf);
    });
    for (LegacyResultFile lrf : resultList) {
        File file = new File(lrf.getLegacyPath());
        if (file.exists()) {
            String targetPath = getResultFilesDir(lrf.getSubmissionId(), lrf.getRelativeFilename().replace('\\', '/'));
            ArachneFileMeta meta = migrateFile(targetPath, file, lrf.getManualUpload() ? 1L : null);
            updateResultFile(lrf, meta);
        } else {
            LOGGER.error("File not found: " + file.getAbsolutePath());
        }
    }
}
Also used : ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) ArrayList(java.util.ArrayList) File(java.io.File)

Example 2 with ArachneFileMeta

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

the class BaseSubmissionController method getResultZipEntry.

@ApiOperation("Get single entry from zip file of the submission.")
@GetMapping("/api/v1/analysis-management/submissions/{submissionId}/results/zip-entry")
public JsonResult<ResultFileDTO> getResultZipEntry(Principal principal, @PathVariable("submissionId") Long submissionId, @RequestParam(value = "path") String path, @RequestParam(value = "entry-name") String entryName) throws PermissionDeniedException {
    IUser user = userService.getByUsername(principal.getName());
    if (StringUtils.isNoneBlank(entryName)) {
        ResultFileSearch resultFileSearch = new ResultFileSearch();
        String filePath = FilenameUtils.getPath(path);
        String fileName = FilenameUtils.getName(path);
        resultFileSearch.setRealName(fileName);
        resultFileSearch.setPath(filePath);
        List<? extends ArachneFileMeta> resultFileList = submissionService.getResultFiles(user, submissionId, resultFileSearch);
        if (!resultFileList.isEmpty()) {
            ArachneFileMeta zipMetaFile = resultFileList.get(0);
            try (ZipInputStream zin = new ZipInputStream(contentStorageService.getContentByFilepath(zipMetaFile.getPath()))) {
                byte[] content = ZipUtil.extractZipEntry(zin, entryName);
                if (ArrayUtils.isEmpty(content)) {
                    LOGGER.info("Cannot find zip entry in the submissionId: {}, path: {}, entry", submissionId, path, entryName);
                }
                ResultFileDTO resultFileDTO = new ResultFileDTO(conversionService.convert(zipMetaFile, FileDTO.class));
                String jsonBody = IOUtils.toString(content, StandardCharsets.UTF_8.name());
                resultFileDTO.setContent(jsonBody);
                resultFileDTO.setName(entryName);
                resultFileDTO.setSubmissionId(submissionId);
                resultFileDTO.setRelativePath(path);
                return new JsonResult<>(NO_ERROR, resultFileDTO);
            } catch (IOException e) {
                LOGGER.error("Cannot read zipFile: {}", zipMetaFile.getPath());
            }
        }
    }
    return new JsonResult<>(NO_ERROR);
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ResultFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.ResultFileDTO) ResultFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.ResultFileDTO) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) SubmissionFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) IUser(com.odysseusinc.arachne.portal.model.IUser) ResultFileSearch(com.odysseusinc.arachne.portal.model.search.ResultFileSearch) IOException(java.io.IOException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with ArachneFileMeta

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

the class BaseSubmissionServiceImpl method createResultFile.

@Override
@Transactional
public ResultFile createResultFile(File localFile, String fileName, Submission submission, Long createById) {
    String filesDir = contentStorageHelper.getResultFilesDir(submission, fileName);
    ArachneFileMeta fileMeta = contentStorageService.saveFile(localFile, filesDir, createById);
    ResultFile resultFile = new ResultFile();
    resultFile.setSubmission(submission);
    resultFile.setPath(fileMeta.getPath());
    return resultFile;
}
Also used : ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ArachneFileMeta

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

the class ResultFileToCommentableResultFileDTOConverter method convert.

@Override
public CommentableResultFileDTO convert(ResultFile source) {
    final CommentableResultFileDTO dto = new CommentableResultFileDTO();
    ArachneFileMeta arachneFileMeta = contentStorageService.getFileByPath(source.getPath());
    dto.setName(arachneFileMeta.getName());
    dto.setCreated(arachneFileMeta.getCreated());
    dto.setSubmissionId(source.getSubmission().getId());
    dto.setCommentTopicId(source.getCommentTopic().getId());
    dto.setCommentCount(source.getCommentTopic().getCount());
    dto.setDocType(arachneFileMeta.getContentType());
    dto.setFileId(source.getId());
    dto.setUuid(arachneFileMeta.getUuid());
    return dto;
}
Also used : CommentableResultFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.CommentableResultFileDTO) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta)

Example 5 with ArachneFileMeta

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

the class AnalysisSubmissionControllerTests method testDeleteSubmissionResult.

// @Test
// @WithUserDetails(DATA_NODE_ONWER)
// @DatabaseSetups({
// @DatabaseSetup("/data/analysis/submission/submission-published-with-added-files.xml"),
// })
// @ExpectedDatabases({
// @ExpectedDatabase(value = "/data/analysis/submission/submission-published-with-added-files.xml", assertionMode = NON_STRICT),
// 
// })
// public void testGetUploadingSubmissionResult() throws Exception {
// 
// prepareResultFile(1L);
// }
@Test
@WithUserDetails(DATA_NODE_ONWER)
@DatabaseSetups({ @DatabaseSetup("/data/analysis/submission/submission-in-progress.xml"), @DatabaseSetup("/data/analysis/submission/result-file.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/analysis/submission/submission-in-progress.xml", assertionMode = NON_STRICT), @ExpectedDatabase(value = "/data/analysis/submission/result/empty-result-file.xml", assertionMode = NON_STRICT) })
public void testDeleteSubmissionResult() throws Exception {
    Long submissionId = 1L;
    ArachneFileMeta fileMeta = prepareResultFile(1L);
    String fileUuid = fileMeta.getUuid();
    mvc.perform(delete("/api/v1/analysis-management/submissions/{submissionId}/result/{fileUuid}", submissionId, fileUuid)).andExpect(NO_ERROR_CODE);
    if (checkFileExists(getResultFilePath(submissionId))) {
        throw new Exception("JCR file was not deleted");
    }
}
Also used : ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) IOException(java.io.IOException) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases)

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