Search in sources :

Example 6 with NotExistException

use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.

the class StudyTypeController method delete.

@ApiOperation(value = "Delete study type.", hidden = true)
@RequestMapping(value = "/api/v1/admin/study-types/{studyTypeId}", method = RequestMethod.DELETE)
public JsonResult delete(@PathVariable("studyTypeId") Long id) {
    JsonResult result = null;
    if (id == null) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        result.getValidatorErrors().put("studyTypeId", "cannot be null");
    } else {
        try {
            studyTypeService.delete(id);
            result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
            result.setResult(Boolean.TRUE);
        } catch (NotExistException ex) {
            log.error(ex.getMessage(), ex);
            result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
            result.getValidatorErrors().put("studyTypeId", "Status with id=" + id + " not found");
            result.setErrorMessage(ex.getMessage());
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            result = new JsonResult<>(JsonResult.ErrorCode.SYSTEM_ERROR);
            result.setErrorMessage(ex.getMessage());
        }
    }
    return result;
}
Also used : NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) ConverterNotFoundException(org.springframework.core.convert.ConverterNotFoundException) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with NotExistException

use of com.odysseusinc.arachne.portal.exception.NotExistException 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 8 with NotExistException

use of com.odysseusinc.arachne.portal.exception.NotExistException 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 9 with NotExistException

use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.

the class BaseAnalysisServiceImpl method processAnalysisUnlockRequest.

@Override
public void processAnalysisUnlockRequest(IUser user, Long invitationId, Boolean invitationAccepted) throws NotExistException {
    final Long userId = user.getId();
    final AnalysisUnlockRequest exist = analysisUnlockRequestRepository.findOneByIdAndLeadId(invitationId, userId).orElseThrow(() -> {
        final String message = String.format(UNLOCK_REQUEST_NOT_EXIST_EXCEPTION, invitationId, userId);
        return new NotExistException(message, AnalysisUnlockRequest.class);
    });
    if (invitationAccepted != null && invitationAccepted) {
        exist.setStatus(AnalysisUnlockRequestStatus.APPROVED);
        final A analysis = (A) exist.getAnalysis();
        analysis.setLocked(false);
        analysisRepository.save(analysis);
    } else {
        exist.setStatus(AnalysisUnlockRequestStatus.DECLINED);
    }
    analysisUnlockRequestRepository.save(exist);
}
Also used : NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) AnalysisUnlockRequest(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest)

Example 10 with NotExistException

use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.

the class BasePaperServiceImpl method deleteFile.

@PreAuthorize("hasPermission(#paperId, 'Paper', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).LIMITED_EDIT_PAPER)")
// @Transactional not usable for this method.
@Override
public void deleteFile(Long paperId, String fileUuid, PaperFileType fileType) throws FileNotFoundException {
    AbstractPaperFile paperFile;
    switch(fileType) {
        case PAPER:
            {
                paperFile = paperPaperFileRepository.findByPaperIdAndUuid(paperId, fileUuid).orElseThrow(() -> new NotExistException(AbstractPaperFile.class));
                paperPaperFileRepository.delete(paperFile.getId());
                break;
            }
        case PROTOCOL:
            {
                paperFile = paperProtocolFileRepository.findByPaperIdAndUuid(paperId, fileUuid).orElseThrow(() -> new NotExistException(AbstractPaperFile.class));
                paperProtocolFileRepository.delete(paperFile.getId());
                break;
            }
        default:
            {
                throw new IllegalArgumentException("Illegal filetype: " + fileType);
            }
    }
    fileService.delete(paperFile);
}
Also used : NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) AbstractPaperFile(com.odysseusinc.arachne.portal.model.AbstractPaperFile) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)29 ApiOperation (io.swagger.annotations.ApiOperation)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 IUser (com.odysseusinc.arachne.portal.model.IUser)8 Date (java.util.Date)7 NotUniqueException (com.odysseusinc.arachne.portal.exception.NotUniqueException)6 UserStudy (com.odysseusinc.arachne.portal.model.UserStudy)6 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)5 Study (com.odysseusinc.arachne.portal.model.Study)5 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)4 FavouriteStudy (com.odysseusinc.arachne.portal.model.FavouriteStudy)4 ResultFile (com.odysseusinc.arachne.portal.model.ResultFile)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 User (com.odysseusinc.arachne.portal.model.User)3 CommonAnalysisType (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType)2 Analysis (com.odysseusinc.arachne.portal.model.Analysis)2 AnalysisUnlockRequest (com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest)2