|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.BasicItem<D> net.sf.basedb.core.Key<ItemKeyData> net.sf.basedb.core.ItemKey
public class ItemKey
This class is used to get information about which users and groups
a 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
Field Summary | |
---|---|
static Item |
TYPE
The type of item represented by this class. |
Constructor Summary | |
---|---|
ItemKey(ItemKeyData itemKeyData)
|
Method Summary | |
---|---|
static int |
deleteUnusedItemKeys()
Delete all keys that are currently not used by any item. |
static void |
deleteUnusedKeys()
Deprecated. Use deleteUnusedItemKeys() instead which returns the number of
deleted keys |
static ItemKey |
getById(DbControl dc,
int id)
Get an ItemKey item when you know the ID. |
Set<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(org.hibernate.Session session,
Map<UserData,Integer> userPermissions,
Map<GroupData,Integer> groupPermissions)
Find the ID of an existing key with exactly the same user/group/permission combination. |
Set<Permission> |
getPermissions(Group group)
Get the permissions for a group. |
Set<Permission> |
getPermissions(User user)
Get the permissions for a user. |
(package private) PluginPermission |
getPluginPermissions()
|
Item |
getType()
Get the type of item represented by the object. |
Set<Integer> |
getUserIds(Permission permission)
Get the ID:s of all users that have the specified permission in this item key. |
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. |
Methods inherited from class net.sf.basedb.core.BasicItem |
---|
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Item TYPE
Item.ITEMKEY
,
getType()
Constructor Detail |
---|
ItemKey(ItemKeyData itemKeyData)
Method Detail |
---|
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 groups
ItemKey
item
PermissionDeniedException
- If the logged in user tried to share to the
Group.EVERYONE
group without having Permission.SHARE_TO_EVERYONE
permission
InvalidDataException
- If not sharing to any user or group
BaseException
- If there is an errorpublic 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 load
ItemKey
item
ItemNotFoundException
- If an item with the specified
ID is not found
PermissionDeniedException
- If the logged in user doesn't
have Permission.READ
permission to the item
BaseException
- If there is another errorpublic static void deleteUnusedKeys() throws BaseException
deleteUnusedItemKeys()
instead which returns the number of
deleted keys
BaseException
public static int deleteUnusedItemKeys() throws BaseException
BaseException
- If a unused key could not be deleted.public Item getType()
Identifiable
Item
enumeration.
public boolean isUsed() throws BaseException
Shareable
item is using this key.
isUsed
in class BasicItem<ItemKeyData>
BaseException
- If not able to tell if item is used or not.BasicItem.getUsingItems()
public Set<ItemProxy> getUsingItems()
Shareable
items shared to this key
getUsingItems
in class BasicItem<ItemKeyData>
BasicItem.addUsingItems(Set, Item, org.hibernate.Query)
void initPermissions(int granted, int denied) throws BaseException
initPermissions
in class BasicItem<ItemKeyData>
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclass
BaseException
- If the permissions couldn't be initialisedPluginPermission getPluginPermissions()
getPluginPermissions
in class BasicItem<ItemKeyData>
public Set<Permission> getPermissions(User user) throws InvalidDataException
user
- The User
for which we want to get the permission
Set
containing the granted permissions, or an
empty set if no permissions have been granted
InvalidDataException
- If the user is nullPermission
public Set<Permission> getPermissions(Group group) throws InvalidDataException
group
- The Group
for which we want to get the permission
Set
containing the granted permissions, or an
empty set if no permissions have been granted
InvalidDataException
- If the user is nullPermission
public Set<Integer> getUserIds(Permission permission)
permission
- The permission the users must have
public Set<Integer> getGroupIds(Permission permission)
permission
- The permission the groups must have
static int getNewOrExistingKey(org.hibernate.Session session, Map<UserData,Integer> userPermissions, Map<GroupData,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 combinations
BaseException
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |