Search in sources :

Example 1 with ValidationException

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;
}
Also used : PasswordValidationException(com.odysseusinc.arachne.portal.exception.PasswordValidationException) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ValidationException

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;
}
Also used : ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ValidationException

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;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) AnalysisHelper(com.odysseusinc.arachne.portal.util.AnalysisHelper) Date(java.util.Date) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) LoggerFactory(org.slf4j.LoggerFactory) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) Analysis(com.odysseusinc.arachne.portal.model.Analysis) ResultFileSearch(com.odysseusinc.arachne.portal.model.search.ResultFileSearch) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile) Path(java.nio.file.Path) SubmissionStatusHistoryElement(com.odysseusinc.arachne.portal.model.SubmissionStatusHistoryElement) ToPdfConverter(com.odysseusinc.arachne.portal.service.ToPdfConverter) BaseSubmissionService(com.odysseusinc.arachne.portal.service.submission.BaseSubmissionService) BaseAnalysisService(com.odysseusinc.arachne.portal.service.analysis.BaseAnalysisService) ContentStorageService(com.odysseusinc.arachne.storage.service.ContentStorageService) ResultFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.ResultFileDTO) HttpUtils(com.odysseusinc.arachne.portal.util.HttpUtils) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) IUser(com.odysseusinc.arachne.portal.model.IUser) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Principal(java.security.Principal) BaseSubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionDTO) SubmissionStatus(com.odysseusinc.arachne.portal.model.SubmissionStatus) FileDtoContentHandler(com.odysseusinc.arachne.portal.api.v1.dto.converters.FileDtoContentHandler) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) GET(org.springframework.web.bind.annotation.RequestMethod.GET) Submission(com.odysseusinc.arachne.portal.model.Submission) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) ArrayList(java.util.ArrayList) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) RequestBody(org.springframework.web.bind.annotation.RequestBody) NoExecutableFileException(com.odysseusinc.arachne.portal.exception.NoExecutableFileException) ApproveDTO(com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO) NO_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR) SubmissionStatusHistoryElementDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionStatusHistoryElementDTO) POST(org.springframework.web.bind.annotation.RequestMethod.POST) LinkedList(java.util.LinkedList) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) BaseController(com.odysseusinc.arachne.portal.api.v1.controller.BaseController) Validated(org.springframework.validation.annotation.Validated) Logger(org.slf4j.Logger) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) CommonAnalysisExecutionStatusDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisExecutionStatusDTO) CreateSubmissionsDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateSubmissionsDTO) SubmissionFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) ContentStorageHelper(com.odysseusinc.arachne.portal.util.ContentStorageHelper) HttpStatus(org.springframework.http.HttpStatus) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) SubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionDTO) BaseSubmissionAndAnalysisTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionAndAnalysisTypeDTO) SubmissionInsightService(com.odysseusinc.arachne.portal.service.submission.SubmissionInsightService) StringUtils(org.springframework.util.StringUtils) Submission(com.odysseusinc.arachne.portal.model.Submission) Analysis(com.odysseusinc.arachne.portal.model.Analysis) IUser(com.odysseusinc.arachne.portal.model.IUser) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) ResultFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.ResultFileDTO) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) BaseSubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionDTO) ApproveDTO(com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO) SubmissionStatusHistoryElementDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionStatusHistoryElementDTO) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) CommonAnalysisExecutionStatusDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisExecutionStatusDTO) CreateSubmissionsDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateSubmissionsDTO) SubmissionFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO) SubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionDTO) BaseSubmissionAndAnalysisTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionAndAnalysisTypeDTO) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ValidationException

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;
}
Also used : ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) Date(java.util.Date) PostAuthorize(org.springframework.security.access.prepost.PostAuthorize) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with ValidationException

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;
}
Also used : ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) Date(java.util.Date)

Aggregations

ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)6 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)4 ApiOperation (io.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)3 ResultFile (com.odysseusinc.arachne.portal.model.ResultFile)3 ArachneFileMeta (com.odysseusinc.arachne.storage.model.ArachneFileMeta)2 Date (java.util.Date)2 CommonAnalysisExecutionStatusDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisExecutionStatusDTO)1 NO_ERROR (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR)1 BaseController (com.odysseusinc.arachne.portal.api.v1.controller.BaseController)1 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)1 BaseSubmissionAndAnalysisTypeDTO (com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionAndAnalysisTypeDTO)1 BaseSubmissionDTO (com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionDTO)1 CreateSubmissionsDTO (com.odysseusinc.arachne.portal.api.v1.dto.CreateSubmissionsDTO)1 FileDTO (com.odysseusinc.arachne.portal.api.v1.dto.FileDTO)1 ResultFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.ResultFileDTO)1 SubmissionDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionDTO)1 SubmissionFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO)1 SubmissionStatusHistoryElementDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionStatusHistoryElementDTO)1