use of com.odysseusinc.arachne.portal.service.mail.UnlockAnalysisRequestMailMessage 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