Advertisement
Guest User

Oleksandr Loushkin

a guest
Sep 13th, 2015
11,690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. package ua.com.lavi.billing.service.impl;
  2.  
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.data.domain.Page;
  5. import org.springframework.data.domain.Pageable;
  6. import org.springframework.stereotype.Service;
  7. import org.springframework.transaction.annotation.Transactional;
  8. import ua.com.lavi.billing.core.utils.PasswordEncryption;
  9. import ua.com.lavi.billing.dao.repositories.TokenRepository;
  10. import ua.com.lavi.billing.domain.entities.Token;
  11. import ua.com.lavi.billing.service.TokenService;
  12.  
  13. import java.util.Date;
  14. import java.util.List;
  15. import java.util.UUID;
  16.  
  17. /**
  18.  * Created by lavi on 29.03.2015.
  19.  */
  20. @Service
  21. public class TokenServiceImpl implements TokenService {
  22.  
  23.     @Autowired
  24.     TokenRepository tokenRepository;
  25.  
  26.     @Override
  27.     @Transactional
  28.     public Token getTokenByKey(String tokenKey) {
  29.         return tokenRepository.findByKey(tokenKey);
  30.     }
  31.  
  32.     @Transactional
  33.     public List<Token> getTokens() {
  34.         return tokenRepository.findAll();
  35.     }
  36.  
  37.     @Override
  38.     @Transactional
  39.     public void addToken(Token token) {
  40.         tokenRepository.saveAndFlush(token);
  41.     }
  42.  
  43.     @Override
  44.     public Token generateToken(Date expiredDate) {
  45.         Token token = new Token();
  46.         token.setExpired(expiredDate);
  47.         token.setCreated(new Date());
  48.         token.setKey(UUID.randomUUID().toString().toUpperCase());
  49.         token.setToken(PasswordEncryption.encrypt(String.valueOf(System.nanoTime())));
  50.         return token;
  51.     }
  52.  
  53.     @Override
  54.     @Transactional
  55.     public void updateLastLoginByCurrentDate(Token token) {
  56.         token.setLastUsed(new Date());
  57.         tokenRepository.saveAndFlush(token);
  58.     }
  59.  
  60.     @Override
  61.     @Transactional
  62.     public void updateToken(Token token) {
  63.         tokenRepository.saveAndFlush(token);
  64.     }
  65.  
  66.     @Transactional
  67.     public void deleteToken(Integer tokenId) {
  68.         tokenRepository.delete(tokenId);
  69.     }
  70.  
  71.     @Transactional
  72.     public Page<Token> getTokens(Pageable pageable) {
  73.         return tokenRepository.findAll(pageable);
  74.     }
  75.  
  76.     @Override
  77.     @Transactional
  78.     public Token getTokenById(Integer tokenId) {
  79.         return tokenRepository.findOne(tokenId);
  80.     }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement