Search in sources :

Example 16 with NotExistException

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

the class BaseAnalysisServiceImpl method sendAnalysisUnlockRequest.

@Override
public AnalysisUnlockRequest sendAnalysisUnlockRequest(Long analysisId, AnalysisUnlockRequest analysisUnlockRequest) throws NotExistException, AlreadyExistException {
    final Optional<A> analysisOptional = analysisRepository.findByIdAndAndLockedTrue(analysisId);
    final Analysis analysis = analysisOptional.orElseThrow(() -> new NotExistException(ANALYSIS_NOT_FOUND_EXCEPTION, Analysis.class));
    IUser user = analysisUnlockRequest.getUser();
    final AnalysisUnlockRequest existUnlockRequest = analysisUnlockRequestRepository.findByAnalysisAndStatus(analysis, AnalysisUnlockRequestStatus.PENDING);
    if (existUnlockRequest != null) {
        String message = String.format(UNLOCK_REQUEST_ALREADY_EXISTS_EXCEPTION, analysis.getId(), user.getId());
        throw new AlreadyExistException(message);
    }
    analysisUnlockRequest.setAnalysis(analysis);
    final AnalysisUnlockRequest savedUnlockRequest = analysisUnlockRequestRepository.save(analysisUnlockRequest);
    studyService.findLeads((S) savedUnlockRequest.getAnalysis().getStudy()).forEach(lead -> mailSender.send(new UnlockAnalysisRequestMailMessage(WebSecurityConfig.getDefaultPortalURI(), lead, savedUnlockRequest)));
    return savedUnlockRequest;
}
Also used : Analysis(com.odysseusinc.arachne.portal.model.Analysis) IUser(com.odysseusinc.arachne.portal.model.IUser) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) AnalysisUnlockRequest(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest) UnlockAnalysisRequestMailMessage(com.odysseusinc.arachne.portal.service.mail.UnlockAnalysisRequestMailMessage)

Example 17 with NotExistException

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

the class BaseAnalysisServiceImpl method update.

@Override
@PreAuthorize("hasPermission(#analysis,  'Analysis', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_ANALYSIS)")
public A update(A analysis) throws NotUniqueException, NotExistException, ValidationException {
    A forUpdate = analysisRepository.findOne(analysis.getId());
    if (forUpdate == null) {
        throw new NotExistException("update: analysis with id=" + analysis.getId() + " not exist", Analysis.class);
    }
    if (analysis.getTitle() != null && !analysis.getTitle().equals(forUpdate.getTitle())) {
        List<A> analyses = analysisRepository.findByTitleAndStudyId(analysis.getTitle(), forUpdate.getStudy().getId());
        if (!analyses.isEmpty()) {
            throw new NotUniqueException("title", "Not unique");
        }
        forUpdate.setTitle(analysis.getTitle());
    }
    if (analysis.getDescription() != null) {
        forUpdate.setDescription(analysis.getDescription());
    }
    final CommonAnalysisType analysisType = analysis.getType();
    if (analysisType != null) {
        forUpdate.setType(analysisType);
    }
    final A saved = super.update(forUpdate);
    solrService.indexBySolr(saved);
    return saved;
}
Also used : NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) CommonAnalysisType(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 18 with NotExistException

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

the class BaseDataNodeServiceImpl method unlinkUserToDataNode.

@Transactional
@Override
@PreAuthorize("#dataNode == authentication.principal")
public void unlinkUserToDataNode(DN dataNode, IUser user) throws NotExistException {
    LOGGER.info(UNLINKING_USER_LOG, user.getId(), dataNode.getId());
    final DataNodeUser existDataNodeUser = dataNodeUserRepository.findByDataNodeAndUserId(dataNode, user.getId()).orElseThrow(() -> {
        final String message = String.format(USER_IS_NOT_LINKED_EXC, user.getId(), dataNode.getId());
        return new NotExistException(message, User.class);
    });
    dataNodeUserRepository.delete(existDataNodeUser);
}
Also used : NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) DataNodeUser(com.odysseusinc.arachne.portal.model.DataNodeUser) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with NotExistException

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

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

the class BaseStudyServiceImpl method removeDataSourceUnsecured.

@Override
public void removeDataSourceUnsecured(Long studyId, Long dataSourceId) {
    Study study = studyRepository.findOne(studyId);
    if (study == null) {
        throw new NotExistException("study does not exist.", Study.class);
    }
    StudyDataSourceLink studyDataSourceLink = studyDataSourceLinkRepository.findByStudyIdAndDataSourceId(study.getId(), dataSourceId);
    if (studyDataSourceLink == null) {
        throw new NotExistException("studyDataSourceLink does not exist.", StudyDataSourceLink.class);
    }
    studyDataSourceLinkRepository.delete(studyDataSourceLink.getId());
}
Also used : UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) Study(com.odysseusinc.arachne.portal.model.Study) FavouriteStudy(com.odysseusinc.arachne.portal.model.FavouriteStudy) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException)

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