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());
}
}
}
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);
}
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;
}
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;
}
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");
}
}
Aggregations