Search in sources :

Example 1 with UpdateNotificationDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO in project ArachneCentralAPI by OHDSI.

the class BaseStudyController method addParticipant.

@ApiOperation("Add participant to the study.")
@RequestMapping(value = "/api/v1/study-management/studies/{studyId}/participants", method = POST)
public JsonResult<Boolean> addParticipant(Principal principal, @PathVariable("studyId") Long studyId, @RequestBody @Valid AddStudyParticipantDTO addParticipantDTO, BindingResult binding) throws PermissionDeniedException, NotExistException, AlreadyExistException {
    JsonResult<Boolean> result;
    if (binding.hasErrors()) {
        return setValidationErrors(binding);
    }
    final IUser createdBy = getUser(principal);
    IUser participant = Optional.ofNullable(userService.getByUuid(addParticipantDTO.getUserId())).orElseThrow(() -> new NotExistException(EX_USER_NOT_EXISTS, User.class));
    UserStudy userStudy = studyService.addParticipant(createdBy, studyId, participant.getId(), addParticipantDTO.getRole());
    wsTemplate.convertAndSendToUser(userStudy.getUser().getUsername(), "/topic/invitations", new UpdateNotificationDTO());
    return new JsonResult<>(NO_ERROR, Boolean.TRUE);
}
Also used : User(com.odysseusinc.arachne.portal.model.User) IUser(com.odysseusinc.arachne.portal.model.IUser) UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) IUser(com.odysseusinc.arachne.portal.model.IUser) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UpdateNotificationDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO 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

JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)2 UpdateNotificationDTO (com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO)2 IUser (com.odysseusinc.arachne.portal.model.IUser)2 ApiOperation (io.swagger.annotations.ApiOperation)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)1 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)1 AnalysisUnlockRequest (com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest)1 User (com.odysseusinc.arachne.portal.model.User)1 UserStudy (com.odysseusinc.arachne.portal.model.UserStudy)1 Date (java.util.Date)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