Blame view

src/main/java/fr/plil/sio/persistence/jdbc/UserServiceJdbc.java 1.77 KB
a800fde0   jcartign   First version, in...
1
2
3
  package fr.plil.sio.persistence.jdbc;
  
  import fr.plil.sio.persistence.api.Right;
ef4eb263   rvangrev   Nouvelles modific...
4
  import fr.plil.sio.persistence.api.Group;
a800fde0   jcartign   First version, in...
5
6
7
8
9
10
11
12
13
  import fr.plil.sio.persistence.api.User;
  import fr.plil.sio.persistence.api.UserService;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  @Service
  public class UserServiceJdbc implements UserService {
  
      @Autowired
ef4eb263   rvangrev   Nouvelles modific...
14
15
      private UserRepository userRepository;
      private GroupRepository groupRepository;
a800fde0   jcartign   First version, in...
16
17
  
      @Override
5418cb05   jcartign   Javadoc of API is...
18
      public User create(String name, String groupName) {
ef4eb263   rvangrev   Nouvelles modific...
19
20
21
22
23
24
25
26
27
28
29
30
          if(name==null){
              throw new IllegalArgumentException("name cannot be null");
          }
          User user = userRepository.findByName(name);
          if(user!=null){
              throw new IllegalStateException("a user with the same name already exists");
          }
          user = new User();
          user.setName(name);
          Group group = groupRepository.findByName(groupName);
          userRepository.save(user, group);
          return user;
a800fde0   jcartign   First version, in...
31
32
33
      }
  
      @Override
5418cb05   jcartign   Javadoc of API is...
34
      public boolean delete(String name) {
ef4eb263   rvangrev   Nouvelles modific...
35
36
37
38
39
40
41
42
43
          if(name == null){
              throw new IllegalStateException("not implemented !");
          }
          User user = findByName(name);
          if(user==null){
              return false;
          }
          userRepository.delete(user.getId());
          return true;
a800fde0   jcartign   First version, in...
44
45
46
47
      }
  
      @Override
      public User findByName(String name) {
ef4eb263   rvangrev   Nouvelles modific...
48
49
50
51
          if(name==null){
              throw new IllegalArgumentException("name cannot be null");
          }
          return userRepository.findByName(name);
a800fde0   jcartign   First version, in...
52
53
      }
  
5418cb05   jcartign   Javadoc of API is...
54
55
      @Override
      public boolean isUserHasRight(String userName, Right right) {
ef4eb263   rvangrev   Nouvelles modific...
56
57
58
59
60
61
          if(right==null){
              throw new IllegalArgumentException("name cannot be null");
          }
          else{
              return false;
          }
a800fde0   jcartign   First version, in...
62
63
      }
  }