Commit a54db7eba504f2cf355f64e6c4f8d44ef4f5c646

Authored by msahmane
1 parent 74b95d8e

Ajout des fichiers Repository et RepositoryJdbc pour le user et les right ainsi que les requetes sql

src/main/java/fr/plil/sio/persistence/jdbc/RightServiceJdbc.java
... ... @@ -2,20 +2,49 @@ package fr.plil.sio.persistence.jdbc;
2 2  
3 3 import fr.plil.sio.persistence.api.Right;
4 4 import fr.plil.sio.persistence.api.RightService;
  5 +import fr.plil.sio.persistence.api.User;
5 6 import org.springframework.stereotype.Service;
6 7  
7 8 import java.util.List;
  9 +import org.springframework.beans.factory.annotation.Autowired;
8 10  
9 11 @Service
10 12 public class RightServiceJdbc implements RightService {
  13 +
  14 + @Autowired
  15 + private RightRepository rightRepository;
  16 +
  17 +
11 18 @Override
12 19 public Right create(String name) {
13   - return null;
  20 + if (name == null) {
  21 + throw new IllegalArgumentException("name cannot be null");
  22 + }
  23 + Right right = rightRepository.findByName(name);
  24 + if (right != null) {
  25 + throw new IllegalStateException("a group with the same name already exists");
  26 + }
  27 + right = new Right();
  28 + right.setName(name);
  29 + rightRepository.save(right);
  30 + return right;
14 31 }
15 32  
16 33 @Override
17 34 public Right create(String name, Right parent) {
18   - throw new IllegalStateException("not implemented !");
  35 + if(name == null || parent == null)
  36 + throw new IllegalArgumentException("Name cannot be null");
  37 +
  38 + Right right = rightRepository.findByName(parent.getName());
  39 + if(right != null)
  40 + throw new IllegalStateException("A right with the same name already exists");
  41 +
  42 + right = new Right();
  43 + right.setName(name);
  44 + rightRepository.save(right);
  45 +
  46 + return right;
  47 +
19 48 }
20 49  
21 50 @Override
... ...