Search in sources :

Example 1 with NotExistException

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

the class BaseStudyServiceImpl method addParticipant.

@Override
@PreAuthorize("hasPermission(#studyId, 'Study', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).INVITE_CONTRIBUTOR)")
public UserStudy addParticipant(IUser createdBy, Long studyId, Long participantId, ParticipantRole role) throws NotExistException, AlreadyExistException {
    Study study = Optional.ofNullable(studyRepository.findOne(studyId)).orElseThrow(() -> new NotExistException(EX_STUDY_NOT_EXISTS, Study.class));
    IUser participant = Optional.ofNullable(userService.findOne(participantId)).orElseThrow(() -> new NotExistException(EX_USER_NOT_EXISTS, User.class));
    UserStudy studyLink = userStudyRepository.findOneByStudyIdAndUserId(study.getId(), participant.getId());
    if (studyLink == null) {
        // If user is invited for first time - create new link
        studyLink = new UserStudy();
    } else if (studyLink.getStatus().isPendingOrApproved()) {
        // Otherwise - invitation is pending or was already accepted. Cannot change or recreate
        throw new AlreadyExistException(EX_PARTICIPANT_EXISTS);
    }
    studyLink.setCreatedBy(createdBy);
    studyLink.setUser(participant);
    studyLink.setStudy(study);
    studyLink.setRole(role);
    studyLink.setCreated(new Date());
    studyLink.setStatus(ParticipantStatus.PENDING);
    studyLink.setDeletedAt(null);
    studyLink.setComment(null);
    studyLink.setToken(UUID.randomUUID().toString().replace("-", ""));
    userStudyRepository.save(studyLink);
    arachneMailSender.send(new InvitationCollaboratorMailSender(WebSecurityConfig.getDefaultPortalURI(), participant, studyLink));
    return studyLink;
}
Also used : UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) Study(com.odysseusinc.arachne.portal.model.Study) FavouriteStudy(com.odysseusinc.arachne.portal.model.FavouriteStudy) User(com.odysseusinc.arachne.portal.model.User) IUser(com.odysseusinc.arachne.portal.model.IUser) DataNodeUser(com.odysseusinc.arachne.portal.model.DataNodeUser) IUser(com.odysseusinc.arachne.portal.model.IUser) InvitationCollaboratorMailSender(com.odysseusinc.arachne.portal.service.mail.InvitationCollaboratorMailSender) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 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")
@DeleteMapping("/api/v1/analysis-management/submissions/{submissionId}/result/{fileUuid}")
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) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 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.")
@PostMapping("/api/v1/analysis-management/{analysisId}/submissions")
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.getByUsername(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) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) PutMapping(org.springframework.web.bind.annotation.PutMapping) Analysis(com.odysseusinc.arachne.portal.model.Analysis) ResultFileSearch(com.odysseusinc.arachne.portal.model.search.ResultFileSearch) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) 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) PostMapping(org.springframework.web.bind.annotation.PostMapping) 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) MediaType(org.springframework.http.MediaType) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) IUser(com.odysseusinc.arachne.portal.model.IUser) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) IOUtils(org.apache.commons.io.IOUtils) Principal(java.security.Principal) BaseSubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionDTO) SubmissionStatus(com.odysseusinc.arachne.portal.model.SubmissionStatus) FilenameUtils(org.apache.commons.io.FilenameUtils) java.util(java.util) FileDtoContentHandler(com.odysseusinc.arachne.portal.api.v1.dto.converters.FileDtoContentHandler) ZipInputStream(java.util.zip.ZipInputStream) StringUtils.getFilename(org.springframework.util.StringUtils.getFilename) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Submission(com.odysseusinc.arachne.portal.model.Submission) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) 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) ZipUtil(com.odysseusinc.arachne.portal.util.ZipUtil) Files(com.google.common.io.Files) ObjectUtils(org.apache.commons.lang3.ObjectUtils) SubmissionStatusHistoryElementDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionStatusHistoryElementDTO) NO_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR) GetMapping(org.springframework.web.bind.annotation.GetMapping) 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) HttpServletResponse(javax.servlet.http.HttpServletResponse) FileUtils(org.apache.commons.io.FileUtils) 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) File(java.io.File) 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) MultipartFile(org.springframework.web.multipart.MultipartFile) 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) Submission(com.odysseusinc.arachne.portal.model.Submission) Analysis(com.odysseusinc.arachne.portal.model.Analysis) IUser(com.odysseusinc.arachne.portal.model.IUser) 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) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with NotExistException

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

