1 | package clarin.cmdi.componentregistry.impl.database; |
---|
2 | |
---|
3 | import clarin.cmdi.componentregistry.UserUnauthorizedException; |
---|
4 | import java.util.List; |
---|
5 | |
---|
6 | import org.springframework.transaction.annotation.Transactional; |
---|
7 | |
---|
8 | import clarin.cmdi.componentregistry.model.BaseDescription; |
---|
9 | import clarin.cmdi.componentregistry.model.Group; |
---|
10 | import clarin.cmdi.componentregistry.model.Ownership; |
---|
11 | import clarin.cmdi.componentregistry.model.RegistryUser; |
---|
12 | |
---|
13 | /** |
---|
14 | * Service for handling groups and component/profile ownership |
---|
15 | * @author george.georgovassilis@mpi.nl |
---|
16 | * |
---|
17 | */ |
---|
18 | @Transactional |
---|
19 | public interface GroupService { |
---|
20 | |
---|
21 | /** |
---|
22 | * Creates a new group. Will fail with an exception if the (normalised) group name already exists |
---|
23 | * @param name |
---|
24 | * @param owner |
---|
25 | * @return ID of group created |
---|
26 | * @throws ValidationException |
---|
27 | */ |
---|
28 | long createNewGroup(String name, String ownerPrincipalName); |
---|
29 | |
---|
30 | /** |
---|
31 | * Gets groups directly owned by a user |
---|
32 | * @param ownerPrincipalName |
---|
33 | * @return |
---|
34 | */ |
---|
35 | List<Group> getGroupsOwnedByUser(String ownerPrincipalName); |
---|
36 | |
---|
37 | /** |
---|
38 | * Get list of groups of which the provided user is a member of. Does not include |
---|
39 | * groups he owns but is not a member of. |
---|
40 | * @param principal |
---|
41 | * @return |
---|
42 | */ |
---|
43 | List<Group> getGroupsOfWhichUserIsAMember(String principal); |
---|
44 | |
---|
45 | /** |
---|
46 | * Lists all group names |
---|
47 | * @return |
---|
48 | */ |
---|
49 | List<String> listGroupNames(); |
---|
50 | |
---|
51 | /** |
---|
52 | * Determines whether a user is the direct owner of a group |
---|
53 | * @param groupId |
---|
54 | * @param user |
---|
55 | * @return |
---|
56 | */ |
---|
57 | boolean isUserOwnerOfGroup(long groupId, RegistryUser user); |
---|
58 | |
---|
59 | /** |
---|
60 | * Add an ownership of a user or group to a profile or component. Will check ownership for plausibility and will fail if that ownership already exists. |
---|
61 | * Will not fail if user/group/component/profile IDs don't correspond to an existing entry. |
---|
62 | * @param ownership |
---|
63 | */ |
---|
64 | void addOwnership(Ownership ownership); |
---|
65 | |
---|
66 | /** |
---|
67 | * Removes an existing ownership. Won't complain if the ownership doesn't exist |
---|
68 | * @param ownership |
---|
69 | */ |
---|
70 | void removeOwnership(Ownership ownership); |
---|
71 | |
---|
72 | /** |
---|
73 | * Determines whether a user has read access to a component. Factors that allow access are: |
---|
74 | * 1. The component is public |
---|
75 | * 2. The user is the creator |
---|
76 | * 3. The user has an ownership (see {@link #addOwnership(Ownership)}) |
---|
77 | * 4. The user belongs to a group that has ownership |
---|
78 | * @param user |
---|
79 | * @param baseDescription |
---|
80 | * @return |
---|
81 | */ |
---|
82 | boolean canUserAccessComponentEitherOnHisOwnOrThroughGroupMembership(RegistryUser user, BaseDescription baseDescription); |
---|
83 | |
---|
84 | /** |
---|
85 | * Make a user a mamber of a group |
---|
86 | * @param userName |
---|
87 | * @param groupName |
---|
88 | * @return database ID of group membership row |
---|
89 | */ |
---|
90 | long makeMember(String userName, String groupName); |
---|
91 | |
---|
92 | /** |
---|
93 | * Move ownership of a component or profile from a user to a group |
---|
94 | * @param principal |
---|
95 | * @param groupName |
---|
96 | * @param componentId |
---|
97 | */ |
---|
98 | void transferItemOwnershipFromUserToGroup(String principal, String groupId, String componentId) throws UserUnauthorizedException; |
---|
99 | |
---|
100 | /** |
---|
101 | * Move ownership of a component or profile from a user to a group |
---|
102 | * @param principal |
---|
103 | * @param groupId |
---|
104 | * @param componentId |
---|
105 | */ |
---|
106 | void transferItemOwnershipFromUserToGroupId(String principal, long groupId, String componentId) throws UserUnauthorizedException; |
---|
107 | |
---|
108 | /** |
---|
109 | * Get component IDs in a group |
---|
110 | * @param groupId |
---|
111 | * @return |
---|
112 | */ |
---|
113 | List<String> getComponentIdsInGroup(long groupId); |
---|
114 | |
---|
115 | /** |
---|
116 | * Get a list of groups the item is a member of. While it's technically possible for an item to belong to none, one or multiple groups, the transferXOwnerwhip methods make sure |
---|
117 | * an item belongs only to a single group at most, thus this method returns at most a single group for all practical purposes. |
---|
118 | * @param itemId |
---|
119 | * @return List of groups |
---|
120 | */ |
---|
121 | List<Group> getGroupsTheItemIsAMemberOf(String itemId); |
---|
122 | |
---|
123 | /** |
---|
124 | * Get profile IDs in a group |
---|
125 | * @param groupId |
---|
126 | * @return |
---|
127 | */ |
---|
128 | List<String> getProfileIdsInGroup(long groupId); |
---|
129 | |
---|
130 | boolean userGroupMember(String principalName, String groupId); |
---|
131 | |
---|
132 | } |
---|