Search in sources :

Example 1 with AlreadyExistException

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

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

the class EstimationPreprocessor method attachEstimationAnalysisCode.

private void attachEstimationAnalysisCode(Analysis analysis) {
    Resource resource = new ClassPathResource(ESTIMATION_ANALYSIS_SOURCE);
    try (final InputStream in = resource.getInputStream()) {
        final MultipartFile analysisFile = new MockMultipartFile(ANALYSIS_BUNDLE_FILENAME, ANALYSIS_BUNDLE_FILENAME, null, in);
        analysisService.saveFile(analysisFile, analysis.getAuthor(), analysis, analysisFile.getName(), false, null);
    } catch (IOException e) {
        LOGGER.error("Failed to add file", e);
        throw new UncheckedIOException(e);
    } catch (AlreadyExistException e) {
        LOGGER.error("Failed to save file", e);
    }
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 3 with AlreadyExistException

use of com.odysseusinc.arachne.portal.exception.AlreadyExistException 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, String message) throws NotExistException, AlreadyExistException {
    Study study = Optional.ofNullable(studyRepository.getOne(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.setInviteMessage(message);
    studyLink.setToken(UUID.randomUUID().toString().replace("-", ""));
    userStudyRepository.save(studyLink);
    arachneMailSender.send(new InvitationCollaboratorMailSender(WebSecurityConfig.getDefaultPortalURI(), participant, studyLink, message));
    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 4 with AlreadyExistException

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

the class AnalysisFilesSavingServiceImpl method saveFiles.

@Override
@PreAuthorize("hasPermission(#analysis, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).UPLOAD_ANALYSIS_FILES)")
public List<AnalysisFile> saveFiles(List<UploadFileDTO> files, IUser user, A analysis) throws IOException {
    List<String> errorFileMessages = new ArrayList<>();
    List<AnalysisFile> savedFiles = new ArrayList<>();
    for (UploadFileDTO f : files) {
        try {
            if (StringUtils.isNotBlank(f.getLink())) {
                savedFiles.add(saveFileByLink(f.getLink(), user, analysis, f.getLabel(), f.getExecutable()));
            } else if (f.getFile() != null) {
                savedFiles.add(saveFile(f.getFile(), user, analysis, f.getLabel(), f.getExecutable(), null));
            } else {
                errorFileMessages.add(String.format("Invalid file: \"%s\"", f.getLabel()));
            }
        } catch (AlreadyExistException e) {
            errorFileMessages.add(e.getMessage());
        }
    }
    if (!errorFileMessages.isEmpty()) {
        throw new ValidationRuntimeException("Failed to save files", ImmutableMap.of("file", errorFileMessages));
    }
    return savedFiles;
}
Also used : UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) ArrayList(java.util.ArrayList) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with AlreadyExistException

use of com.odysseusinc.arachne.portal.exception.AlreadyExistException 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)

Aggregations

AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)10 Date (java.util.Date)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)5 IUser (com.odysseusinc.arachne.portal.model.IUser)5 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)3 IOException (java.io.IOException)3 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3 UploadFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO)2 ValidationRuntimeException (com.odysseusinc.arachne.portal.exception.ValidationRuntimeException)2 Analysis (com.odysseusinc.arachne.portal.model.Analysis)2 AnalysisUnlockRequest (com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest)2 DataNodeUser (com.odysseusinc.arachne.portal.model.DataNodeUser)2 FavouriteStudy (com.odysseusinc.arachne.portal.model.FavouriteStudy)2 Study (com.odysseusinc.arachne.portal.model.Study)2 User (com.odysseusinc.arachne.portal.model.User)2 UserStudy (com.odysseusinc.arachne.portal.model.UserStudy)2 InvitationCollaboratorMailSender (com.odysseusinc.arachne.portal.service.mail.InvitationCollaboratorMailSender)2 List (java.util.List)2