Class GroupsUpdate


  • public class GroupsUpdate
    extends Object
    A database accessor for write calls related to groups.

    All calls which write group related details to 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.

    • Method Detail

      • addGroup

        public void addGroup​(ReviewDb db,
                             AccountGroup group,
                             Set<Account.Id> memberIds)
                      throws com.google.gwtorm.server.OrmException,
                             IOException
        Adds/Creates the specified group for the specified members (accounts).
        Parameters:
        db - the ReviewDb instance to update
        group - the group to add
        memberIds - the IDs of the accounts which should be members of the created group
        Throws:
        com.google.gwtorm.server.OrmException - if an error occurs while reading/writing from/to ReviewDb
        IOException - if the cache entry of one of the new members couldn't be invalidated, or the new group couldn't be indexed
      • addNewGroup

        public static void addNewGroup​(ReviewDb db,
                                       AccountGroup group)
                                throws com.google.gwtorm.server.OrmException
        Adds the specified group.

        Note: This method doesn't update the index! It just adds the group to the database. Use this method with care.

        Parameters:
        db - the ReviewDb instance to update
        group - the group to add
        Throws:
        com.google.gwtorm.server.OrmException - if an error occurs while reading/writing from/to ReviewDb
      • updateGroup

        public void updateGroup​(ReviewDb db,
                                AccountGroup.UUID groupUuid,
                                Consumer<AccountGroup> groupConsumer)
                         throws com.google.gwtorm.server.OrmException,
                                IOException,
                                NoSuchGroupException
        Updates the specified group.
        Parameters:
        db - the ReviewDb instance to update
        groupUuid - the UUID of the group to update
        groupConsumer - a Consumer which performs the desired updates on the group
        Throws:
        com.google.gwtorm.server.OrmException - if an error occurs while reading/writing from/to ReviewDb
        IOException - if the cache entry for the group couldn't be invalidated
        NoSuchGroupException - if the specified group doesn't exist
      • addGroupMember

        public void addGroupMember​(ReviewDb db,
                                   AccountGroup.UUID groupUuid,
                                   Account.Id accountId)
                            throws com.google.gwtorm.server.OrmException,
                                   IOException,
                                   NoSuchGroupException
        Adds an account as member to a group. The account is only added as a new member if it isn't already a member of the group.

        Note: This method doesn't check whether the account exists!

        Parameters:
        db - the ReviewDb instance to update
        groupUuid - the UUID of the group
        accountId - the ID of the account to add
        Throws:
        com.google.gwtorm.server.OrmException - if an error occurs while reading/writing from/to ReviewDb
        IOException - if the cache entry of the new member couldn't be invalidated
        NoSuchGroupException - if the specified group doesn't exist
      • addGroupMembers

        public void addGroupMembers​(ReviewDb db,
                                    AccountGroup.UUID groupUuid,
                                    Set<Account.Id> accountIds)
                             throws com.google.gwtorm.server.OrmException,
                                    IOException,
                                    NoSuchGroupException
        Adds several accounts as members to a group. Only accounts which currently aren't members of the group are added.

        Note: This method doesn't check whether the accounts exist!

        Parameters:
        db - the ReviewDb instance to update
        groupUuid - the UUID of the group
        accountIds - a set of IDs of accounts to add
        Throws:
        com.google.gwtorm.server.OrmException - if an error occurs while reading/writing from/to ReviewDb
        IOException - if the group or one of the new members couldn't be indexed
        NoSuchGroupException - if the specified group doesn't exist
      • removeGroupMembers

        public void removeGroupMembers​(ReviewDb db,
                                       AccountGroup.UUID groupUuid,
                                       Set<Account.Id> accountIds)
                                throws com.google.gwtorm.server.OrmException,
                                       IOException,
                                       NoSuchGroupException
        Removes several members (accounts) from a group. Only accounts which currently are members of the group are removed.
        Parameters:
        db - the ReviewDb instance to update
        groupUuid - the UUID of the group
        accountIds - a set of IDs of accounts to remove
        Throws:
        com.google.gwtorm.server.OrmException - if an error occurs while reading/writing from/to ReviewDb
        IOException - if the group or one of the removed members couldn't be indexed
        NoSuchGroupException - if the specified group doesn't exist
      • addSubgroups

        public void addSubgroups​(ReviewDb db,
                                 AccountGroup.UUID parentGroupUuid,
                                 Set<AccountGroup.UUID> subgroupUuids)
                          throws com.google.gwtorm.server.OrmException,
                                 NoSuchGroupException,
                                 IOException
        Adds several groups as subgroups to a group. Only groups which currently aren't subgroups of the group are added.

        The 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 update
        parentGroupUuid - the UUID of the parent group
        subgroupUuids - a set of IDs of the groups to add as subgroups
        Throws:
        com.google.gwtorm.server.OrmException - if an error occurs while reading/writing from/to ReviewDb
        IOException - if the parent group couldn't be indexed
        NoSuchGroupException - if the specified parent group doesn't exist
      • removeSubgroups

        public void removeSubgroups​(ReviewDb db,
                                    AccountGroup.UUID parentGroupUuid,
                                    Set<AccountGroup.UUID> subgroupUuids)
                             throws com.google.gwtorm.server.OrmException,
                                    NoSuchGroupException,
                                    IOException
        Removes several subgroups from a parent group. Only groups which currently are subgroups of the group are removed.

        The parent group must be an internal group whereas the subgroups can either be internal or external groups.

        Parameters:
        db - the ReviewDb instance to update
        parentGroupUuid - the UUID of the parent group
        subgroupUuids - a set of IDs of the subgroups to remove from the parent group
        Throws:
        com.google.gwtorm.server.OrmException - if an error occurs while reading/writing from/to ReviewDb
        IOException - if the parent group couldn't be indexed
        NoSuchGroupException - if the specified parent group doesn't exist