Search in sources :

Example 21 with NotExistException

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

the class BaseStudyServiceImpl method addDataSource.

@Override
// ordering annotations is important to check current participants before method invoke
@PreAuthorize("hasPermission(#studyId, 'Study', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).INVITE_DATANODE)")
public StudyDataSourceLink addDataSource(IUser createdBy, Long studyId, Long dataSourceId) throws NotExistException, AlreadyExistException {
    T study = studyRepository.findOne(studyId);
    if (study == null) {
        throw new NotExistException("study not exist", Study.class);
    }
    DS dataSource = dataSourceService.getNotDeletedById(dataSourceId);
    if (dataSource == null) {
        throw new NotExistException("dataSource not exist", DataSource.class);
    }
    StudyDataSourceLink studyDataSourceLink = studyDataSourceLinkRepository.findByDataSourceIdAndStudyId(dataSource.getId(), study.getId());
    if (studyDataSourceLink == null) {
        studyDataSourceLink = new StudyDataSourceLink();
    } else if (studyDataSourceLink.getStatus().isPendingOrApproved()) {
        throw new AlreadyExistException();
    }
    studyDataSourceLink.setStudy(study);
    studyDataSourceLink.setDataSource(dataSource);
    studyDataSourceLink.setCreated(new Date());
    studyDataSourceLink.setToken(UUID.randomUUID().toString());
    studyDataSourceLink.setCreatedBy(createdBy);
    studyDataSourceLink.setDeletedAt(null);
    AddDataSourceStrategy<DS> strategy = addDataSourceStrategyFactory.getStrategy(dataSource);
    strategy.addDataSourceToStudy(createdBy, dataSource, studyDataSourceLink);
    return studyDataSourceLink;
}
Also used : StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 22 with NotExistException

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

the class BaseStudyServiceImpl method updateParticipantRole.

@Override
@PreAuthorize("hasPermission(#studyId, 'Study', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).INVITE_CONTRIBUTOR)")
public UserStudy updateParticipantRole(Long studyId, Long participantId, ParticipantRole role) throws NotExistException, AlreadyExistException, ValidationException {
    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 = Optional.ofNullable(userStudyRepository.findOneByStudyAndUser(study, participant)).orElseThrow(() -> new NotExistException(UserStudy.class));
    checkLastLeadInvestigator(studyLink, study);
    studyLink.setRole(role);
    return userStudyRepository.save(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) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 23 with NotExistException

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

the class BaseAnalysisController method list.

@ApiOperation("List analyses.")
@RequestMapping(value = "/api/v1/analysis-management/analyses", method = GET)
public JsonResult<List<D>> list(Principal principal, @RequestParam("study-id") Long studyId) throws PermissionDeniedException, NotExistException {
    JsonResult<List<D>> result;
    IUser user = userService.getByEmail(principal.getName());
    if (user == null) {
        result = new JsonResult<>(PERMISSION_DENIED);
        return result;
    }
    Iterable<T> analyses = analysisService.list(user, studyId);
    result = new JsonResult<>(NO_ERROR);
    List<D> analysisDTOs = StreamSupport.stream(analyses.spliterator(), false).map(analysis -> conversionService.convert(analysis, getAnalysisDTOClass())).collect(Collectors.toList());
    result.setResult(analysisDTOs);
    return result;
}
Also used : Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) SqlTranslate(org.ohdsi.sql.SqlTranslate) Valid(javax.validation.Valid) CommentUtils.getRecentCommentables(com.odysseusinc.arachne.portal.util.CommentUtils.getRecentCommentables) AnalysisLockDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisLockDTO) BaseDataSourceService(com.odysseusinc.arachne.portal.service.BaseDataSourceService) Analysis(com.odysseusinc.arachne.portal.model.Analysis) Map(java.util.Map) Commentable(com.odysseusinc.arachne.portal.api.v1.dto.Commentable) Sort(org.springframework.data.domain.Sort) ImportedFile(com.odysseusinc.arachne.portal.util.ImportedFile) Resource(org.springframework.core.io.Resource) MessagingUtils(com.odysseusinc.arachne.portal.service.messaging.MessagingUtils) FieldError(org.springframework.validation.FieldError) SqlRender(org.ohdsi.sql.SqlRender) Set(java.util.Set) AnalysisFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO) Page(org.springframework.data.domain.Page) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) IUser(com.odysseusinc.arachne.portal.model.IUser) IOUtils(org.apache.commons.io.IOUtils) SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) RuntimeIOException(org.assertj.core.api.exception.RuntimeIOException) VALIDATION_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataReference(com.odysseusinc.arachne.portal.model.DataReference) BindingResult(org.springframework.validation.BindingResult) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) ZipUtil(com.odysseusinc.arachne.portal.util.ZipUtil) SubmissionInsightDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO) NO_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR) StreamSupport(java.util.stream.StreamSupport) CommonEntityRequestDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO) IOException(java.io.IOException) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) HttpUtils.putFileContentToResponse(com.odysseusinc.arachne.portal.util.HttpUtils.putFileContentToResponse) SubmissionInsightUpdateDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightUpdateDTO) DataReferenceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataReferenceDTO) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) AnalysisUpdateDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUpdateDTO) PathVariable(org.springframework.web.bind.annotation.PathVariable) AnalysisUnlockRequestDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUnlockRequestDTO) Date(java.util.Date) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) ApiOperation(io.swagger.annotations.ApiOperation) ByteArrayInputStream(java.io.ByteArrayInputStream) PERMISSION_DENIED(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.PERMISSION_DENIED) AnalysisUnlockRequest(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest) ToPdfConverter(com.odysseusinc.arachne.portal.service.ToPdfConverter) BaseSubmissionService(com.odysseusinc.arachne.portal.service.submission.BaseSubmissionService) BaseAnalysisService(com.odysseusinc.arachne.portal.service.analysis.BaseAnalysisService) AnalysisDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisDTO) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) CommonAnalysisType(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType) UUID(java.util.UUID) ShortBaseAnalysisDTO(com.odysseusinc.arachne.portal.api.v1.dto.ShortBaseAnalysisDTO) Collectors(java.util.stream.Collectors) JMSException(javax.jms.JMSException) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) CommonFileUtils(com.odysseusinc.arachne.commons.utils.CommonFileUtils) List(java.util.List) Principal(java.security.Principal) DataReferenceService(com.odysseusinc.arachne.portal.service.DataReferenceService) AnalysisCreateDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisCreateDTO) AnalysisUnlockRequestStatus(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequestStatus) FilenameUtils(org.apache.commons.io.FilenameUtils) SubmissionGroupDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionGroupDTO) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) FileDtoContentHandler(com.odysseusinc.arachne.portal.api.v1.dto.converters.FileDtoContentHandler) ClassPathResource(org.springframework.core.io.ClassPathResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) ObjectMessage(javax.jms.ObjectMessage) GET(org.springframework.web.bind.annotation.RequestMethod.GET) Submission(com.odysseusinc.arachne.portal.model.Submission) SubmissionGroupSearch(com.odysseusinc.arachne.portal.model.search.SubmissionGroupSearch) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) JmsTemplate(org.springframework.jms.core.JmsTemplate) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) POST(org.springframework.web.bind.annotation.RequestMethod.POST) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) LinkedList(java.util.LinkedList) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) ServiceNotAvailableException(com.odysseusinc.arachne.portal.exception.ServiceNotAvailableException) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) Logger(org.slf4j.Logger) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) DBMSType(com.odysseusinc.arachne.commons.types.DBMSType) HttpServletResponse(javax.servlet.http.HttpServletResponse) BaseDataNodeService(com.odysseusinc.arachne.portal.service.BaseDataNodeService) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) OptionDTO(com.odysseusinc.arachne.commons.api.v1.dto.OptionDTO) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) DataNode(com.odysseusinc.arachne.portal.model.DataNode) MultipartFile(org.springframework.web.multipart.MultipartFile) ImportService(com.odysseusinc.arachne.portal.service.ImportService) NotEmptyException(com.odysseusinc.arachne.portal.exception.NotEmptyException) SubmissionInsightService(com.odysseusinc.arachne.portal.service.submission.SubmissionInsightService) InputStream(java.io.InputStream) StringUtils(org.springframework.util.StringUtils) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) PERMISSION_DENIED(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.PERMISSION_DENIED) UUID(java.util.UUID) IUser(com.odysseusinc.arachne.portal.model.IUser) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with NotExistException

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

