Search in sources :

Example 1 with UserSettingEntity

use of org.usermanagement.dao.entity.UserSettingEntity in project open-kilda by telstra.

the class UserService method saveOrUpdateSettings.

/**
 * Save or update settings.
 *
 * @param userInfo the user info
 * @return the user info
 */
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public UserInfo saveOrUpdateSettings(UserInfo userInfo) {
    if (ValidatorUtil.isNull(userInfo.getUserId())) {
        LOGGER.warn("Validation failed for user (id: " + userInfo.getUserId() + "). Error: " + messageUtil.getAttributeInvalid("user_id", userInfo.getUserId() + ""));
        throw new RequestValidationException(messageUtil.getAttributeInvalid("user_id", userInfo.getUserId() + ""));
    }
    UserSettingEntity userSettingEntity = userSettingRepository.findOneByUserId(userInfo.getUserId());
    if (userSettingEntity == null) {
        userSettingEntity = new UserSettingEntity();
        userSettingEntity.setUserId(userInfo.getUserId());
    }
    userSettingEntity.setSettings(IConstants.Settings.TOPOLOGY_SETTING);
    userSettingEntity.setData(userInfo.getData());
    userSettingEntity = userSettingRepository.save(userSettingEntity);
    // activityLogger.log(ActivityType.UPDATE_USER_SETTINGS,
    // userInfo.getUserId() + "");
    LOGGER.info("User Settings saved successfully for user(user_id: " + userInfo.getUserId() + ").");
    return userInfo;
}
Also used : UserSettingEntity(org.usermanagement.dao.entity.UserSettingEntity) RequestValidationException(org.usermanagement.exception.RequestValidationException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Transactional (org.springframework.transaction.annotation.Transactional)1 UserSettingEntity (org.usermanagement.dao.entity.UserSettingEntity)1 RequestValidationException (org.usermanagement.exception.RequestValidationException)1