use of com.odysseusinc.arachne.portal.exception.NotExistException 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.exception.NotExistException 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.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseAchillesController method getFile.
@ApiOperation("Get file contents")
@RequestMapping(value = { "datasource/{id}/files/{filename:.*}", "datasource/{id}/files/{filepath:.*}/{filename:.*}" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public JsonResult<JsonNode> getFile(@PathVariable("id") Long datasourceId, @RequestParam(name = "char", required = false) Long characterizationId, @PathVariable(value = "filepath", required = false) String path, @PathVariable("filename") String filename) throws NotExistException, IOException {
final String filepath = StringUtils.isBlank(path) ? filename : path + File.separator + filename;
DS dataSource = checkDataSource(datasourceId);
if (characterizationId == null) {
characterizationId = achillesService.getLatestCharacterizationId(dataSource);
}
AchillesFile file = achillesService.getAchillesFile(characterizationId, filepath).orElseThrow(() -> new NotExistException(String.format("File %s not found", filepath), AchillesFile.class));
JsonObject jsonObject = file.getData();
JsonNode node = objectMapper.readTree(new Gson().toJson(jsonObject));
return new JsonResult<>(NO_ERROR, node);
}
use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseAchillesController method getLatestCharacterization.
@ApiOperation("List latest characterization for given datasource")
@RequestMapping(value = "datasource/{id}", method = RequestMethod.GET)
public JsonResult<CharacterizationDTO> getLatestCharacterization(@PathVariable("id") Long datasourceId) throws NotExistException {
DS dataSource = checkDataSource(datasourceId);
Characterization characterization = achillesService.getLatestCharacterization(dataSource).orElseThrow(() -> new NotExistException(String.format("Characterization doesn't exist for dataSource: %s", datasourceId), Characterization.class));
JsonResult<CharacterizationDTO> result = new JsonResult<>();
result.setErrorCode(NO_ERROR.getCode());
CharacterizationDTO dto = conversionService.convert(characterization, CharacterizationDTO.class);
result.setResult(dto);
return result;
}
Aggregations