From 5418cb05242790ed882af5ebf4a8a6ad443b5740 Mon Sep 17 00:00:00 2001 From: Julien Iguchi-Cartigny Date: Sun, 17 Jul 2016 17:40:18 +0200 Subject: [PATCH] Javadoc of API is specified --- src/main/java/fr/plil/sio/persistence/api/Group.java | 18 ++++++++++++++++++ src/main/java/fr/plil/sio/persistence/api/GroupService.java | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- src/main/java/fr/plil/sio/persistence/api/Right.java | 5 ++++- src/main/java/fr/plil/sio/persistence/api/RightService.java | 44 ++++++++++++++++++++++++++++++++++++++++++-- src/main/java/fr/plil/sio/persistence/api/User.java | 9 --------- src/main/java/fr/plil/sio/persistence/api/UserService.java | 38 +++++++++++++++++++++++++++++++++++--- src/main/java/fr/plil/sio/persistence/jdbc/GroupServiceJdbc.java | 12 +++++------- src/main/java/fr/plil/sio/persistence/jdbc/RightServiceJdbc.java | 11 +++++++++-- src/main/java/fr/plil/sio/persistence/jdbc/UserServiceJdbc.java | 14 +++++--------- 9 files changed, 179 insertions(+), 38 deletions(-) diff --git a/src/main/java/fr/plil/sio/persistence/api/Group.java b/src/main/java/fr/plil/sio/persistence/api/Group.java index 1457cd3..d9cf671 100644 --- a/src/main/java/fr/plil/sio/persistence/api/Group.java +++ b/src/main/java/fr/plil/sio/persistence/api/Group.java @@ -1,5 +1,7 @@ package fr.plil.sio.persistence.api; +import java.util.LinkedList; +import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -9,8 +11,24 @@ public class Group { private String name; + /** + * Users in the group. + */ private Set users = new TreeSet<>(); + /** + * List of rights. The list CANNOT contains duplicate rights. + */ + private List rights = new LinkedList<>(); + + public List getRights() { + return rights; + } + + public void setRights(List rights) { + this.rights = rights; + } + public Long getId() { return id; } diff --git a/src/main/java/fr/plil/sio/persistence/api/GroupService.java b/src/main/java/fr/plil/sio/persistence/api/GroupService.java index f8d9cae..c059914 100644 --- a/src/main/java/fr/plil/sio/persistence/api/GroupService.java +++ b/src/main/java/fr/plil/sio/persistence/api/GroupService.java @@ -2,17 +2,73 @@ package fr.plil.sio.persistence.api; public interface GroupService { + /** + * Create a group with a specific name in the database. + * There is no two groups with the same name in the database. + * + * @param name the name of the group + * @return an instance of the group + * @throws IllegalArgumentException if name is null + * @throws IllegalStateException if a group with the same name is already present + */ Group create(String name); - boolean delete(Group group); + /** + * Delete a group in the database. Remove all users in the group. + * + * @param name the name of the group to remove + * @return true if group has been deleted, false if group is not found in the database. + * @throws IllegalArgumentException if name is null + */ + boolean delete(String name); + /** + * Find a group in the database based on its name. + * + * @param name the name of the group to search for. + * @return an instance of the group if found, else null. + * @throws IllegalArgumentException if name is null + */ Group findByName(String name); - boolean addUser(Group group, User user); + /** + * Add an user in the group. + * + * @param groupName the name of the group. + * @param userName the name of the user to add in the group. + * @return true if user is added in the group, false if user was already present. + * @throws IllegalArgumentException if groupName or userName is null, or if group or user cannot be found. + */ + boolean addUser(String groupName, String userName); - boolean removeUser(Group group, User user); + /** + * Remove an user in the group. + * + * @param groupName the name of the group. + * @param userName the name of the user to remove from the group. + * @return true if user is removed from the group, false if user was not present in the group. + * @throws IllegalArgumentException if groupName or userName is null, or if group or user cannot be found. + */ + boolean removeUser(String groupName, String userName); - boolean addRight(Group group, Right right); + /** + * Add a right in the group. Right is inserted at the end of rights list of the group. + * + * @param groupName the name of the group. + * @param right the right to add + * @return true if right is added in the group, false if right was already present. + * @throws IllegalStateException if a parent right is already present + * @throws IllegalArgumentException if groupName or right is null, or if group or right cannot be found. + */ + boolean addRight(String groupName, Right right); - boolean removeRight(Group group, Right right); + /** + * Remove a right associated with a group. + * + * @param groupName the name of the group. + * @param right the right to remove + * @return true if right is removed from the group, false if teh right was not present in the group. + * @throws IllegalArgumentException if groupName or right is null, or if group or right cannot be found. + */ + boolean removeRight(String groupName, Right right); } diff --git a/src/main/java/fr/plil/sio/persistence/api/Right.java b/src/main/java/fr/plil/sio/persistence/api/Right.java index 468bcbb..cc7ef4e 100644 --- a/src/main/java/fr/plil/sio/persistence/api/Right.java +++ b/src/main/java/fr/plil/sio/persistence/api/Right.java @@ -1,5 +1,6 @@ package fr.plil.sio.persistence.api; +import java.util.HashSet; import java.util.Set; public class Right { @@ -8,9 +9,11 @@ public class Right { private String name; + /// the parent group private Right parent; - private Set siblings; + /// the sibling group(s), eventually empty + private Set siblings = new HashSet<>(); public Set getSiblings() { return siblings; diff --git a/src/main/java/fr/plil/sio/persistence/api/RightService.java b/src/main/java/fr/plil/sio/persistence/api/RightService.java index e57437e..8379d85 100644 --- a/src/main/java/fr/plil/sio/persistence/api/RightService.java +++ b/src/main/java/fr/plil/sio/persistence/api/RightService.java @@ -1,12 +1,52 @@ package fr.plil.sio.persistence.api; +import java.util.List; + public interface RightService { + /** + * Create a parent right with a specific name in the database. + * It is possible that two rights has the same name. + * + * @param name the name of the right + * @throws IllegalArgumentException if name is null + */ Right create(String name); + /** + * Create a sibling right attached to a parent right with a specific name in the database. + * It is possible that two rights has the same name. + * + * @param name the name of the right + * @param parent the parent right + * @throws IllegalArgumentException if name or parent is null, or if parent does not exist in the database. + */ Right create(String name, Right parent); - boolean delete(Right group); + /** + * Delete a right in the database. + * + * @param right the right to delete + * @return true if right has been deleted + * @throws IllegalArgumentException if right is null or if right is not found in the database. + */ + boolean delete(Right right); + + /** + * Find a list of rights in the database based on their name. + * + * @param name the name of the rights to search for. + * @return A list of rights, eventually empty. + * @throws IllegalArgumentException if name is null + */ + List findByName(String name); - Right findByName(String name); + /** + * Find a right in the database based on its id. + * + * @param id the name of the right to search for. + * @return an instance of the right if found, else null. + * @throws IllegalArgumentException if id is null + */ + Right findOne(Long id); } diff --git a/src/main/java/fr/plil/sio/persistence/api/User.java b/src/main/java/fr/plil/sio/persistence/api/User.java index b2bf6dc..cbc3f27 100644 --- a/src/main/java/fr/plil/sio/persistence/api/User.java +++ b/src/main/java/fr/plil/sio/persistence/api/User.java @@ -1,16 +1,7 @@ package fr.plil.sio.persistence.api; -import javax.annotation.Generated; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity public class User { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String name; diff --git a/src/main/java/fr/plil/sio/persistence/api/UserService.java b/src/main/java/fr/plil/sio/persistence/api/UserService.java index 20b3813..63e47a8 100644 --- a/src/main/java/fr/plil/sio/persistence/api/UserService.java +++ b/src/main/java/fr/plil/sio/persistence/api/UserService.java @@ -2,11 +2,43 @@ package fr.plil.sio.persistence.api; public interface UserService { - User create(String name); + /** + * Create an user with a specific name in the database and affected to an existing group. + * There is no two users with the same name in the database. + * + * @param name the name of the user + * @return an instance of the user + * @throws IllegalArgumentException if name or groupName is null, or if group does not exist. + * @throws IllegalStateException if an user with the same name is already present + */ + User create(String name, String groupName); - boolean delete(User user); + /** + * Delete an user in the database. + * + * @param name the name of the user to remove + * @return true if user has been deleted, false if user is not found in the database. + * @throws IllegalArgumentException if name is null + */ + boolean delete(String name); + /** + * Find an user in the database based on its name. + * + * @param name the name of the user to search for. + * @return an instance of the user if found, else null. + * @throws IllegalArgumentException if name is null + */ User findByName(String name); - boolean isUserHasRight(User user, Right right); + /** + * Check method to control if an user has a specific right. The following rule is used: an user has a specific + * right if the group where the user is contains the specific right or one of its parents. + * + * @param userName the name of the user + * @param right the specific right + * @return true if the group where the user is contains the specific right or one of its parents, false else. + * @throws IllegalArgumentException if userName or right is null, or if the user or right does not exist in the db. + */ + boolean isUserHasRight(String userName, Right right); } diff --git a/src/main/java/fr/plil/sio/persistence/jdbc/GroupServiceJdbc.java b/src/main/java/fr/plil/sio/persistence/jdbc/GroupServiceJdbc.java index a0af9d0..3908935 100644 --- a/src/main/java/fr/plil/sio/persistence/jdbc/GroupServiceJdbc.java +++ b/src/main/java/fr/plil/sio/persistence/jdbc/GroupServiceJdbc.java @@ -3,7 +3,6 @@ package fr.plil.sio.persistence.jdbc; import fr.plil.sio.persistence.api.Group; import fr.plil.sio.persistence.api.GroupService; import fr.plil.sio.persistence.api.Right; -import fr.plil.sio.persistence.api.User; import org.springframework.stereotype.Service; @Service @@ -14,7 +13,7 @@ public class GroupServiceJdbc implements GroupService { } @Override - public boolean delete(Group group) { + public boolean delete(String name) { return false; } @@ -24,23 +23,22 @@ public class GroupServiceJdbc implements GroupService { } @Override - public boolean addUser(Group group, User user) { + public boolean addUser(String groupName, String userName) { return false; } @Override - public boolean removeUser(Group group, User user) { + public boolean removeUser(String groupName, String userName) { return false; } @Override - public boolean addRight(Group group, Right right) { + public boolean addRight(String groupName, Right right) { return false; - } @Override - public boolean removeRight(Group group, Right right) { + public boolean removeRight(String groupName, Right right) { return false; } } 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 0d69789..a57b8c6 100644 --- a/src/main/java/fr/plil/sio/persistence/jdbc/RightServiceJdbc.java +++ b/src/main/java/fr/plil/sio/persistence/jdbc/RightServiceJdbc.java @@ -4,6 +4,8 @@ import fr.plil.sio.persistence.api.Right; import fr.plil.sio.persistence.api.RightService; import org.springframework.stereotype.Service; +import java.util.List; + @Service public class RightServiceJdbc implements RightService{ @Override @@ -17,12 +19,17 @@ public class RightServiceJdbc implements RightService{ } @Override - public boolean delete(Right group) { + public boolean delete(Right right) { return false; } @Override - public Right findByName(String name) { + public List findByName(String name) { + return null; + } + + @Override + public Right findOne(Long id) { return null; } } diff --git a/src/main/java/fr/plil/sio/persistence/jdbc/UserServiceJdbc.java b/src/main/java/fr/plil/sio/persistence/jdbc/UserServiceJdbc.java index 2f52bc9..1ec0396 100644 --- a/src/main/java/fr/plil/sio/persistence/jdbc/UserServiceJdbc.java +++ b/src/main/java/fr/plil/sio/persistence/jdbc/UserServiceJdbc.java @@ -13,17 +13,12 @@ public class UserServiceJdbc implements UserService { private UserRepository userRepository; @Override - public User create(String name) { + public User create(String name, String groupName) { return null; } @Override - public boolean delete(User user) { - return false; - } - - @Override - public boolean isUserHasRight(User user, Right right) { + public boolean delete(String name) { return false; } @@ -32,7 +27,8 @@ public class UserServiceJdbc implements UserService { return null; } - public void setUserRepository(UserRepository userRepository) { - this.userRepository = userRepository; + @Override + public boolean isUserHasRight(String userName, Right right) { + return false; } } -- libgit2 0.21.2