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);
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations