public class ItemKey extends Key
Shareable
item has been shared to.
An item key is immutable and the user/group/permission combinations cannot be changed once the key has been created. This allows the core to resuse item keys for all items with the same combination of user/group/permission values without fear that someone else may change the permissions.
To create a new item key use the UserPermissions
and/or
GroupPermissions
objects and pass the information to
the getNewOrExisting(DbControl, UserPermissions, GroupPermissions)
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. The MultiPermissions
class takes care of all
the cumbersome work of creating new keys and assigning those to the items
for you.
Shareable
Modifier and Type | Field and Description |
---|---|
static Item |
TYPE
The type of item represented by this class.
|
Constructor and Description |
---|
ItemKey(ItemKeyData itemKeyData) |
Modifier and Type | Method and Description |
---|---|
static int |
deleteUnusedItemKeys()
Delete all keys that are currently not used by any item.
|
static ItemKey |
getById(DbControl dc,
int id)
Get an
ItemKey item when you know the ID. |
(package private) ItemKeyData |
getData()
Get the
BasicData object that holds all data for this item. |
java.util.Set<java.lang.Integer> |
getGroupIds(Permission permission)
Get the ID:s of all groups that have the specified permission in this item key.
|
static ItemKey |
getNewOrExisting(DbControl dc,
UserPermissions userPermissions,
GroupPermissions groupPermissions)
Create a new or load an existing
ItemKey when you
have a combination of user/group/permission values. |
(package private) static int |
getNewOrExistingKey(Session session,
java.util.Map<UserData,java.lang.Integer> userPermissions,
java.util.Map<GroupData,java.lang.Integer> groupPermissions)
Find the ID of an existing key with exactly the same
user/group/permission combination.
|
java.util.Set<Permission> |
getPermissions(Group group)
Get the permissions for a group.
|
java.util.Set<Permission> |
getPermissions(User user)
Get the permissions for a user.
|
(package private) PluginPermission |
getPluginPermissions() |
static ItemKey |
getShareToEveryOneKey(DbControl dc,
Permission permission)
Get a key that can be used to share items to the EVERYONE group with the
given permissions.
|
Item |
getType()
Get the type of item represented by the object.
|
java.util.Set<java.lang.Integer> |
getUserIds(Permission permission)
Get the ID:s of all users that have the specified permission in this item key.
|
java.util.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:
A
Shareable item is using this key. |
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
public static final Item TYPE
Item.ITEMKEY
,
getType()
ItemKey(ItemKeyData itemKeyData)
public static ItemKey getNewOrExisting(DbControl dc, UserPermissions userPermissions, GroupPermissions groupPermissions) throws PermissionDeniedException, InvalidDataException, BaseException
ItemKey
when you
have a combination of user/group/permission values. If the database
contains an item key with the same combination that key is
loaded and returned, otherwise a new item key is created.
If no existing key is found, the new key will immediately be saved
and committed to the database using a different transaction. This ensures
that no two keys contains identical permissions.dc
- The DbControl
which will be used for
permission checking and database accessuserPermissions
- A UserPermissions
object
holding the permissions for usersgroupPermissions
- A GroupPermissions
object
holding the permissions for groupsItemKey
itemPermissionDeniedException
- If the logged in user tried to share to the
Group.EVERYONE
group without having Permission.SHARE_TO_EVERYONE
permissionInvalidDataException
- If not sharing to any user or groupBaseException
- If there is an errorpublic static ItemKey getShareToEveryOneKey(DbControl dc, Permission permission)
dc
- An open DbControlpermission
- The permissionspublic static ItemKey getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
ItemKey
item when you know the ID.dc
- The DbControl
which will be used for
permission checking and database access.id
- The ID of the item to loadItemKey
itemItemNotFoundException
- If an item with the specified
ID is not foundPermissionDeniedException
- If the logged in user doesn't
have Permission.READ
permission to the itemBaseException
- If there is another errorpublic static int deleteUnusedItemKeys() throws BaseException
BaseException
- If a unused key could not be deleted.ItemKeyData getData()
BasicItem
BasicData
object that holds all data for this item.public Item getType()
Identifiable
Item
enumeration.public boolean isUsed() throws BaseException
Shareable
item is using this key.
isUsed
in class BasicItem
BaseException
- If not able to tell if item is used or not.BasicItem.getUsingItems()
public java.util.Set<ItemProxy> getUsingItems()
Shareable
items shared to this key
getUsingItems
in class BasicItem
BasicItem.addUsingItems(Set, Item, org.hibernate.Query)
void initPermissions(int granted, int denied) throws BaseException
initPermissions
in class BasicItem
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclassBaseException
- If the permissions couldn't be initialisedPluginPermission getPluginPermissions()
getPluginPermissions
in class BasicItem
public java.util.Set<Permission> getPermissions(User user) throws InvalidDataException
user
- The User
for which we want to get the permissionSet
containing the granted permissions, or an
empty set if no permissions have been grantedInvalidDataException
- If the user is nullPermission
public java.util.Set<Permission> getPermissions(Group group) throws InvalidDataException
group
- The Group
for which we want to get the permissionSet
containing the granted permissions, or an
empty set if no permissions have been grantedInvalidDataException
- If the user is nullPermission
public java.util.Set<java.lang.Integer> getUserIds(Permission permission)
permission
- The permission the users must havepublic java.util.Set<java.lang.Integer> getGroupIds(Permission permission)
permission
- The permission the groups must havestatic int getNewOrExistingKey(Session session, java.util.Map<UserData,java.lang.Integer> userPermissions, java.util.Map<GroupData,java.lang.Integer> groupPermissions) throws BaseException
session
- The Hibernate session to use, or null if a new session should be createduserPermissions
- A Map
holding the user/permission combinationsgroupPermissions
- A Map
holding the group/permission combinationsBaseException