use of com.odysseusinc.arachne.portal.exception.ValidationException in project ArachneCentralAPI by OHDSI.
the class BaseUserController method changePassword.
@ApiOperation("Change user password")
@RequestMapping(value = "/api/v1/user-management/users/changepassword", method = POST)
public JsonResult changePassword(@RequestBody @Valid ChangePasswordDTO changePasswordDTO, Principal principal) throws ValidationException, PasswordValidationException {
JsonResult result;
U loggedUser = userService.getByEmail(principal.getName());
try {
userService.updatePassword(loggedUser, changePasswordDTO.getOldPassword(), changePasswordDTO.getNewPassword());
result = new JsonResult<>(NO_ERROR);
} catch (ValidationException ex) {
result = new JsonResult<>(VALIDATION_ERROR);
result.setErrorMessage(ex.getMessage());
}
return result;
}
use of com.odysseusinc.arachne.portal.exception.ValidationException in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionController method deleteSubmissionResultsByUuid.
@ApiOperation("Delete manually uploaded submission result file")
@RequestMapping(value = "/api/v1/analysis-management/submissions/{submissionId}/result/{fileUuid}", method = DELETE)
public JsonResult<Boolean> deleteSubmissionResultsByUuid(@PathVariable("submissionId") Long id, @PathVariable("fileUuid") String fileUuid) {
LOGGER.info("deleting result file for submission with id={} having uuid={}", id, fileUuid);
JsonResult.ErrorCode errorCode;
Boolean hasResult;
try {
ResultFile resultFile = submissionService.getResultFileByPath(contentStorageService.getFileByIdentifier(fileUuid).getPath());
hasResult = submissionService.deleteSubmissionResultFile(id, resultFile);
errorCode = JsonResult.ErrorCode.NO_ERROR;
} catch (NotExistException e) {
LOGGER.warn("Submission was not found, id: {}", id);
errorCode = JsonResult.ErrorCode.VALIDATION_ERROR;
hasResult = false;
} catch (ValidationException e) {
LOGGER.warn("Result file was not deleted", e);
errorCode = JsonResult.ErrorCode.VALIDATION_ERROR;
hasResult = false;
}
JsonResult<Boolean> result = new JsonResult<>(errorCode);
result.setResult(hasResult);
return result;
}
use of com.odysseusinc.arachne.portal.exception.ValidationException in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionController method createSubmission.
@ApiOperation("Create and send submission.")
@RequestMapping(value = "/api/v1/analysis-management/{analysisId}/submissions", method = POST)
public JsonResult<List<DTO>> createSubmission(Principal principal, @RequestBody @Validated CreateSubmissionsDTO createSubmissionsDTO, @PathVariable("analysisId") Long analysisId) throws PermissionDeniedException, NotExistException, IOException, NoExecutableFileException, ValidationException {
final JsonResult<List<DTO>> result;
if (principal == null) {
throw new PermissionDeniedException();
}
IUser user = userService.getByEmail(principal.getName());
if (user == null) {
throw new PermissionDeniedException();
}
Analysis analysis = analysisService.getById(analysisId);
final List<Submission> submissions = AnalysisHelper.createSubmission(submissionService, createSubmissionsDTO.getDataSources(), user, analysis);
final List<DTO> submissionDTOs = submissions.stream().map(s -> conversionService.convert(s, getSubmissionDTOClass())).collect(Collectors.toList());
result = new JsonResult<>(NO_ERROR);
result.setResult(submissionDTOs);
return result;
}
use of com.odysseusinc.arachne.portal.exception.ValidationException in project ArachneCentralAPI by OHDSI.
the class BaseStudyServiceImpl method update.
@Override
@PreAuthorize("hasPermission(#study, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_STUDY)")
@PostAuthorize("@ArachnePermissionEvaluator.addPermissions(principal, returnObject )")
public T update(T study) throws NotExistException, NotUniqueException, ValidationException {
if (study.getId() == null) {
throw new NotExistException("id is null", getType());
}
List<T> byTitle = studyRepository.findByTitle(study.getTitle());
if (!byTitle.isEmpty()) {
throw new NotUniqueException("title", "not unique");
}
T forUpdate = studyRepository.findOne(study.getId());
if (forUpdate == null) {
throw new NotExistException(getType());
}
if (study.getType() != null && study.getType().getId() != null) {
forUpdate.setType(studyTypeService.getById(study.getType().getId()));
}
if (study.getStatus() != null && study.getStatus().getId() != null && studyStateMachine.canTransit(forUpdate, studyStatusService.getById(study.getStatus().getId()))) {
forUpdate.setStatus(studyStatusService.getById(study.getStatus().getId()));
}
forUpdate.setTitle(study.getTitle() != null ? study.getTitle() : forUpdate.getTitle());
forUpdate.setDescription(study.getDescription() != null ? study.getDescription() : forUpdate.getDescription());
forUpdate.setStartDate(study.getStartDate() != null ? study.getStartDate() : forUpdate.getStartDate());
forUpdate.setEndDate(study.getEndDate() != null ? study.getEndDate() : forUpdate.getEndDate());
if (forUpdate.getStartDate() != null && forUpdate.getEndDate() != null && forUpdate.getStartDate().getTime() > forUpdate.getEndDate().getTime()) {
throw new ValidationException("end date before start date ");
}
forUpdate.setPrivacy(study.getPrivacy() != null ? study.getPrivacy() : forUpdate.getPrivacy());
forUpdate.setUpdated(new Date());
forUpdate.setPrivacy(study.getPrivacy() != null ? study.getPrivacy() : forUpdate.getPrivacy());
T updatedStudy = studyRepository.save(forUpdate);
// mb too frequently
solrService.indexBySolr(forUpdate);
return updatedStudy;
}
use of com.odysseusinc.arachne.portal.exception.ValidationException 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;
}
Aggregations