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