2.17.2: 2011-06-17

net.sf.basedb.core
Class MultiPermissions

java.lang.Object
  extended by net.sf.basedb.core.MultiPermissions

public class MultiPermissions
extends Object

This is a helper class that is very useful when you have a collection of Shareable items and want to modify some permissions on all of them without affecting the rest of the permissions.

For example it is possible to add write permission for a new user while preserving the permissions already given to other user, groups and projects. This works even if the logged in user doesn't have read permission to all other user, groups and projects the items have been shared to.

It is a four-step procedure:

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2010-06-23 14:51:50 +0200 (Wed, 23 Jun 2010) $

Field Summary
private  Map<ItemKey,GroupPermissions> groupPermissions
           
private  Set<SharedItem> items
           
private  Map<ProjectKey,ProjectPermissions> projectPermissions
           
private  Map<ItemKey,UserPermissions> userPermissions
           
 
Constructor Summary
MultiPermissions(Collection<? extends SharedItem> itemsToShare)
          Create a new MultiPermissions object and feed it the collection of Shareable items that you want to modify.
 
Method Summary
 void addPermissions(Group group, Set<Permission> permissions)
          Grant permissions to a group, keeping those that have already been set.
 void addPermissions(Project project, Set<Permission> permissions)
          Grant permissions to a project, keeping those that have already been set.
 void addPermissions(User user, Set<Permission> permissions)
          Grant permissions to a user, keeping those that have already been set.
static boolean allSame(Collection<Set<Permission>> permissions)
          Check if a collection of Set:s all contain the same permissions.
 ItemQuery<Group> getGroups()
          Get a query that returns all groups appearing in at least one of the item keys.
 Set<SharedItem> getItems()
          Returns the items that are handled within this class.
 Set<SharedItem> getItems(Collection<Item> types)
          Get all items of specific item types.
 Set<SharedItem> getItems(Item type)
          Get all items of a specific item type.
 Map<ItemKey,Set<Permission>> getPermissions(Group group)
          Get the permissions for a group.
 Map<ProjectKey,Set<Permission>> getPermissions(Project project)
          Get the permissions for a project.
 Map<ItemKey,Set<Permission>> getPermissions(User user)
          Get the permissions for a user.
 ItemQuery<Project> getProjects()
          Get a query that returns all projects appearing in at least one of the project keys.
 ItemQuery<User> getUsers()
          Get a query that returns all users appearing in at least one of the item keys.
 void merge(ItemKey itemKey)
          Merge the permissions from the given item key keeping those that has already been set.
 void merge(ProjectKey projectKey)
          Merge the permissions from the given project key keeping those that has already been set.
 void setPermissions(Group group, Set<Permission> permissions)
          Grant permissions to a group.
 void setPermissions(Project project, Set<Permission> permissions)
          Grant permissions to a project.
 void setPermissions(User user, Set<Permission> permissions)
          Grant permissions to a user.
 void updateKeys(DbControl dc)
          Generate the new keys and update all items with the new keys.
 void updateKeys(DbControl dc, boolean recursive)
          Generate the new keys and update all items with the new keys.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

items

private final Set<SharedItem> items

userPermissions

private final Map<ItemKey,UserPermissions> userPermissions

groupPermissions

private final Map<ItemKey,GroupPermissions> groupPermissions

projectPermissions

private final Map<ProjectKey,ProjectPermissions> projectPermissions
Constructor Detail

MultiPermissions

public MultiPermissions(Collection<? extends SharedItem> itemsToShare)
                 throws InvalidDataException,
                        BaseException
Create a new MultiPermissions object and feed it the collection of Shareable items that you want to modify.

Parameters:
itemsToShare - The collection of items
Throws:
InvalidDataException - If the collection is null or empty
BaseException - If there is another error
Method Detail

allSame

public static boolean allSame(Collection<Set<Permission>> permissions)
Check if a collection of Set:s all contain the same permissions.

Parameters:
permissions - The collection of sets to check
Returns:
TRUE If all sets in the collection contains the same permissions
See Also:
Permission

setPermissions

public void setPermissions(User user,
                           Set<Permission> permissions)
                    throws InvalidDataException
Grant permissions to a user. Use an empty Set or null to remove all permissions for the user.

Parameters:
user - The User
permissions - The permissions to grant
Throws:
InvalidDataException - If the user is null
See Also:
Permission

addPermissions

public void addPermissions(User user,
                           Set<Permission> permissions)
                    throws InvalidDataException
Grant permissions to a user, keeping those that have already been set.

Parameters:
user - The User
permissions - The permissions to grant
Throws:
InvalidDataException - If the user is null
See Also:
Permission

getPermissions

public Map<ItemKey,Set<Permission>> getPermissions(User user)
                                            throws InvalidDataException
Get the permissions for a user. The returned map contains one entry for each unique ItemKey found among the items passed to the constructor, including the null item key if present. The value of each entry is a Set containing the granted permissions.