the class BaseStudyController method addParticipant.

@ApiOperation("Add participant to the study.")
@RequestMapping(value = "/api/v1/study-management/studies/{studyId}/participants", method = POST)
public JsonResult<Boolean> addParticipant(Principal principal, @PathVariable("studyId") Long studyId, @RequestBody @Valid AddStudyParticipantDTO addParticipantDTO, BindingResult binding) throws PermissionDeniedException, NotExistException, AlreadyExistException {
    JsonResult<Boolean> result;
    if (binding.hasErrors()) {
        return setValidationErrors(binding);
    }
    final IUser createdBy = getUser(principal);
    IUser participant = Optional.ofNullable(userService.getByUuid(addParticipantDTO.getUserId())).orElseThrow(() -> new NotExistException(EX_USER_NOT_EXISTS, User.class));
    UserStudy userStudy = studyService.addParticipant(createdBy, studyId, participant.getId(), addParticipantDTO.getRole(), addParticipantDTO.getMessage());
    wsTemplate.convertAndSendToUser(userStudy.getUser().getUsername(), "/topic/invitations", new UpdateNotificationDTO());
    return new JsonResult<>(NO_ERROR, Boolean.TRUE);
}
Also used : User(com.odysseusinc.arachne.portal.model.User) IUser(com.odysseusinc.arachne.portal.model.IUser) UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) IUser(com.odysseusinc.arachne.portal.model.IUser) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with NotExistException

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

the class BaseStudyController method suggest.

@ApiOperation("Suggest study.")
@RequestMapping(value = "/api/v1/study-management/studies/search", method = GET)
public JsonResult<List<StudyDTO>> suggest(Principal principal, @RequestParam("id") String requestId, @RequestParam("query") String query, @RequestParam("region") SuggestSearchRegion region) throws PermissionDeniedException {
    JsonResult<List<StudyDTO>> result;
    IUser owner = getUser(principal);
    Long id;
    switch(region) {
        case DATASOURCE:
            id = Long.valueOf(requestId);
            break;
        case PARTICIPANT:
            IUser participant = Optional.ofNullable(userService.getByUuid(requestId)).orElseThrow(() -> new NotExistException(EX_USER_NOT_EXISTS, User.class));
            id = participant.getId();
            break;
        default:
            id = 0L;
            break;
    }
    Iterable<T> studies = studyService.suggestStudy(query, owner, id, region);
    result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
    List<StudyDTO> studiesDTOs = new LinkedList<>();
    for (Study study : studies) {
        studiesDTOs.add(conversionService.convert(study, StudyDTO.class));
    }
    result.setResult(studiesDTOs);
    return result;
}
Also used : UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) Study(com.odysseusinc.arachne.portal.model.Study) CreateStudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateStudyDTO) StudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO) User(com.odysseusinc.arachne.portal.model.User) IUser(com.odysseusinc.arachne.portal.model.IUser) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) LinkedList(java.util.LinkedList) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) IUser(com.odysseusinc.arachne.portal.model.IUser) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)33 ApiOperation (io.swagger.annotations.ApiOperation)13 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)11 IUser (com.odysseusinc.arachne.portal.model.IUser)9 Date (java.util.Date)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Study (com.odysseusinc.arachne.portal.model.Study)7 UserStudy (com.odysseusinc.arachne.portal.model.UserStudy)7 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)6 NotUniqueException (com.odysseusinc.arachne.portal.exception.NotUniqueException)6 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)5 FavouriteStudy (com.odysseusinc.arachne.portal.model.FavouriteStudy)5 DataNodeUser (com.odysseusinc.arachne.portal.model.DataNodeUser)4 ResultFile (com.odysseusinc.arachne.portal.model.ResultFile)4 User (com.odysseusinc.arachne.portal.model.User)4 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)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