diff options
Diffstat (limited to 'gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CreateGroupCommand.java')
-rw-r--r-- | gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CreateGroupCommand.java | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CreateGroupCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CreateGroupCommand.java index 1446f84504..1855f41b13 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CreateGroupCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CreateGroupCommand.java @@ -25,8 +25,8 @@ import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.extensions.restapi.TopLevelResource; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.AccountGroup; -import com.google.gerrit.server.group.AddIncludedGroups; import com.google.gerrit.server.group.AddMembers; +import com.google.gerrit.server.group.AddSubgroups; import com.google.gerrit.server.group.CreateGroup; import com.google.gerrit.server.group.GroupResource; import com.google.gerrit.server.group.GroupsCollection; @@ -37,6 +37,7 @@ import com.google.inject.Inject; import java.io.IOException; import java.util.HashSet; import java.util.Set; +import org.eclipse.jgit.errors.ConfigInvalidException; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -72,7 +73,7 @@ final class CreateGroupCommand extends SshCommand { aliases = {"-m"}, metaVar = "USERNAME", usage = "initial set of users to become members of the group") - void addMember(final Account.Id id) { + void addMember(Account.Id id) { initialMembers.add(id); } @@ -86,7 +87,7 @@ final class CreateGroupCommand extends SshCommand { aliases = "-g", metaVar = "GROUP", usage = "initial set of groups to be included in the group") - void addGroup(final AccountGroup.UUID id) { + void addGroup(AccountGroup.UUID id) { initialGroups.add(id); } @@ -96,10 +97,10 @@ final class CreateGroupCommand extends SshCommand { @Inject private AddMembers addMembers; - @Inject private AddIncludedGroups addIncludedGroups; + @Inject private AddSubgroups addSubgroups; @Override - protected void run() throws Failure, OrmException, IOException { + protected void run() throws Failure, OrmException, IOException, ConfigInvalidException { try { GroupResource rsrc = createGroup(); @@ -108,14 +109,15 @@ final class CreateGroupCommand extends SshCommand { } if (!initialGroups.isEmpty()) { - addIncludedGroups(rsrc); + addSubgroups(rsrc); } } catch (RestApiException e) { throw die(e); } } - private GroupResource createGroup() throws RestApiException, OrmException, IOException { + private GroupResource createGroup() + throws RestApiException, OrmException, IOException, ConfigInvalidException { GroupInput input = new GroupInput(); input.description = groupDescription; input.visibleToAll = visibleToAll; @@ -128,17 +130,18 @@ final class CreateGroupCommand extends SshCommand { return groups.parse(TopLevelResource.INSTANCE, IdString.fromUrl(group.id)); } - private void addMembers(GroupResource rsrc) throws RestApiException, OrmException, IOException { + private void addMembers(GroupResource rsrc) + throws RestApiException, OrmException, IOException, ConfigInvalidException { AddMembers.Input input = AddMembers.Input.fromMembers( initialMembers.stream().map(Object::toString).collect(toList())); addMembers.apply(rsrc, input); } - private void addIncludedGroups(GroupResource rsrc) throws RestApiException, OrmException { - AddIncludedGroups.Input input = - AddIncludedGroups.Input.fromGroups( + private void addSubgroups(GroupResource rsrc) throws RestApiException, OrmException, IOException { + AddSubgroups.Input input = + AddSubgroups.Input.fromGroups( initialGroups.stream().map(AccountGroup.UUID::get).collect(toList())); - addIncludedGroups.apply(rsrc, input); + addSubgroups.apply(rsrc, input); } } |