Search in sources :

Example 1 with UserProfileGeneralDTO

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

the class BaseUserController method saveProfile.

@ApiOperation("Save user profile")
@RequestMapping(value = "/api/v1/user-management/users/profile", method = POST)
public JsonResult<UserProfileDTO> saveProfile(Principal principal, @RequestBody @Valid UserProfileGeneralDTO dto, BindingResult binding) throws IllegalAccessException, SolrServerException, IOException, NotExistException, NoSuchFieldException {
    JsonResult<UserProfileDTO> result;
    IUser owner = userService.getByEmail(principal.getName());
    if (binding.hasErrors()) {
        result = new JsonResult<>(VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        U user = convertUserProfileGeneralDTO(dto);
        user.setId(owner.getId());
        user = userService.update(user);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(conversionService.convert(user, UserProfileDTO.class));
    }
    return result;
}
Also used : UserProfileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserProfileDTO) IUser(com.odysseusinc.arachne.portal.model.IUser) FieldError(org.springframework.validation.FieldError) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UserProfileGeneralDTO

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

the class UserToUserProfileGeneralDTOConverter method convert.

@Override
public UserProfileGeneralDTO convert(IUser user) {
    UserProfileGeneralDTO dto = new UserProfileGeneralDTO();
    dto.setFirstname(user.getFirstname());
    dto.setMiddlename(user.getMiddlename());
    dto.setLastname(user.getLastname());
    dto.setPersonalSummary(user.getPersonalSummary());
    if (user.getProfessionalType() != null) {
        if (conversionService.canConvert(ProfessionalType.class, CommonProfessionalTypeDTO.class)) {
            dto.setProfessionalType(conversionService.convert(user.getProfessionalType(), CommonProfessionalTypeDTO.class));
        } else {
            throw new NoDTOConverterException("cannot convert ProfessionalType to ProfessionaltypeDTO");
        }
    }
    dto.setPhone(user.getPhone());
    dto.setMobile(user.getMobile());
    dto.setAddress1(user.getAddress1());
    dto.setAddress2(user.getAddress2());
    dto.setCity(user.getCity());
    dto.setStateProvince(conversionService.convert(user.getStateProvince(), StateProvinceDTO.class));
    dto.setZipCode(user.getZipCode());
    dto.setCountry(conversionService.convert(user.getCountry(), CountryDTO.class));
    dto.setAffiliation(user.getAffiliation());
    dto.setContactEmail(user.getContactEmail());
    return dto;
}
Also used : StateProvinceDTO(com.odysseusinc.arachne.portal.api.v1.dto.StateProvinceDTO) UserProfileGeneralDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserProfileGeneralDTO) CommonProfessionalTypeDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonProfessionalTypeDTO) CountryDTO(com.odysseusinc.arachne.portal.api.v1.dto.CountryDTO) NoDTOConverterException(com.odysseusinc.arachne.portal.exception.NoDTOConverterException)

Example 3 with UserProfileGeneralDTO

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

the class UserControllerTests method getUserProfileGeneralDTO.

private UserProfileGeneralDTO getUserProfileGeneralDTO() {
    UserProfileGeneralDTO inputDTO = new UserProfileGeneralDTO();
    inputDTO.setFirstname(UPDATED_FIRST_NAME);
    inputDTO.setLastname(UPDATED_LAST_NAME);
    inputDTO.setMiddlename(UPDATED_MIDDLE_NAME);
    inputDTO.setAffiliation(UPDATED_AFFILIATION);
    inputDTO.setPersonalSummary(UPDATED_PERSONAL_SUMMARY);
    CommonProfessionalTypeDTO professionalTypeDTO = new CommonProfessionalTypeDTO();
    professionalTypeDTO.setId(PROFESSIONAL_TYPE_ID);
    inputDTO.setProfessionalType(professionalTypeDTO);
    return inputDTO;
}
Also used : UserProfileGeneralDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserProfileGeneralDTO) CommonProfessionalTypeDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonProfessionalTypeDTO)

Example 4 with UserProfileGeneralDTO

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

the class UserControllerTests method testUpdate.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/updated-admin-user.xml", assertionMode = NON_STRICT)
public void testUpdate() throws Exception {
    UserProfileGeneralDTO dto = getUserProfileGeneralDTO();
    MvcResult mvcResult = mvc.perform(post("/api/v1/user-management/users/profile").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(dto))).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andReturn();
    JSONObject general = getGeneral(mvcResult);
    JSONAssert.assertEquals(UPDATED_USER_JSON_OBJECT, general, false);
    Assert.assertEquals(PROFESSIONAL_TYPE_ID.intValue(), general.getJSONObject("professionalType").get("id"));
}
Also used : UserProfileGeneralDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserProfileGeneralDTO) JSONObject(org.json.JSONObject) MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Aggregations

UserProfileGeneralDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserProfileGeneralDTO)3 CommonProfessionalTypeDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonProfessionalTypeDTO)2 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)1 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)1 CountryDTO (com.odysseusinc.arachne.portal.api.v1.dto.CountryDTO)1 StateProvinceDTO (com.odysseusinc.arachne.portal.api.v1.dto.StateProvinceDTO)1 UserProfileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserProfileDTO)1 NoDTOConverterException (com.odysseusinc.arachne.portal.exception.NoDTOConverterException)1 IUser (com.odysseusinc.arachne.portal.model.IUser)1 ApiOperation (io.swagger.annotations.ApiOperation)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1 FieldError (org.springframework.validation.FieldError)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1