public class MultiPermissions extends Object
Shareable
items and want to modify some permissions on
all of them without affecting the rest of the permissions.
For example it is possible to add write permission for a new user while preserving the permissions already given to other user, groups and projects. This works even if the logged in user doesn't have read permission to all other user, groups and projects the items have been shared to.
It is a four-step procedure:
MultiPermissions(Collection)
constructor.
updateKeys(DbControl)
method to generate the new keys
and assign those to the items
Modifier and Type | Field and Description |
---|---|
private Map<ItemKey,GroupPermissions> |
groupPermissions |
private boolean |
hasAnnotatableItem |
private Set<SharedItem> |
items |
private Map<ProjectKey,ProjectPermissions> |
projectPermissions |
private Map<ItemKey,UserPermissions> |
userPermissions |
Constructor and Description |
---|
MultiPermissions(Collection<? extends SharedItem> itemsToShare)
Create a new
MultiPermissions object and feed it the
collection of Shareable items that you want to modify. |
Modifier and Type | Method and Description |
---|---|
void |
addPermissions(Group group,
Set<Permission> permissions)
Grant permissions to a group, keeping those that have already been set.
|
void |
addPermissions(Project project,
Set<Permission> permissions)
Grant permissions to a project, keeping those that have already been set.
|
void |
addPermissions(User user,
Set<Permission> permissions)
Grant permissions to a user, keeping those that have already been set.
|
static boolean |
allSame(Collection<Set<Permission>> permissions)
Check if a collection of
Set :s all contain
the same permissions. |
ItemQuery<Group> |
getGroups()
Get a query that returns all groups appearing in at least one of
the item keys.
|
Set<SharedItem> |
getItems()
Returns the items that are handled within this class.
|
Set<SharedItem> |
getItems(Collection<Item> types)
Get all items of specific item types.
|
Set<SharedItem> |
getItems(Item type)
Get all items of a specific item type.
|
Map<ItemKey,Set<Permission>> |
getPermissions(Group group)
Get the permissions for a group.
|
Map<ProjectKey,Set<Permission>> |
getPermissions(Project project)
Get the permissions for a project.
|
Map<ItemKey,Set<Permission>> |
getPermissions(User user)
Get the permissions for a user.
|
ItemQuery<Project> |
getProjects()
Get a query that returns all projects appearing in at least one of
the project keys.
|
ItemQuery<User> |
getUsers()
Get a query that returns all users appearing in at least one of
the item keys.
|
boolean |
hasAnnotatableItem()
Is any of the items to share an annotatable item?
|
void |
merge(ItemKey itemKey)
Merge the permissions from the given item key keeping those
that has already been set.
|
void |
merge(ProjectKey projectKey)
Merge the permissions from the given project key keeping those
that has already been set.
|
void |
setPermissions(Group group,
Set<Permission> permissions)
Grant permissions to a group.
|
void |
setPermissions(Project project,
Set<Permission> permissions)
Grant permissions to a project.
|
void |
setPermissions(User user,
Set<Permission> permissions)
Grant permissions to a user.
|
void |
updateKeys(DbControl dc)
Generate the new keys and update all items with the new keys.
|
void |
updateKeys(DbControl dc,
boolean recursive)
Generate the new keys and update all items with the new keys.
|
private final Set<SharedItem> items
private final Map<ItemKey,UserPermissions> userPermissions
private final Map<ItemKey,GroupPermissions> groupPermissions
private final Map<ProjectKey,ProjectPermissions> projectPermissions
private final boolean hasAnnotatableItem
public MultiPermissions(Collection<? extends SharedItem> itemsToShare) throws InvalidDataException, BaseException
MultiPermissions
object and feed it the
collection of Shareable
items that you want to modify.itemsToShare
- The collection of itemsInvalidDataException
- If the collection is null or emptyBaseException
- If there is another errorpublic static boolean allSame(Collection<Set<Permission>> permissions)
Set
:s all contain
the same permissions.permissions
- The collection of sets to checkPermission
public boolean hasAnnotatableItem()
public void setPermissions(User user, Set<Permission> permissions) throws InvalidDataException
Set
or null
to remove all permissions for the user.user
- The User
permissions
- The permissions to grantInvalidDataException
- If the user is nullPermission
public void addPermissions(User user, Set<Permission> permissions) throws InvalidDataException
user
- The User
permissions
- The permissions to grantInvalidDataException
- If the user is nullPermission
public Map<ItemKey,Set<Permission>> getPermissions(User user) throws InvalidDataException
ItemKey
found among the items passed
to the constructor, including the null item key if present. The value
of each entry is a Set
containing the granted permissions.user
- The User
for which we want to get the permissionMap
containing a Set
of
the granted permissions for each ItemKey
InvalidDataException
- If the user is nullPermission
public void setPermissions(Group group, Set<Permission> permissions) throws InvalidDataException
Set
or null
to remove all permissions for the group.group
- The Group
permissions
- The permissions to grantInvalidDataException
- If the group is nullPermission
public void addPermissions(Group group, Set<Permission> permissions) throws InvalidDataException
group
- The Group
permissions
- The permissions to grantInvalidDataException
- If the group is nullPermission
public Map<ItemKey,Set<Permission>> getPermissions(Group group) throws InvalidDataException
ItemKey
found among the items passed
to the constructor, including the null item key if present. The value
of each entry is a Set
containing the granted permissions.group
- The Group
for which we want to get the permissionMap
containing a Set
of
the granted permissions for each ItemKey
InvalidDataException
- If the group is nullPermission
public void setPermissions(Project project, Set<Permission> permissions) throws PermissionDeniedException, InvalidDataException
Set
or null
to remove all permissions for the project.project
- The Project
permissions
- The permissions to grantInvalidDataException
- If the project is nullPermissionDeniedException
- If the logged in user's doesn't have
Permission.USE
permission to the projectPermission
public void addPermissions(Project project, Set<Permission> permissions) throws PermissionDeniedException, InvalidDataException
project
- The Project
permissions
- The permissions to grantInvalidDataException
- If the project is nullPermissionDeniedException
- If the logged in user's doesn't have
Permission.USE
permission to the projectPermission
public Map<ProjectKey,Set<Permission>> getPermissions(Project project) throws InvalidDataException
ProjectKey
found among the items passed
to the constructor, including the null project key if present. The value
of each entry is a Set
containing the granted permissions.project
- The Project
for which we want to get the permissionMap
containing a Set
of
the granted permissions for each ProjectKey
InvalidDataException
- If the project is nullPermission
public void merge(ItemKey itemKey)
itemKey
- An item key (if null, this method simply returns)UserPermissions.merge(ItemKey)
,
GroupPermissions.merge(ItemKey)
public void merge(ProjectKey projectKey)
projectKey
- An project key (if null, this method simply returns)ProjectPermissions.merge(ProjectKey)
public ItemQuery<User> getUsers()
public ItemQuery<Group> getGroups()
public ItemQuery<Project> getProjects()
public Set<SharedItem> getItems()
public Set<SharedItem> getItems(Item type)
type
- The item type to search forpublic Set<SharedItem> getItems(Collection<Item> types)
types
- A collection with the item types
to search forpublic void updateKeys(DbControl dc) throws PermissionDeniedException, BaseException
dc
- The DbControl
object to use for database accessPermissionDeniedException
- If the logged in user doesn't have
Permission.SET_PERMISSION
permission on all itemsBaseException
- If there is another errorpublic void updateKeys(DbControl dc, boolean recursive) throws PermissionDeniedException, BaseException
dc
- The DbControl
object to use for database accessrecursive
- If TRUE, files and subdirectories to a selected
directory will also shared with the same permissions as the
parent directoryPermissionDeniedException
- If the logged in user doesn't have
Permission.SET_PERMISSION
permission on all itemsBaseException
- If there is another error