Search in sources :

Example 1 with AnalysisUnlockRequest

use of com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest in project ArachneCentralAPI by OHDSI.

the class BaseAnalysisServiceImpl method processAnalysisUnlockRequest.

@Override
public void processAnalysisUnlockRequest(IUser user, Long invitationId, Boolean invitationAccepted) throws NotExistException {
    final Long userId = user.getId();
    final AnalysisUnlockRequest exist = analysisUnlockRequestRepository.findOneByIdAndLeadId(invitationId, userId).orElseThrow(() -> {
        final String message = String.format(UNLOCK_REQUEST_NOT_EXIST_EXCEPTION, invitationId, userId);
        return new NotExistException(message, AnalysisUnlockRequest.class);
    });
    if (invitationAccepted != null && invitationAccepted) {
        exist.setStatus(AnalysisUnlockRequestStatus.APPROVED);
        final A analysis = (A) exist.getAnalysis();
        analysis.setLocked(false);
        analysisRepository.save(analysis);
    } else {
        exist.setStatus(AnalysisUnlockRequestStatus.DECLINED);
    }
    analysisUnlockRequestRepository.save(exist);
}
Also used : NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) AnalysisUnlockRequest(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest)

Example 2 with AnalysisUnlockRequest

use of com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest 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 3 with AnalysisUnlockRequest

use of com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest in project ArachneCentralAPI by OHDSI.

the class BaseAnalysisController method sendUnlockRequest.

@ApiOperation("Send analysis unlock request")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/unlock-request", method = POST)
public JsonResult<FileDTO> sendUnlockRequest(Principal principal, @PathVariable("analysisId") Long analysisId, @RequestBody AnalysisUnlockRequestDTO analysisUnlockRequestDTO) throws NotExistException, PermissionDeniedException, AlreadyExistException {
    JsonResult result;
    final IUser user = getUser(principal);
    final AnalysisUnlockRequest unlockRequest = new AnalysisUnlockRequest();
    unlockRequest.setUser(user);
    unlockRequest.setStatus(AnalysisUnlockRequestStatus.PENDING);
    unlockRequest.setCreated(new Date());
    unlockRequest.setToken(UUID.randomUUID().toString().replace("-", ""));
    unlockRequest.setDescription(analysisUnlockRequestDTO.getDescription());
    try {
        final AnalysisUnlockRequest analysisUnlockRequest = analysisService.sendAnalysisUnlockRequest(analysisId, unlockRequest);
        analysisService.findLeads((T) analysisUnlockRequest.getAnalysis()).forEach(lead -> wsTemplate.convertAndSendToUser(lead.getUsername(), "/topic/invitations", new UpdateNotificationDTO()));
        result = new JsonResult<>(NO_ERROR);
    } catch (AlreadyExistException ex) {
        result = new JsonResult<>(VALIDATION_ERROR);
        result.setErrorMessage("Unlock request for the analysis was already created");
    }
    return result;
}
Also used : UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) IUser(com.odysseusinc.arachne.portal.model.IUser) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) AnalysisUnlockRequest(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest) Date(java.util.Date) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AnalysisUnlockRequest (com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest)3 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)2 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)2 IUser (com.odysseusinc.arachne.portal.model.IUser)2 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)1 UpdateNotificationDTO (com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO)1 Analysis (com.odysseusinc.arachne.portal.model.Analysis)1 UnlockAnalysisRequestMailMessage (com.odysseusinc.arachne.portal.service.mail.UnlockAnalysisRequestMailMessage)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Date (java.util.Date)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 GET (org.springframework.web.bind.annotation.RequestMethod.GET)1 POST (org.springframework.web.bind.annotation.RequestMethod.POST)1 PUT (org.springframework.web.bind.annotation.RequestMethod.PUT)1