SHARE
TWEET

Untitled

a guest Oct 13th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class UserRepositoryCustomImpl implements UserRepositoryCustom {
  2.  
  3.     private final MongoTemplate mongoTemplate;
  4.  
  5.     @Autowired
  6.     public UserRepositoryCustomImpl(MongoTemplate mongoTemplate) {
  7.         this.mongoTemplate = mongoTemplate;
  8.     }
  9.  
  10.     @Override
  11.     public List<User> findAndUpdateByUsernames(Collection<User> users) {
  12.         return users
  13.                 .stream()
  14.                 .map(user -> {
  15.                     Query byUsername = new Query(Criteria.where("username").is(user.getUsername()));
  16.                     Update update = new Update();
  17.  
  18.                     if (user.getAuthorities() != null && user.getAuthorities().size() > 0) {
  19.                         update.set("authorities", user.getAuthorities());
  20.                     }
  21.  
  22.                     return this.mongoTemplate.findAndModify(byUsername,
  23.                                                             update,
  24.                                                             new FindAndModifyOptions().returnNew(true),
  25.                                                             User.class);
  26.                 })
  27.                 .collect(Collectors.toList());
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top