source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/GroupService.java @ 5553

Last change on this file since 5553 was 5553, checked in by olhsha@mpi.nl, 10 years ago

fixing serialisation issues for List<String>. Adding unit tests for goup service

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