Parameters:
user - The User for which we want to get the permission
Returns:
A Map containing a Set of the granted permissions for each ItemKey
Throws:
InvalidDataException - If the user is null
See Also:
Permission

setPermissions

public void setPermissions(Group group,
                           Set<Permission> permissions)
                    throws InvalidDataException
Grant permissions to a group. Use an empty Set or null to remove all permissions for the group.

Parameters:
group - The Group
permissions - The permissions to grant
Throws:
InvalidDataException - If the group is null
See Also:
Permission

addPermissions

public void addPermissions(Group group,
                           Set<Permission> permissions)
                    throws InvalidDataException
Grant permissions to a group, keeping those that have already been set.

Parameters:
group - The Group
permissions - The permissions to grant
Throws:
InvalidDataException - If the group is null
See Also:
Permission

getPermissions

public Map<ItemKey,Set<Permission>> getPermissions(Group group)
                                            throws InvalidDataException
Get the permissions for a group. The returned map contains one entry for each unique ItemKey found among the items passed to the constructor, including the null item key if present. The value of each entry is a Set containing the granted permissions.

Parameters:
group - The Group for which we want to get the permission
Returns:
A Map containing a Set of the granted permissions for each ItemKey
Throws:
InvalidDataException - If the group is null
See Also:
Permission

setPermissions

public void setPermissions(Project project,
                           Set<Permission> permissions)
                    throws PermissionDeniedException,
                           InvalidDataException
Grant permissions to a project. Use an empty Set or null to remove all permissions for the project.

Parameters:
project - The Project
permissions - The permissions to grant
Throws:
InvalidDataException - If the project is null
PermissionDeniedException - If the logged in user's doesn't have Permission.USE permission to the project
See Also:
Permission

addPermissions

public void addPermissions(Project project,
                           Set<Permission> permissions)
                    throws PermissionDeniedException,
                           InvalidDataException
Grant permissions to a project, keeping those that have already been set.

Parameters:
project - The Project
permissions - The permissions to grant
Throws:
InvalidDataException - If the project is null
PermissionDeniedException - If the logged in user's doesn't have Permission.USE permission to the project
See Also:
Permission

getPermissions

public Map<ProjectKey,Set<Permission>> getPermissions(Project project)
                                               throws InvalidDataException
Get the permissions for a project. The returned map contains one entry for each unique ProjectKey found among the items passed to the constructor, including the null project key if present. The value of each entry is a Set containing the granted permissions.

Parameters:
project - The Project for which we want to get the permission
Returns:
A Map containing a Set of the granted permissions for each ProjectKey
Throws:
InvalidDataException - If the project is null
See Also:
Permission

merge

public void merge(ItemKey itemKey)
Merge the permissions from the given item key keeping those that has already been set.

Parameters:
itemKey - An item key (if null, this method simply returns)
Since:
2.16
See Also:
UserPermissions.merge(ItemKey), GroupPermissions.merge(ItemKey)

merge

public void merge(ProjectKey projectKey)
Merge the permissions from the given project key keeping those that has already been set.

Parameters:
projectKey - An project key (if null, this method simply returns)
Since:
2.16
See Also:
ProjectPermissions.merge(ProjectKey)

getUsers

public ItemQuery<User> getUsers()
Get a query that returns all users appearing in at least one of the item keys. The query will not return users that the logged in user doesn't have permission to read.


getGroups

public ItemQuery<Group> getGroups()
Get a query that returns all groups appearing in at least one of the item keys. The query will not return groups that the logged in user doesn't have permission to read.


getProjects

public ItemQuery<Project> getProjects()
Get a query that returns all projects appearing in at least one of the project keys. The query will not return projects that the logged in user doesn't have permission to read.


getItems

public Set<SharedItem> getItems()
Returns the items that are handled within this class.


getItems

public Set<SharedItem> getItems(Item type)
Get all items of a specific item type. The returned set is never null, but may be empty if no items of the specified type was found.

Parameters:
type - The item type to search for
Returns:
A set with the items
Since:
2.8

getItems

public Set<SharedItem> getItems(Collection<Item> types)
Get all items of specific item types. The returned set is never null, but may be empty if no items of the specified types was found.

Parameters:
types - A collection with the item types to search for
Returns:
A set with the items
Since:
2.8

updateKeys

public void updateKeys(DbControl dc)
                throws PermissionDeniedException,
                       BaseException
Generate the new keys and update all items with the new keys.

Parameters:
dc - The DbControl object to use for database access
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.SET_PERMISSION permission on all items
BaseException - If there is another error

updateKeys

public void updateKeys(DbControl dc,
                       boolean recursive)
                throws PermissionDeniedException,
                       BaseException
Generate the new keys and update all items with the new keys.

Parameters:
dc - The DbControl object to use for database access
recursive - If TRUE, files and subdirectories to a selected directory will also shared with the same permissions as the parent directory
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.SET_PERMISSION permission on all items
BaseException - If there is another error
Since:
2.8

2.17.2: 2011-06-17