@RequestMapping(value="/identity/users/{userId}/info", method = RequestMethod.POST, produces = "application/json")
public UserInfoResponse setUserInfo(@PathVariable String userId, @RequestBody UserInfoRequest userRequest,
HttpServletRequest request, HttpServletResponse response) {
User user = getUserFromRequest(userId);
if (userRequest.getKey() == null) {
throw new ActivitiIllegalArgumentException("The key cannot be null.");
}
if (userRequest.getValue() == null) {
throw new ActivitiIllegalArgumentException("The value cannot be null.");
}
String existingValue = identityService.getUserInfo(user.getId(), userRequest.getKey());
if (existingValue != null) {
throw new ActivitiConflictException("User info with key '" + userRequest.getKey() + "' already exists for this user.");
}
identityService.setUserInfo(user.getId(), userRequest.getKey(), userRequest.getValue());
response.setStatus(HttpStatus.CREATED.value());
String serverRootUrl = request.getRequestURL().toString();
serverRootUrl = serverRootUrl.substring(0, serverRootUrl.indexOf("/identity/users/"));
return restResponseFactory.createUserInfoResponse(userRequest.getKey(), userRequest.getValue(), user.getId(), serverRootUrl);
}