the class BaseUserController method linkUserToDataNode.

@ApiOperation("Link U to DataNode")
@RequestMapping(value = "/api/v1/user-management/datanodes/{datanodeSid}/users", method = POST)
public JsonResult linkUserToDataNode(@PathVariable("datanodeSid") Long datanodeId, @RequestBody CommonLinkUserToDataNodeDTO linkUserToDataNode) throws NotExistException, AlreadyExistException {
    final DN dataNode = Optional.ofNullable(baseDataNodeService.getById(datanodeId)).orElseThrow(() -> new NotExistException(String.format(DATA_NODE_NOT_FOUND_EXCEPTION, datanodeId), DataNode.class));
    final U user = userService.getByUnverifiedEmailInAnyTenant(linkUserToDataNode.getUserName());
    baseDataNodeService.linkUserToDataNode(dataNode, user);
    return new JsonResult(NO_ERROR);
}
Also used : DataNode(com.odysseusinc.arachne.portal.model.DataNode) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with NotExistException

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

the class StudyTypeController method update.

@ApiOperation(value = "Edit study type.", hidden = true)
@RequestMapping(value = "/api/v1/admin/study-types/{studyTypeId}", method = RequestMethod.PUT)
public JsonResult update(@PathVariable("studyTypeId") Long id, @RequestBody @Valid StudyTypeDTO studyTypeDTO, BindingResult binding) {
    JsonResult result = null;
    if (binding.hasErrors()) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        try {
            StudyType studyType = conversionService.convert(studyTypeDTO, StudyType.class);
            studyType = studyTypeService.update(studyType);
            result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
            result.setResult(studyType);
        } catch (ConverterNotFoundException ex) {
            log.error(ex.getMessage(), ex);
            result = new JsonResult<>(JsonResult.ErrorCode.SYSTEM_ERROR);
            result.setErrorMessage(ex.getMessage());
        } catch (NotExistException ex) {
            log.error(ex.getMessage(), ex);
            result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
            result.getValidatorErrors().put("id", "Status with id=" + id + " not found");
            result.setErrorMessage(ex.getMessage());
        } catch (NotUniqueException ex) {
            log.error(ex.getMessage(), ex);
            result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
            result.getValidatorErrors().put(ex.getField(), ex.getMessage());
            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 : StudyType(com.odysseusinc.arachne.portal.model.StudyType) ConverterNotFoundException(org.springframework.core.convert.ConverterNotFoundException) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) FieldError(org.springframework.validation.FieldError) 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)

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