Search in sources :

Example 1 with UnlockAnalysisRequestMailMessage

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;
}
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)1 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)1 Analysis (com.odysseusinc.arachne.portal.model.Analysis)1 AnalysisUnlockRequest (com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest)1 IUser (com.odysseusinc.arachne.portal.model.IUser)1 UnlockAnalysisRequestMailMessage (com.odysseusinc.arachne.portal.service.mail.UnlockAnalysisRequestMailMessage)1