use of com.odysseusinc.arachne.portal.api.v1.dto.AddStudyParticipantDTO 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(), addParticipantDTO.getMessage());
wsTemplate.convertAndSendToUser(userStudy.getUser().getUsername(), "/topic/invitations", new UpdateNotificationDTO());
return new JsonResult<>(NO_ERROR, Boolean.TRUE);
}
use of com.odysseusinc.arachne.portal.api.v1.dto.AddStudyParticipantDTO in project ArachneCentralAPI by OHDSI.
the class StudyControllerTests method testAddParticipant.
@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study/study-after-updating-description.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-participant-after-add.xml", assertionMode = NON_STRICT) })
public void testAddParticipant() throws Exception {
AddStudyParticipantDTO participantDTO = new AddStudyParticipantDTO();
participantDTO.setUserId(USER_2_UUID);
participantDTO.setRole(CONTRIBUTOR);
mvc.perform(post("/api/v1/study-management/studies/" + STUDY_ID + "/participants").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(participantDTO))).andExpect(NO_ERROR_CODE).andReturn();
}
use of com.odysseusinc.arachne.portal.api.v1.dto.AddStudyParticipantDTO in project ArachneCentralAPI by OHDSI.
the class StudyControllerTests method testAddExistedParticipant.
@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study/study-participant.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-participant.xml", assertionMode = NON_STRICT) })
public void testAddExistedParticipant() throws Exception {
AddStudyParticipantDTO participantDTO = new AddStudyParticipantDTO();
participantDTO.setUserId(USER_2_UUID);
participantDTO.setRole(CONTRIBUTOR);
mvc.perform(post("/api/v1/study-management/studies/" + STUDY_ID + "/participants").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(participantDTO))).andExpect(jsonPath("$.errorCode").value(ALREADY_EXIST.getCode()));
}
Aggregations