From a54db7eba504f2cf355f64e6c4f8d44ef4f5c646 Mon Sep 17 00:00:00 2001 From: msahmane Date: Mon, 19 Sep 2016 12:08:19 +0200 Subject: [PATCH] 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 | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/plil/sio/persistence/jdbc/RightServiceJdbc.java b/src/main/java/fr/plil/sio/persistence/jdbc/RightServiceJdbc.java index b1242a1..6f2a66c 100644 --- a/src/main/java/fr/plil/sio/persistence/jdbc/RightServiceJdbc.java +++ b/src/main/java/fr/plil/sio/persistence/jdbc/RightServiceJdbc.java @@ -2,20 +2,49 @@ package fr.plil.sio.persistence.jdbc; import fr.plil.sio.persistence.api.Right; import fr.plil.sio.persistence.api.RightService; +import fr.plil.sio.persistence.api.User; import org.springframework.stereotype.Service; import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; @Service public class RightServiceJdbc implements RightService { + + @Autowired + private RightRepository rightRepository; + + @Override public Right create(String name) { - return null; + if (name == null) { + throw new IllegalArgumentException("name cannot be null"); + } + Right right = rightRepository.findByName(name); + if (right != null) { + throw new IllegalStateException("a group with the same name already exists"); + } + right = new Right(); + right.setName(name); + rightRepository.save(right); + return right; } @Override public Right create(String name, Right parent) { - throw new IllegalStateException("not implemented !"); + if(name == null || parent == null) + throw new IllegalArgumentException("Name cannot be null"); + + Right right = rightRepository.findByName(parent.getName()); + if(right != null) + throw new IllegalStateException("A right with the same name already exists"); + + right = new Right(); + right.setName(name); + rightRepository.save(right); + + return right; + } @Override -- libgit2 0.21.2