Class ProjectKey
- java.lang.Object
-
- net.sf.basedb.core.BasicItem
-
- net.sf.basedb.core.Key
-
- net.sf.basedb.core.ProjectKey
-
- All Implemented Interfaces:
AccessControlled
,Identifiable
public class ProjectKey extends Key
This class is used to get information about which projects aShareable
item has been shared to.A project key is immutable and the project/permission combinations cannot be changed once the key has been created. This allows the core to resuse project keys for all items with the same combination of project/permission values without fear that someone else may change the permissions.
Project keys can be used with
Shareable
items to share them with projects. If the logged in user has set an active project (seeSessionControl.setActiveProject(Project)
) new items will automatically be shared to that project.To create a new project key use the
ProjectPermissions
object and pass the information to thegetNewOrExisting(DbControl, ProjectPermissions)
method.Another option is to use the
MultiPermissions
object which allows you to modifiy the sharing information of a whole bunch of shareable items in one go. TheMultiPermissions
class takes care of all the cumbersome work of creating new keys and assigning those to the items for you.- Version:
- 2.0
- Author:
- Nicklas
- See Also:
Shareable
,SessionControl.setActiveProject(Project)
- Last modified
- $Date: 2017-05-22 14:35:27 +0200 (må, 22 maj 2017) $
-
-
Constructor Summary
Constructors Constructor Description ProjectKey(ProjectKeyData projectKeyData)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static int
deleteUnusedProjectKeys()
Delete all keys that are currently not used by any item.static ProjectKey
getById(DbControl dc, int id)
Get aProjectKey
item when you know the ID.(package private) ProjectKeyData
getData()
Get theBasicData
object that holds all data for this item.static ProjectKey
getNewOrExisting(DbControl dc, ProjectPermissions projectPermissions)
Create a new or load an existingProjectKey
when you have a combination of project/permission values.(package private) static int
getNewOrExistingId(Session session, Map<ProjectData,Integer> projectPermissions)
Find the ID of an existing key with exactly the same project/permission combination.Set<Permission>
getPermissions(Project project)
Get the permissions for a project.(package private) PluginPermission
getPluginPermissions()
Set<Integer>
getProjectIds(Permission permission)
Get the ID:s of all projects that are shared with this project key having the specified permission.Item
getType()
Get the type of item represented by the object.Set<ItemProxy>
getUsingItems()
Get all:Shareable
items shared to this key(package private) void
initPermissions(int granted, int denied)
WRITE permission is always denied.boolean
isUsed()
Checks if: AShareable
item is using this key.-
Methods inherited from class net.sf.basedb.core.BasicItem
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, validate
-
-
-
-
Field Detail
-
TYPE
public static final Item TYPE
The type of item represented by this class.- See Also:
Item.PROJECTKEY
,getType()
-
-
Constructor Detail
-
ProjectKey
ProjectKey(ProjectKeyData projectKeyData)
-
-
Method Detail
-
getNewOrExisting
public static ProjectKey getNewOrExisting(DbControl dc, ProjectPermissions projectPermissions) throws BaseException
Create a new or load an existingProjectKey
when you have a combination of project/permission values. If the database contains a project key with the same combination that project key is loaded and returned, otherwise a new project key is created. If no existing key is found, the new key will immediately be saved and committed to the database using another transaction. This ensures that no two keys contains identical permissions.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database accessprojectPermissions
- AProjectPermissions
object holding the permissions- Returns:
- The
ProjectKey
item - Throws:
BaseException
- If there is an error
-
getById
public static ProjectKey getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
Get aProjectKey
item when you know the ID.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database access.id
- The ID of the item to load- Returns:
- The
ProjectKey
item - Throws:
ItemNotFoundException
- If an item with the specified ID is not foundPermissionDeniedException
- If the logged in user doesn't havePermission.READ
permission to the itemBaseException
- If there is another error
-
deleteUnusedProjectKeys
public static int deleteUnusedProjectKeys() throws BaseException
Delete all keys that are currently not used by any item. This method is intended to be executed at regular intervals by a cleanup application.- Throws:
BaseException
- If there is some kind of error.
-
getData
ProjectKeyData getData()
Description copied from class:BasicItem
Get theBasicData
object that holds all data for this item.
-
getType
public Item getType()
Description copied from interface:Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in theItem
enumeration.- Returns:
- A value indicating the type of item
-
isUsed
public boolean isUsed() throws BaseException
Checks if:- A
Shareable
item is using this key.
- Overrides:
isUsed
in classBasicItem
- Returns:
- TRUE if this item is used, FALSE otherwise
- Throws:
BaseException
- If not able to tell if item is used or not.- See Also:
BasicItem.getUsingItems()
- A
-
getUsingItems
public Set<ItemProxy> getUsingItems()
Get all:Shareable
items shared to this key
- Overrides:
getUsingItems
in classBasicItem
- Returns:
- A set containing proxies for the items, or an empty set if no items are using this item
- Since:
- 2.2
- See Also:
BasicItem.addUsingItems(Set, Item, org.hibernate.query.Query)
-
initPermissions
void initPermissions(int granted, int denied) throws BaseException
WRITE permission is always denied. USE and CREATE permission is always granted.- Overrides:
initPermissions
in classBasicItem
- Parameters:
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclass- Throws:
BaseException
- If the permissions couldn't be initialised
-
getPluginPermissions
PluginPermission getPluginPermissions()
- Overrides:
getPluginPermissions
in classBasicItem
-
getPermissions
public Set<Permission> getPermissions(Project project) throws InvalidDataException
Get the permissions for a project.- Parameters:
project
- TheProject
for which we want to get the permission- Returns:
- A
Set
containing the granted permissions, or an empty set if no permissions have been granted - Throws:
InvalidDataException
- If the project is null- See Also:
Permission
-
getProjectIds
public Set<Integer> getProjectIds(Permission permission)
Get the ID:s of all projects that are shared with this project key having the specified permission.- Parameters:
permission
- The permission the projects must have- Returns:
- A set with the ID:s of all matching projects, or an empty set if there are no matches
-
getNewOrExistingId
static int getNewOrExistingId(Session session, Map<ProjectData,Integer> projectPermissions) throws BaseException
Find the ID of an existing key with exactly the same project/permission combination. If no existing key is found a new one is created.- Parameters:
projectPermissions
- AMap
holding the project/permission combinations- Returns:
- The ID of the new or existing key
- Throws:
BaseException
-
-