public class Groups
extends java.lang.Object
All calls which read group related details from the database (either ReviewDb or NoteDb) are
gathered here. Other classes should always use this class instead of accessing the database
directly. There are a few exceptions though: schema classes, wrapper classes, and classes
executed during init. The latter ones should use GroupsOnInit
instead.
If not explicitly stated, all methods of this class refer to internal groups.
Constructor and Description |
---|
Groups() |
Modifier and Type | Method and Description |
---|---|
java.util.stream.Stream<AccountGroup> |
getAll(ReviewDb db) |
java.util.stream.Stream<AccountGroup.UUID> |
getExternalGroups(ReviewDb db)
Returns all known external groups.
|
java.util.Optional<InternalGroup> |
getGroup(ReviewDb db,
AccountGroup.Id groupId)
Returns the
AccountGroup for the specified ID if it exists. |
java.util.Optional<InternalGroup> |
getGroup(ReviewDb db,
AccountGroup.UUID groupUuid)
Returns the
InternalGroup for the specified UUID if it exists. |
static java.util.stream.Stream<AccountGroup.Id> |
getGroupsWithMemberFromReviewDb(ReviewDb db,
Account.Id accountId)
Returns the groups of which the specified account is a member.
|
java.util.stream.Stream<Account.Id> |
getMembers(ReviewDb db,
AccountGroup.UUID groupUuid)
Returns the members (accounts) of a group.
|
static java.util.stream.Stream<AccountGroup.Id> |
getParentGroupsFromReviewDb(ReviewDb db,
AccountGroup.UUID subgroupUuid)
Returns the parent groups of the specified (sub)group.
|
java.util.stream.Stream<AccountGroup.UUID> |
getSubgroups(ReviewDb db,
AccountGroup.UUID groupUuid)
Returns the subgroups of a group.
|
boolean |
isMember(ReviewDb db,
AccountGroup.UUID groupUuid,
Account.Id accountId)
Indicates whether the specified account is a member of the specified group.
|
boolean |
isSubgroup(ReviewDb db,
AccountGroup.UUID parentGroupUuid,
AccountGroup.UUID subgroupUuid)
Indicates whether the specified group is a subgroup of the specified parent group.
|
public java.util.Optional<InternalGroup> getGroup(ReviewDb db, AccountGroup.Id groupId) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
AccountGroup
for the specified ID if it exists.db
- the ReviewDb
instance to use for lookupsgroupId
- the ID of the groupAccountGroup
if it exists, or else an empty Optional
com.google.gwtorm.server.OrmException
- if the group couldn't be retrieved from ReviewDbNoSuchGroupException
public java.util.Optional<InternalGroup> getGroup(ReviewDb db, AccountGroup.UUID groupUuid) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
InternalGroup
for the specified UUID if it exists.db
- the ReviewDb
instance to use for lookupsgroupUuid
- the UUID of the groupInternalGroup
if it exists, or else an empty Optional
com.google.gwtorm.server.OrmDuplicateKeyException
- if multiple groups are found for the specified UUIDcom.google.gwtorm.server.OrmException
- if the group couldn't be retrieved from ReviewDbNoSuchGroupException
public java.util.stream.Stream<AccountGroup> getAll(ReviewDb db) throws com.google.gwtorm.server.OrmException
com.google.gwtorm.server.OrmException
public boolean isMember(ReviewDb db, AccountGroup.UUID groupUuid, Account.Id accountId) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
Note: This method doesn't check whether the account exists!
db
- the ReviewDb
instance to use for lookupsgroupUuid
- the UUID of the groupaccountId
- the ID of the accounttrue
if the account is a member of the group, or else false
com.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDbNoSuchGroupException
- if the specified group doesn't existpublic boolean isSubgroup(ReviewDb db, AccountGroup.UUID parentGroupUuid, AccountGroup.UUID subgroupUuid) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
The parent group must be an internal group whereas the subgroup may either be an internal or an external group.
Note: This method doesn't check whether the subgroup exists!
db
- the ReviewDb
instance to use for lookupsparentGroupUuid
- the UUID of the parent groupsubgroupUuid
- the UUID of the subgrouptrue
if the group is a subgroup of the other group, or else false
com.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDbNoSuchGroupException
- if the specified parent group doesn't existpublic java.util.stream.Stream<Account.Id> getMembers(ReviewDb db, AccountGroup.UUID groupUuid) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
Note: This method doesn't check whether the accounts exist!
db
- the ReviewDb
instance to use for lookupsgroupUuid
- the UUID of the groupcom.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDbNoSuchGroupException
- if the specified group doesn't existpublic java.util.stream.Stream<AccountGroup.UUID> getSubgroups(ReviewDb db, AccountGroup.UUID groupUuid) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
This parent group must be an internal group whereas the subgroups can either be internal or external groups.
Note: This method doesn't check whether the subgroups exist!
db
- the ReviewDb
instance to use for lookupsgroupUuid
- the UUID of the parent groupcom.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDbNoSuchGroupException
- if the specified parent group doesn't existpublic static java.util.stream.Stream<AccountGroup.Id> getGroupsWithMemberFromReviewDb(ReviewDb db, Account.Id accountId) throws com.google.gwtorm.server.OrmException
Note: This method returns an empty stream if the account doesn't exist. This method doesn't check whether the groups exist.
db
- the ReviewDb
instance to use for lookupsaccountId
- the ID of the accountcom.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDbpublic static java.util.stream.Stream<AccountGroup.Id> getParentGroupsFromReviewDb(ReviewDb db, AccountGroup.UUID subgroupUuid) throws com.google.gwtorm.server.OrmException
The subgroup may either be an internal or an external group whereas the returned parent groups represent only internal groups.
Note: This method returns an empty stream if the specified group doesn't exist. This method doesn't check whether the parent groups exist.
db
- the ReviewDb
instance to use for lookupssubgroupUuid
- the UUID of the subgroupcom.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDbpublic java.util.stream.Stream<AccountGroup.UUID> getExternalGroups(ReviewDb db) throws com.google.gwtorm.server.OrmException
db
- the ReviewDb
instance to use for lookupscom.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDb