2.17.2: 2011-06-17

net.sf.basedb.core
Class UserPermissions

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

public class UserPermissions
extends Object

This class is used to specify permissions to share an item to users. It is a three-step procedure:

Don't forget to commit the transaction.

Version:
2.0
Author:
Nicklas
See Also:
ItemKey, GroupPermissions, ProjectPermissions
Last modified
$Date: 2010-06-22 14:51:41 +0200 (Tue, 22 Jun 2010) $

Field Summary
private  Map<UserData,Integer> originalPermissions
           
private  Map<UserData,Integer> userPermissions
           
 
Constructor Summary
UserPermissions()
          Create a new empty object.
UserPermissions(ItemKey itemKey)
          Create a new object, and initialise it with the permissions from a ItemKey.
 
Method Summary
 void addPermissions(User user, Set<Permission> permissions)
          Grant permissions to a user, keeping those that have already been set.
(package private)  Map<UserData,Integer> getOriginalPermissions()
          Get the internal representation of the original permissions.
 Set<Permission> getOriginalPermissions(User user)
          Get the original permissions for a user if this object was created with the UserPermissions(ItemKey) constructor.
 Set<Permission> getPermissions(User user)
          Get the permissions for a user.
(package private)  Map<UserData,Integer> getUserPermissions()
          Get the internal representation of the permissions.
 boolean hasChanged(User user)
          Check if the current permissions for the user has been changed from the original permissions.
 void merge(ItemKey itemKey)
          Merge the permissions for all users from the given item key with the permissions in this object.
 void setPermissions(User user, Set<Permission> permissions)
          Grant permissions to a user.
 int size()
          Get the number of entries.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

userPermissions

private final Map<UserData,Integer> userPermissions

originalPermissions

private final Map<UserData,Integer> originalPermissions
Constructor Detail

UserPermissions

public UserPermissions()
Create a new empty object.


UserPermissions

public UserPermissions(ItemKey itemKey)
                throws InvalidDataException
Create a new object, and initialise it with the permissions from a ItemKey.

Parameters:
itemKey - The item key from which we take the current permissions
Throws:
InvalidDataException - If the item key is null
Method Detail

merge

public void merge(ItemKey itemKey)
Merge the permissions for all users from the given item key with the permissions in this object. If the item key contains permissions for a user that already has permissions in this object the permissions are combined (added) to create a new permission.

Parameters:
itemKey - An item key (if null, this method simply returns)
Since:
2.16

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 Set<Permission> getPermissions(User user)
                               throws InvalidDataException
Get the permissions for a user.

Parameters:
user - The User for which we want to get the permission
Returns:
An Set containing the granted permissions, or an empty set if no permissions have been granted
Throws:
InvalidDataException - If the user is null
See Also:
getOriginalPermissions(User), Permission

getOriginalPermissions

public Set<Permission> getOriginalPermissions(User user)
Get the original permissions for a user if this object was created with the UserPermissions(ItemKey) constructor.

Parameters:
user - The User for which we want to get the permission
Returns:
An Set containing the original permissions, or an empty set
Throws:
InvalidDataException - If the user is null
Since:
2.6
See Also:
getPermissions(User)

hasChanged

public boolean hasChanged(User user)
Check if the current permissions for the user has been changed from the original permissions. This method will return false if the getPermissions(User) returns a set with the same permissions getOriginalPermissions(User).

Parameters:
user - The user to check
Returns:
TRUE if the permissions have changed, FALSE otherwise
Throws:
InvalidDataException - If the user is null
Since:
2.6

size

public int size()
Get the number of entries.


getUserPermissions

final Map<UserData,Integer> getUserPermissions()
Get the internal representation of the permissions.


getOriginalPermissions

final Map<UserData,Integer> getOriginalPermissions()
Get the internal representation of the original permissions.

Since:
2.6

2.17.2: 2011-06-17