@Override public void update(final User user) { if (user == null) { throw new IllegalArgumentException("User can't null"); } if (Strings.isNullOrEmpty(user.getUsername())) { throw new IllegalArgumentException("Username of the user can't be null or empty"); } User old = find(user.getUsername()); String newEncryptPassword = generateEncryptPassword(user); if (!old.getPassword().equals(newEncryptPassword)) { user.setPassword(newEncryptPassword); } mongoDBUtil.execute(userCollectionName, collection -> { collection.updateOne(new Document(usernameKey, user.getUsername()), new Document("$set", new Document(usernameKey, user.getPassword()))); return null; }); cache.put(user.getUsername(), user); }
@Override public void update(final User user) { if (user == null) { throw new IllegalArgumentException("User can't null"); } if (Strings.isNullOrEmpty(user.getUsername())) { throw new IllegalArgumentException("Username of the user can't be null or empty"); } User old = find(user.getUsername()); String newEncryptPassword = generateEncryptPassword(user); if (!old.getPassword().equals(newEncryptPassword)) { user.setPassword(newEncryptPassword); } mongoDBUtil.execute(userCollectionName, collection -> { collection.updateOne(new Document(usernameKey, user.getUsername()), new Document("$set", new Document(usernameKey, user.getPassword()))); return null; }); cache.put(user.getUsername(), user); }