@Override public User createUser(final User userConfig, final String authKey) throws IOException, IllegalArgumentException { final String userName = userConfig.getUserName(); if (findUserByUserName(userName) != null) { throw UserException.validationError() .message("User [%s] already exists", userName) .build(logger); } validatePassword(authKey); UserConfig newUser = toUserConfig(userConfig) .setUid(new UID(UUID.randomUUID().toString())) .setCreatedAt(System.currentTimeMillis()) .setModifiedAt(userConfig.getCreatedAt()) .setTag(null); UserInfo userInfo = new UserInfo(); userInfo.setConfig(newUser); userInfo.setAuth(buildUserAuth(newUser.getUid(), authKey)); userStore.put(newUser.getUid(), userInfo); // Return the new state return fromUserConfig(newUser); }
userConfig.setModifiedAt(System.currentTimeMillis());
protected UserConfig toUserConfig(User user) { return new UserConfig() .setUid(user.getUID()) .setUserName(user.getUserName()) .setFirstName(user.getFirstName()) .setLastName(user.getLastName()) .setEmail(user.getEmail()) .setCreatedAt(user.getCreatedAt()) .setModifiedAt(user.getModifiedAt()) .setTag(user.getVersion()); }
@Override public User updateUser(final User userGroup, final String authKey) throws IOException, IllegalArgumentException, UserNotFoundException { UserConfig userConfig = toUserConfig(userGroup); final String userName = userConfig.getUserName(); final UserInfo oldUserInfo = findUserByUserName(userName); if (oldUserInfo == null) { throw new UserNotFoundException(userName); } merge(userConfig, oldUserInfo.getConfig()); userConfig.setModifiedAt(System.currentTimeMillis()); UserInfo newUserInfo = new UserInfo(); newUserInfo.setConfig(userConfig); if(authKey != null){ validatePassword(authKey); newUserInfo.setAuth(buildUserAuth(oldUserInfo.getConfig().getUid(), authKey)); } else { newUserInfo.setAuth(oldUserInfo.getAuth()); } userStore.put(userConfig.getUid(), newUserInfo); // Return the new state return fromUserConfig(userConfig); }