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) { 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) { 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 public boolean delete(Right right) { throw new IllegalStateException("not implemented !"); } @Override public List findByName(String name) { throw new IllegalStateException("not implemented !"); } @Override public Right findOne(Long id) { throw new IllegalStateException("not implemented !"); } }