Commit 5418cb05242790ed882af5ebf4a8a6ad443b5740
1 parent
a800fde0
Javadoc of API is specified
Showing
9 changed files
with
179 additions
and
38 deletions
Show diff stats
src/main/java/fr/plil/sio/persistence/api/Group.java
1 | 1 | package fr.plil.sio.persistence.api; |
2 | 2 | |
3 | +import java.util.LinkedList; | |
4 | +import java.util.List; | |
3 | 5 | import java.util.Set; |
4 | 6 | import java.util.TreeSet; |
5 | 7 | |
... | ... | @@ -9,8 +11,24 @@ public class Group { |
9 | 11 | |
10 | 12 | private String name; |
11 | 13 | |
14 | + /** | |
15 | + * Users in the group. | |
16 | + */ | |
12 | 17 | private Set<User> users = new TreeSet<>(); |
13 | 18 | |
19 | + /** | |
20 | + * List of rights. The list CANNOT contains duplicate rights. | |
21 | + */ | |
22 | + private List<Right> rights = new LinkedList<>(); | |
23 | + | |
24 | + public List<Right> getRights() { | |
25 | + return rights; | |
26 | + } | |
27 | + | |
28 | + public void setRights(List<Right> rights) { | |
29 | + this.rights = rights; | |
30 | + } | |
31 | + | |
14 | 32 | public Long getId() { |
15 | 33 | return id; |
16 | 34 | } | ... | ... |
src/main/java/fr/plil/sio/persistence/api/GroupService.java
... | ... | @@ -2,17 +2,73 @@ package fr.plil.sio.persistence.api; |
2 | 2 | |
3 | 3 | public interface GroupService { |
4 | 4 | |
5 | + /** | |
6 | + * Create a group with a specific name in the database. | |
7 | + * There is no two groups with the same name in the database. | |
8 | + * | |
9 | + * @param name the name of the group | |
10 | + * @return an instance of the group | |
11 | + * @throws IllegalArgumentException if name is null | |
12 | + * @throws IllegalStateException if a group with the same name is already present | |
13 | + */ | |
5 | 14 | Group create(String name); |
6 | 15 | |
7 | - boolean delete(Group group); | |
16 | + /** | |
17 | + * Delete a group in the database. Remove all users in the group. | |
18 | + * | |
19 | + * @param name the name of the group to remove | |
20 | + * @return true if group has been deleted, false if group is not found in the database. | |
21 | + * @throws IllegalArgumentException if name is null | |
22 | + */ | |
23 | + boolean delete(String name); | |
8 | 24 | |
25 | + /** | |
26 | + * Find a group in the database based on its name. | |
27 | + * | |
28 | + * @param name the name of the group to search for. | |
29 | + * @return an instance of the group if found, else null. | |
30 | + * @throws IllegalArgumentException if name is null | |
31 | + */ | |
9 | 32 | Group findByName(String name); |
10 | 33 | |
11 | - boolean addUser(Group group, User user); | |
34 | + /** | |
35 | + * Add an user in the group. | |
36 | + * | |
37 | + * @param groupName the name of the group. | |
38 | + * @param userName the name of the user to add in the group. | |
39 | + * @return true if user is added in the group, false if user was already present. | |
40 | + * @throws IllegalArgumentException if groupName or userName is null, or if group or user cannot be found. | |
41 | + */ | |
42 | + boolean addUser(String groupName, String userName); | |
12 | 43 | |
13 | - boolean removeUser(Group group, User user); | |
44 | + /** | |
45 | + * Remove an user in the group. | |
46 | + * | |
47 | + * @param groupName the name of the group. | |
48 | + * @param userName the name of the user to remove from the group. | |
49 | + * @return true if user is removed from the group, false if user was not present in the group. | |
50 | + * @throws IllegalArgumentException if groupName or userName is null, or if group or user cannot be found. | |
51 | + */ | |
52 | + boolean removeUser(String groupName, String userName); | |
14 | 53 | |
15 | - boolean addRight(Group group, Right right); | |
54 | + /** | |
55 | + * Add a right in the group. Right is inserted at the end of rights list of the group. | |
56 | + * | |
57 | + * @param groupName the name of the group. | |
58 | + * @param right the right to add | |
59 | + * @return true if right is added in the group, false if right was already present. | |
60 | + * @throws IllegalStateException if a parent right is already present | |
61 | + * @throws IllegalArgumentException if groupName or right is null, or if group or right cannot be found. | |
62 | + */ | |
63 | + boolean addRight(String groupName, Right right); | |
16 | 64 | |
17 | - boolean removeRight(Group group, Right right); | |
65 | + /** | |
66 | + * Remove a right associated with a group. | |
67 | + * | |
68 | + * @param groupName the name of the group. | |
69 | + * @param right the right to remove | |
70 | + * @return true if right is removed from the group, false if teh right was not present in the group. | |
71 | + * @throws IllegalArgumentException if groupName or right is null, or if group or right cannot be found. | |
72 | + */ | |
73 | + boolean removeRight(String groupName, Right right); | |
18 | 74 | } | ... | ... |
src/main/java/fr/plil/sio/persistence/api/Right.java
1 | 1 | package fr.plil.sio.persistence.api; |
2 | 2 | |
3 | +import java.util.HashSet; | |
3 | 4 | import java.util.Set; |
4 | 5 | |
5 | 6 | public class Right { |
... | ... | @@ -8,9 +9,11 @@ public class Right { |
8 | 9 | |
9 | 10 | private String name; |
10 | 11 | |
12 | + /// the parent group | |
11 | 13 | private Right parent; |
12 | 14 | |
13 | - private Set<Right> siblings; | |
15 | + /// the sibling group(s), eventually empty | |
16 | + private Set<Right> siblings = new HashSet<>(); | |
14 | 17 | |
15 | 18 | public Set<Right> getSiblings() { |
16 | 19 | return siblings; | ... | ... |
src/main/java/fr/plil/sio/persistence/api/RightService.java
1 | 1 | package fr.plil.sio.persistence.api; |
2 | 2 | |
3 | +import java.util.List; | |
4 | + | |
3 | 5 | public interface RightService { |
4 | 6 | |
7 | + /** | |
8 | + * Create a parent right with a specific name in the database. | |
9 | + * It is possible that two rights has the same name. | |
10 | + * | |
11 | + * @param name the name of the right | |
12 | + * @throws IllegalArgumentException if name is null | |
13 | + */ | |
5 | 14 | Right create(String name); |
6 | 15 | |
16 | + /** | |
17 | + * Create a sibling right attached to a parent right with a specific name in the database. | |
18 | + * It is possible that two rights has the same name. | |
19 | + * | |
20 | + * @param name the name of the right | |
21 | + * @param parent the parent right | |
22 | + * @throws IllegalArgumentException if name or parent is null, or if parent does not exist in the database. | |
23 | + */ | |
7 | 24 | Right create(String name, Right parent); |
8 | 25 | |
9 | - boolean delete(Right group); | |
26 | + /** | |
27 | + * Delete a right in the database. | |
28 | + * | |
29 | + * @param right the right to delete | |
30 | + * @return true if right has been deleted | |
31 | + * @throws IllegalArgumentException if right is null or if right is not found in the database. | |
32 | + */ | |
33 | + boolean delete(Right right); | |
34 | + | |
35 | + /** | |
36 | + * Find a list of rights in the database based on their name. | |
37 | + * | |
38 | + * @param name the name of the rights to search for. | |
39 | + * @return A list of rights, eventually empty. | |
40 | + * @throws IllegalArgumentException if name is null | |
41 | + */ | |
42 | + List<Right> findByName(String name); | |
10 | 43 | |
11 | - Right findByName(String name); | |
44 | + /** | |
45 | + * Find a right in the database based on its id. | |
46 | + * | |
47 | + * @param id the name of the right to search for. | |
48 | + * @return an instance of the right if found, else null. | |
49 | + * @throws IllegalArgumentException if id is null | |
50 | + */ | |
51 | + Right findOne(Long id); | |
12 | 52 | } | ... | ... |
src/main/java/fr/plil/sio/persistence/api/User.java
1 | 1 | package fr.plil.sio.persistence.api; |
2 | 2 | |
3 | -import javax.annotation.Generated; | |
4 | -import javax.persistence.Entity; | |
5 | -import javax.persistence.GeneratedValue; | |
6 | -import javax.persistence.GenerationType; | |
7 | -import javax.persistence.Id; | |
8 | - | |
9 | -@Entity | |
10 | 3 | public class User { |
11 | 4 | |
12 | - @Id | |
13 | - @GeneratedValue(strategy = GenerationType.AUTO) | |
14 | 5 | private Long id; |
15 | 6 | |
16 | 7 | private String name; | ... | ... |
src/main/java/fr/plil/sio/persistence/api/UserService.java
... | ... | @@ -2,11 +2,43 @@ package fr.plil.sio.persistence.api; |
2 | 2 | |
3 | 3 | public interface UserService { |
4 | 4 | |
5 | - User create(String name); | |
5 | + /** | |
6 | + * Create an user with a specific name in the database and affected to an existing group. | |
7 | + * There is no two users with the same name in the database. | |
8 | + * | |
9 | + * @param name the name of the user | |
10 | + * @return an instance of the user | |
11 | + * @throws IllegalArgumentException if name or groupName is null, or if group does not exist. | |
12 | + * @throws IllegalStateException if an user with the same name is already present | |
13 | + */ | |
14 | + User create(String name, String groupName); | |
6 | 15 | |
7 | - boolean delete(User user); | |
16 | + /** | |
17 | + * Delete an user in the database. | |
18 | + * | |
19 | + * @param name the name of the user to remove | |
20 | + * @return true if user has been deleted, false if user is not found in the database. | |
21 | + * @throws IllegalArgumentException if name is null | |
22 | + */ | |
23 | + boolean delete(String name); | |
8 | 24 | |
25 | + /** | |
26 | + * Find an user in the database based on its name. | |
27 | + * | |
28 | + * @param name the name of the user to search for. | |
29 | + * @return an instance of the user if found, else null. | |
30 | + * @throws IllegalArgumentException if name is null | |
31 | + */ | |
9 | 32 | User findByName(String name); |
10 | 33 | |
11 | - boolean isUserHasRight(User user, Right right); | |
34 | + /** | |
35 | + * Check method to control if an user has a specific right. The following rule is used: an user has a specific | |
36 | + * right if the group where the user is contains the specific right or one of its parents. | |
37 | + * | |
38 | + * @param userName the name of the user | |
39 | + * @param right the specific right | |
40 | + * @return true if the group where the user is contains the specific right or one of its parents, false else. | |
41 | + * @throws IllegalArgumentException if userName or right is null, or if the user or right does not exist in the db. | |
42 | + */ | |
43 | + boolean isUserHasRight(String userName, Right right); | |
12 | 44 | } | ... | ... |
src/main/java/fr/plil/sio/persistence/jdbc/GroupServiceJdbc.java
... | ... | @@ -3,7 +3,6 @@ package fr.plil.sio.persistence.jdbc; |
3 | 3 | import fr.plil.sio.persistence.api.Group; |
4 | 4 | import fr.plil.sio.persistence.api.GroupService; |
5 | 5 | import fr.plil.sio.persistence.api.Right; |
6 | -import fr.plil.sio.persistence.api.User; | |
7 | 6 | import org.springframework.stereotype.Service; |
8 | 7 | |
9 | 8 | @Service |
... | ... | @@ -14,7 +13,7 @@ public class GroupServiceJdbc implements GroupService { |
14 | 13 | } |
15 | 14 | |
16 | 15 | @Override |
17 | - public boolean delete(Group group) { | |
16 | + public boolean delete(String name) { | |
18 | 17 | return false; |
19 | 18 | } |
20 | 19 | |
... | ... | @@ -24,23 +23,22 @@ public class GroupServiceJdbc implements GroupService { |
24 | 23 | } |
25 | 24 | |
26 | 25 | @Override |
27 | - public boolean addUser(Group group, User user) { | |
26 | + public boolean addUser(String groupName, String userName) { | |
28 | 27 | return false; |
29 | 28 | } |
30 | 29 | |
31 | 30 | @Override |
32 | - public boolean removeUser(Group group, User user) { | |
31 | + public boolean removeUser(String groupName, String userName) { | |
33 | 32 | return false; |
34 | 33 | } |
35 | 34 | |
36 | 35 | @Override |
37 | - public boolean addRight(Group group, Right right) { | |
36 | + public boolean addRight(String groupName, Right right) { | |
38 | 37 | return false; |
39 | - | |
40 | 38 | } |
41 | 39 | |
42 | 40 | @Override |
43 | - public boolean removeRight(Group group, Right right) { | |
41 | + public boolean removeRight(String groupName, Right right) { | |
44 | 42 | return false; |
45 | 43 | } |
46 | 44 | } | ... | ... |
src/main/java/fr/plil/sio/persistence/jdbc/RightServiceJdbc.java
... | ... | @@ -4,6 +4,8 @@ import fr.plil.sio.persistence.api.Right; |
4 | 4 | import fr.plil.sio.persistence.api.RightService; |
5 | 5 | import org.springframework.stereotype.Service; |
6 | 6 | |
7 | +import java.util.List; | |
8 | + | |
7 | 9 | @Service |
8 | 10 | public class RightServiceJdbc implements RightService{ |
9 | 11 | @Override |
... | ... | @@ -17,12 +19,17 @@ public class RightServiceJdbc implements RightService{ |
17 | 19 | } |
18 | 20 | |
19 | 21 | @Override |
20 | - public boolean delete(Right group) { | |
22 | + public boolean delete(Right right) { | |
21 | 23 | return false; |
22 | 24 | } |
23 | 25 | |
24 | 26 | @Override |
25 | - public Right findByName(String name) { | |
27 | + public List<Right> findByName(String name) { | |
28 | + return null; | |
29 | + } | |
30 | + | |
31 | + @Override | |
32 | + public Right findOne(Long id) { | |
26 | 33 | return null; |
27 | 34 | } |
28 | 35 | } | ... | ... |
src/main/java/fr/plil/sio/persistence/jdbc/UserServiceJdbc.java
... | ... | @@ -13,17 +13,12 @@ public class UserServiceJdbc implements UserService { |
13 | 13 | private UserRepository userRepository; |
14 | 14 | |
15 | 15 | @Override |
16 | - public User create(String name) { | |
16 | + public User create(String name, String groupName) { | |
17 | 17 | return null; |
18 | 18 | } |
19 | 19 | |
20 | 20 | @Override |
21 | - public boolean delete(User user) { | |
22 | - return false; | |
23 | - } | |
24 | - | |
25 | - @Override | |
26 | - public boolean isUserHasRight(User user, Right right) { | |
21 | + public boolean delete(String name) { | |
27 | 22 | return false; |
28 | 23 | } |
29 | 24 | |
... | ... | @@ -32,7 +27,8 @@ public class UserServiceJdbc implements UserService { |
32 | 27 | return null; |
33 | 28 | } |
34 | 29 | |
35 | - public void setUserRepository(UserRepository userRepository) { | |
36 | - this.userRepository = userRepository; | |
30 | + @Override | |
31 | + public boolean isUserHasRight(String userName, Right right) { | |
32 | + return false; | |
37 | 33 | } |
38 | 34 | } | ... | ... |