Class Groups
- java.lang.Object
-
- com.google.gerrit.server.group.Groups
-
public class Groups extends Object
A database accessor for read calls related to groups.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 Summary
Constructors Constructor Description Groups()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stream<AccountGroup>
getAll(ReviewDb db)
Stream<AccountGroup.UUID>
getExternalGroups(ReviewDb db)
Returns all known external groups.Optional<InternalGroup>
getGroup(ReviewDb db, AccountGroup.Id groupId)
Returns theAccountGroup
for the specified ID if it exists.Optional<InternalGroup>
getGroup(ReviewDb db, AccountGroup.UUID groupUuid)
Returns theInternalGroup
for the specified UUID if it exists.static Stream<AccountGroup.Id>
getGroupsWithMemberFromReviewDb(ReviewDb db, Account.Id accountId)
Returns the groups of which the specified account is a member.Stream<Account.Id>
getMembers(ReviewDb db, AccountGroup.UUID groupUuid)
Returns the members (accounts) of a group.static Stream<AccountGroup.Id>
getParentGroupsFromReviewDb(ReviewDb db, AccountGroup.UUID subgroupUuid)
Returns the parent groups of the specified (sub)group.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.
-
-
-
Method Detail
-
getGroup
public Optional<InternalGroup> getGroup(ReviewDb db, AccountGroup.Id groupId) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
Returns theAccountGroup
for the specified ID if it exists.- Parameters:
db
- theReviewDb
instance to use for lookupsgroupId
- the ID of the group- Returns:
- the found
AccountGroup
if it exists, or else an emptyOptional
- Throws:
com.google.gwtorm.server.OrmException
- if the group couldn't be retrieved from ReviewDbNoSuchGroupException
-
getGroup
public Optional<InternalGroup> getGroup(ReviewDb db, AccountGroup.UUID groupUuid) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
Returns theInternalGroup
for the specified UUID if it exists.- Parameters:
db
- theReviewDb
instance to use for lookupsgroupUuid
- the UUID of the group- Returns:
- the found
InternalGroup
if it exists, or else an emptyOptional
- Throws:
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
-
getAll
public Stream<AccountGroup> getAll(ReviewDb db) throws com.google.gwtorm.server.OrmException
- Throws:
com.google.gwtorm.server.OrmException
-
isMember
public boolean isMember(ReviewDb db, AccountGroup.UUID groupUuid, Account.Id accountId) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
Indicates whether the specified account is a member of the specified group.Note: This method doesn't check whether the account exists!
- Parameters:
db
- theReviewDb
instance to use for lookupsgroupUuid
- the UUID of the groupaccountId
- the ID of the account- Returns:
true
if the account is a member of the group, or elsefalse
- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDbNoSuchGroupException
- if the specified group doesn't exist
-
isSubgroup
public boolean isSubgroup(ReviewDb db, AccountGroup.UUID parentGroupUuid, AccountGroup.UUID subgroupUuid) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
Indicates whether the specified group is a subgroup of the specified parent group.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!
- Parameters:
db
- theReviewDb
instance to use for lookupsparentGroupUuid
- the UUID of the parent groupsubgroupUuid
- the UUID of the subgroup- Returns:
true
if the group is a subgroup of the other group, or elsefalse
- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDbNoSuchGroupException
- if the specified parent group doesn't exist
-
getMembers
public Stream<Account.Id> getMembers(ReviewDb db, AccountGroup.UUID groupUuid) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
Returns the members (accounts) of a group.Note: This method doesn't check whether the accounts exist!
- Parameters:
db
- theReviewDb
instance to use for lookupsgroupUuid
- the UUID of the group- Returns:
- a stream of the IDs of the members
- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDbNoSuchGroupException
- if the specified group doesn't exist
-
getSubgroups
public Stream<AccountGroup.UUID> getSubgroups(ReviewDb db, AccountGroup.UUID groupUuid) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
Returns the subgroups of a group.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!
- Parameters:
db
- theReviewDb
instance to use for lookupsgroupUuid
- the UUID of the parent group- Returns:
- a stream of the UUIDs of the subgroups
- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDbNoSuchGroupException
- if the specified parent group doesn't exist
-
getGroupsWithMemberFromReviewDb
public static Stream<AccountGroup.Id> getGroupsWithMemberFromReviewDb(ReviewDb db, Account.Id accountId) throws com.google.gwtorm.server.OrmException
Returns the groups of which the specified account is a member.Note: This method returns an empty stream if the account doesn't exist. This method doesn't check whether the groups exist.
- Parameters:
db
- theReviewDb
instance to use for lookupsaccountId
- the ID of the account- Returns:
- a stream of the IDs of the groups of which the account is a member
- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDb
-
getParentGroupsFromReviewDb
public static Stream<AccountGroup.Id> getParentGroupsFromReviewDb(ReviewDb db, AccountGroup.UUID subgroupUuid) throws com.google.gwtorm.server.OrmException
Returns the parent groups of the specified (sub)group.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.
- Parameters:
db
- theReviewDb
instance to use for lookupssubgroupUuid
- the UUID of the subgroup- Returns:
- a stream of the IDs of the parent groups
- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDb
-
getExternalGroups
public Stream<AccountGroup.UUID> getExternalGroups(ReviewDb db) throws com.google.gwtorm.server.OrmException
Returns all known external groups. External groups are 'known' when they are specified as a subgroup of an internal group.- Parameters:
db
- theReviewDb
instance to use for lookups- Returns:
- a stream of the UUIDs of the known external groups
- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading from ReviewDb
-
-