Search in sources :

Example 1 with UserStudy

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

use of com.odysseusinc.arachne.portal.model.UserStudy 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;
}
Also used : UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) Study(com.odysseusinc.arachne.portal.model.Study) FavouriteStudy(com.odysseusinc.arachne.portal.model.FavouriteStudy) User(com.odysseusinc.arachne.portal.model.User) IUser(com.odysseusinc.arachne.portal.model.IUser) DataNodeUser(com.odysseusinc.arachne.portal.model.DataNodeUser) IUser(com.odysseusinc.arachne.portal.model.IUser) InvitationCollaboratorMailSender(com.odysseusinc.arachne.portal.service.mail.InvitationCollaboratorMailSender) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with UserStudy

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

the class BaseStudyServiceImpl method removeParticipant.

@Override
@PreAuthorize("hasPermission(#id, 'Study'," + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_STUDY)")
public void removeParticipant(Long id, Long participantId) throws NotExistException, PermissionDeniedException, ValidationException {
    Study study = getById(id);
    IUser participant = userService.findOne(participantId);
    UserStudy studyLink = Optional.ofNullable(userStudyRepository.findOneByStudyAndUser(study, participant)).orElseThrow(() -> new NotExistException(UserStudy.class));
    checkLastLeadInvestigator(studyLink, study);
    if (userStudyRepository.hardRemoveIfNotTracked(id, participantId) == 0) {
        userStudyRepository.delete(studyLink);
    }
}
Also used : UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) Study(com.odysseusinc.arachne.portal.model.Study) FavouriteStudy(com.odysseusinc.arachne.portal.model.FavouriteStudy) IUser(com.odysseusinc.arachne.portal.model.IUser) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with UserStudy

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

the class BaseStudyServiceImpl method addDefaultLead.

private UserStudy addDefaultLead(Study study, IUser owner) {
    UserStudy leadStudyLink = new UserStudy();
    leadStudyLink.setCreatedBy(owner);
    leadStudyLink.setUser(owner);
    leadStudyLink.setStudy(study);
    leadStudyLink.setRole(LEAD_INVESTIGATOR);
    leadStudyLink.setCreated(new Date());
    leadStudyLink.setStatus(ParticipantStatus.APPROVED);
    leadStudyLink.setToken("");
    userStudyRepository.save(leadStudyLink);
    return leadStudyLink;
}
Also used : UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) Date(java.util.Date)

Example 5 with UserStudy

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

the class BaseStudyServiceImpl method updateParticipantRole.

@Override
@PreAuthorize("hasPermission(#studyId, 'Study', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).INVITE_CONTRIBUTOR)")
public UserStudy updateParticipantRole(Long studyId, Long participantId, ParticipantRole role) throws NotExistException, AlreadyExistException, ValidationException {
    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 = Optional.ofNullable(userStudyRepository.findOneByStudyAndUser(study, participant)).orElseThrow(() -> new NotExistException(UserStudy.class));
    checkLastLeadInvestigator(studyLink, study);
    studyLink.setRole(role);
    return userStudyRepository.save(studyLink);
}
Also used : UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) Study(com.odysseusinc.arachne.portal.model.Study) FavouriteStudy(com.odysseusinc.arachne.portal.model.FavouriteStudy) User(com.odysseusinc.arachne.portal.model.User) IUser(com.odysseusinc.arachne.portal.model.IUser) DataNodeUser(com.odysseusinc.arachne.portal.model.DataNodeUser) IUser(com.odysseusinc.arachne.portal.model.IUser) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

UserStudy (com.odysseusinc.arachne.portal.model.UserStudy)6 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)4 IUser (com.odysseusinc.arachne.portal.model.IUser)4 FavouriteStudy (com.odysseusinc.arachne.portal.model.FavouriteStudy)3 Study (com.odysseusinc.arachne.portal.model.Study)3 User (com.odysseusinc.arachne.portal.model.User)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 DataNodeUser (com.odysseusinc.arachne.portal.model.DataNodeUser)2 Date (java.util.Date)2 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)1 UpdateNotificationDTO (com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO)1 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)1 ParticipantStatus (com.odysseusinc.arachne.portal.model.ParticipantStatus)1 InvitationCollaboratorMailSender (com.odysseusinc.arachne.portal.service.mail.InvitationCollaboratorMailSender)1 ApiOperation (io.swagger.annotations.ApiOperation)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1