Class 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 Detail

      • Groups

        public Groups()
    • Method Detail

      • getGroup

        public Optional<InternalGroup> getGroup​(ReviewDb db,
                                                AccountGroup.Id groupId)
                                         throws com.google.gwtorm.server.OrmException,
                                                NoSuchGroupException
        Returns the AccountGroup for the specified ID if it exists.
        Parameters:
        db - the ReviewDb instance to use for lookups
        groupId - the ID of the group
        Returns:
        the found AccountGroup if it exists, or else an empty Optional
        Throws:
        com.google.gwtorm.server.OrmException - if the group couldn't be retrieved from ReviewDb
        NoSuchGroupException
      • getGroup

        public Optional<InternalGroup> getGroup​(ReviewDb db,
                                                AccountGroup.UUID groupUuid)
                                         throws com.google.gwtorm.server.OrmException,
                                                NoSuchGroupException
        Returns the InternalGroup for the specified UUID if it exists.
        Parameters:
        db - the ReviewDb instance to use for lookups
        groupUuid - the UUID of the group
        Returns:
        the found InternalGroup if it exists, or else an empty Optional
        Throws:
        com.google.gwtorm.server.OrmDuplicateKeyException - if multiple groups are found for the specified UUID
        com.google.gwtorm.server.OrmException - if the group couldn't be retrieved from ReviewDb
        NoSuchGroupException
      • 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 - the ReviewDb instance to use for lookups
        groupUuid - the UUID of the group
        accountId - the ID of the account
        Returns:
        true if the account is a member of the group, or else false
        Throws:
        com.google.gwtorm.server.OrmException - if an error occurs while reading from ReviewDb
        NoSuchGroupException - 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 - the ReviewDb instance to use for lookups
        parentGroupUuid - the UUID of the parent group
        subgroupUuid - the UUID of the subgroup
        Returns:
        true if the group is a subgroup of the other group, or else false
        Throws:
        com.google.gwtorm.server.OrmException - if an error occurs while reading from ReviewDb
        NoSuchGroupException - 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 - the ReviewDb instance to use for lookups
        groupUuid - 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 ReviewDb
        NoSuchGroupException - 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 - the ReviewDb instance to use for lookups
        groupUuid - 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 ReviewDb
        NoSuchGroupException - 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 - the ReviewDb instance to use for lookups
        accountId - 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 - the ReviewDb instance to use for lookups
        subgroupUuid - 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 - the ReviewDb 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