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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations