2.17.2: 2011-06-17

net.sf.basedb.core
Class ProjectPermissions

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

public final class ProjectPermissions
extends Object

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

Don't forget to commit the transaction.

NOTE! As of BASE 2.6 this class is final because of a security issue. Existing code that has subclassed this class will no longer work. There is no workaround.

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

Field Summary
private  Map<ProjectData,Integer> originalPermissions
           
private  Map<ProjectData,Integer> projectPermissions
           
 
Constructor Summary
ProjectPermissions()
          Create a new empty object.
ProjectPermissions(ProjectKey projectKey)
          Create a new object, and initialise it with the permissions from a ProjectKey.
 
Method Summary
 void addPermissions(Project project, Set<Permission> permissions)
          Grant permissions to a project, keeping those that have already been set.
(package private)  Map<ProjectData,Integer> getOriginalPermissions()
          Get the internal representation of the original permissions.
 Set<Permission> getOriginalPermissions(Project project)
          Get the original permissions for a project if this object was created with the ProjectPermissions(ProjectKey) constructor.
 Set<Permission> getPermissions(Project project)
          Get the permissions for a project.
(package private)  Map<ProjectData,Integer> getProjectPermissions()
          Get the internal representation of the permissions.
 boolean hasChanged(Project project)
          Check if the current permissions for the project has been changed from the original permissions.
 void merge(ProjectKey projectKey)
          Merge the permissions for all projects from the given project key with the permissions in this object.
 void setPermissions(Project project, Set<Permission> permissions)
          Grant permissions to a project.
 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

projectPermissions

private final Map<ProjectData,Integer> projectPermissions

originalPermissions

private final Map<ProjectData,Integer> originalPermissions
Constructor Detail

ProjectPermissions

public ProjectPermissions()
Create a new empty object.


ProjectPermissions

public ProjectPermissions(ProjectKey projectKey)
                   throws InvalidDataException
Create a new object, and initialise it with the permissions from a ProjectKey.

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

merge

public void merge(ProjectKey projectKey)
Merge the permissions for all projects from the given project key with the permissions in this object. If the project key contains permissions for a project that already has permissions in this object the permissions are combined (added) to create a new permission.

Parameters:
projectKey - A project key (if null, this method simply returns)
Since:
2.16

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:
PermissionDeniedException - If the logged in user doesn't have Permission.USE permission for the project
InvalidDataException - If the project is null
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:
PermissionDeniedException - If the logged in user doesn't have Permission.USE permission for the project
InvalidDataException - If the project is null
See Also:
Permission

getPermissions

public Set<Permission> getPermissions(Project project)
                               throws InvalidDataException
Get the permissions for a project.

Parameters:
project - The Project 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 project is null
See Also:
getOriginalPermissions(Project), Permission

getOriginalPermissions

public Set<Permission> getOriginalPermissions(Project project)
Get the original permissions for a project if this object was created with the ProjectPermissions(ProjectKey) constructor.

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

hasChanged

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

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

size

public int size()
Get the number of entries.


getProjectPermissions

final Map<ProjectData,Integer> getProjectPermissions()
Get the internal representation of the permissions.


getOriginalPermissions

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

Since:
2.6

2.17.2: 2011-06-17