Search in sources :

Example 1 with AddStudyParticipantDTO

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

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();
}
Also used : AddStudyParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.AddStudyParticipantDTO) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases)

Example 3 with AddStudyParticipantDTO

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()));
}
Also used : AddStudyParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.AddStudyParticipantDTO) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases)

Aggregations

DatabaseSetups (com.github.springtestdbunit.annotation.DatabaseSetups)2 ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)2 AddStudyParticipantDTO (com.odysseusinc.arachne.portal.api.v1.dto.AddStudyParticipantDTO)2 Test (org.junit.Test)2 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)2 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)1 UpdateNotificationDTO (com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO)1 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)1 IUser (com.odysseusinc.arachne.portal.model.IUser)1 User (com.odysseusinc.arachne.portal.model.User)1 UserStudy (com.odysseusinc.arachne.portal.model.UserStudy)1 ApiOperation (io.swagger.annotations.ApiOperation)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1