use of com.odysseusinc.arachne.portal.model.ResultFile in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionInsightServiceImpl method createSubmissionInsight.
@Override
@PreAuthorize("hasPermission(#submissionId, 'Submission', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_ANALYSIS)")
public SubmissionInsight createSubmissionInsight(Long submissionId, SubmissionInsight insight) throws AlreadyExistException, NotExistException {
LOGGER.info(CREATING_INSIGHT_LOG, submissionId);
final SubmissionInsight submissionInsight = submissionInsightRepository.findOneBySubmissionId(submissionId);
if (submissionInsight != null) {
final String message = String.format(INSIGHT_ALREADY_EXISTS_EXCEPTION, submissionId);
throw new AlreadyExistException(message);
}
final List<SubmissionStatus> allowedStatuses = Arrays.asList(EXECUTED_PUBLISHED, FAILED_PUBLISHED);
final Submission submission = submissionService.getSubmissionByIdAndStatus(submissionId, allowedStatuses);
throwNotExistExceptionIfNull(submission, submissionId);
insight.setId(null);
insight.setCreated(new Date());
insight.setSubmission(submission);
final SubmissionInsight savedInsight = submissionInsightRepository.save(insight);
final List<SubmissionInsightSubmissionFile> submissionInsightSubmissionFiles = submission.getSubmissionGroup().getFiles().stream().map(sf -> new SubmissionInsightSubmissionFile(savedInsight, sf, new CommentTopic())).collect(Collectors.toList());
submissionInsightSubmissionFileRepository.save(submissionInsightSubmissionFiles);
final List<ResultFile> resultFiles = submission.getResultFiles();
resultFiles.forEach(resultFile -> resultFile.setCommentTopic(new CommentTopic()));
submissionResultFileRepository.save(resultFiles);
return savedInsight;
}
use of com.odysseusinc.arachne.portal.model.ResultFile 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());
}
use of com.odysseusinc.arachne.portal.model.ResultFile in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionServiceImpl method getSubmissionResultAllFiles.
@Override
public void getSubmissionResultAllFiles(IUser user, Long analysisId, Long submissionId, String archiveName, OutputStream os) throws IOException, PermissionDeniedException {
Submission submission = submissionRepository.findOne(submissionId);
checkSubmissionPermission(user, submission);
Path resultFilesPath = Paths.get(contentStorageHelper.getResultFilesDir(submission));
try (ZipOutputStream zos = new ZipOutputStream(os)) {
for (ResultFile resultFile : submission.getResultFiles()) {
Path relativePath = resultFilesPath.relativize(Paths.get(resultFile.getPath()));
ZipUtil.addZipEntry(zos, relativePath.toString(), contentStorageService.getContentByFilepath(resultFile.getPath()));
}
}
}
use of com.odysseusinc.arachne.portal.model.ResultFile 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;
}
use of com.odysseusinc.arachne.portal.model.ResultFile in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionServiceImpl method createResultFile.
@Override
@Transactional
public ResultFile createResultFile(Path filePath, String name, Submission submission, Long createById) throws IOException {
ResultFile resultFile = new ResultFile();
resultFile.setSubmission(submission);
ArachneFileMeta fileMeta = contentStorageService.saveFile(filePath.toFile(), contentStorageHelper.getResultFilesDir(submission, name), createById);
resultFile.setPath(fileMeta.getPath());
return resultFile;
}
Aggregations