Blame view

src/main/java/fr/plil/sio/persistence/jdbc/RightServiceJdbc.java 1.85 KB
a800fde0   jcartign   First version, in...
1
2
3
4
5
6
  package fr.plil.sio.persistence.jdbc;
  
  import fr.plil.sio.persistence.api.Right;
  import fr.plil.sio.persistence.api.RightService;
  import org.springframework.stereotype.Service;
  
5418cb05   jcartign   Javadoc of API is...
7
  import java.util.List;
e1ed8749   Rémi Vangrevelynghe   save before merge
8
  import org.springframework.beans.factory.annotation.Autowired;
5418cb05   jcartign   Javadoc of API is...
9
  
a800fde0   jcartign   First version, in...
10
  @Service
292aec6f   jcartign   First version bef...
11
  public class RightServiceJdbc implements RightService {
ef4eb263   rvangrev   Nouvelles modific...
12
      
e1ed8749   Rémi Vangrevelynghe   save before merge
13
14
15
16
      @Autowired
      private GroupRepository groupRepository;
      private RightRepository rightRepository;
      
a800fde0   jcartign   First version, in...
17
18
      @Override
      public Right create(String name) {
ef4eb263   rvangrev   Nouvelles modific...
19
20
21
          if(name==null){
              throw new IllegalArgumentException("name cannot be null");
          }
e1ed8749   Rémi Vangrevelynghe   save before merge
22
23
24
25
          Right right = new Right();
          right.setName(name);
          if(right==null){
              throw new IllegalArgumentException("name cannot be null");
ef4eb263   rvangrev   Nouvelles modific...
26
          }
e1ed8749   Rémi Vangrevelynghe   save before merge
27
28
          rightRepository.save(right);
          return right;
a800fde0   jcartign   First version, in...
29
30
31
32
      }
  
      @Override
      public Right create(String name, Right parent) {
e1ed8749   Rémi Vangrevelynghe   save before merge
33
34
35
36
37
38
39
40
41
42
43
          if(name==null || parent.getId()==null){
              throw new IllegalArgumentException("name cannot be null");
          }
          Right right = new Right();
          right.setName(name);
          right.setParent(parent);
          if(right==null){
              throw new IllegalArgumentException("name cannot be null");
          }
          rightRepository.save(right);
          return right;
a800fde0   jcartign   First version, in...
44
45
46
      }
  
      @Override
5418cb05   jcartign   Javadoc of API is...
47
      public boolean delete(Right right) {
ef4eb263   rvangrev   Nouvelles modific...
48
49
50
          if(right==null){
              throw new IllegalArgumentException("name cannot be null");
          }
e1ed8749   Rémi Vangrevelynghe   save before merge
51
52
53
          
          rightRepository.delete(right.getId());
          return true;
a800fde0   jcartign   First version, in...
54
55
56
      }
  
      @Override
5418cb05   jcartign   Javadoc of API is...
57
      public List<Right> findByName(String name) {
292aec6f   jcartign   First version bef...
58
          throw new IllegalStateException("not implemented !");
5418cb05   jcartign   Javadoc of API is...
59
60
61
62
      }
  
      @Override
      public Right findOne(Long id) {
ef4eb263   rvangrev   Nouvelles modific...
63
64
65
66
67
68
          if(id==null){
              throw new IllegalArgumentException("name cannot be null");
          }
          else{
              return null;
          }
a800fde0   jcartign   First version, in...
69
70
      }
  }