Search in sources :

Example 1 with AccountGroup

use of com.google.gerrit.entities.AccountGroup in project gerrit by GerritCodeReview.

the class GroupsOnInit method getExistingGroup.

/**
 * Returns the {@code AccountGroup} for the specified {@code GroupReference}.
 *
 * @param groupReference the {@code GroupReference} of the group
 * @return the {@code InternalGroup} represented by the {@code GroupReference}
 * @throws IOException if an error occurs while reading from NoteDb
 * @throws ConfigInvalidException if the data in NoteDb is in an incorrect format
 * @throws NoSuchGroupException if a group with such a name doesn't exist
 */
public InternalGroup getExistingGroup(GroupReference groupReference) throws NoSuchGroupException, IOException, ConfigInvalidException {
    File allUsersRepoPath = getPathToAllUsersRepository();
    if (allUsersRepoPath != null) {
        try (Repository allUsersRepo = new FileRepository(allUsersRepoPath)) {
            AccountGroup.UUID groupUuid = groupReference.getUUID();
            GroupConfig groupConfig = GroupConfig.loadForGroup(allUsers, allUsersRepo, groupUuid);
            return groupConfig.getLoadedGroup().orElseThrow(() -> new NoSuchGroupException(groupReference.getUUID()));
        }
    }
    throw new NoSuchGroupException(groupReference.getUUID());
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupConfig(com.google.gerrit.server.group.db.GroupConfig) File(java.io.File) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException)

Aggregations

AccountGroup (com.google.gerrit.entities.AccountGroup)1 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)1 GroupConfig (com.google.gerrit.server.group.db.GroupConfig)1 File (java.io.File)1 FileRepository (org.eclipse.jgit.internal.storage.file.FileRepository)1 Repository (org.eclipse.jgit.lib.Repository)1