Search in sources :

Example 1 with GroupResource

use of com.google.gerrit.server.group.GroupResource in project gerrit by GerritCodeReview.

the class SetMembersCommand method reportGroupsAction.

private void reportGroupsAction(String action, GroupResource group, List<AccountGroup.UUID> groupUuidList) throws UnsupportedEncodingException, IOException {
    String names = groupUuidList.stream().map(uuid -> groupCache.get(uuid).getName()).collect(joining(", "));
    out.write(String.format("Groups %s group %s: %s\n", action, group.getName(), names).getBytes(ENC));
}
Also used : CommandMetaData(com.google.gerrit.sshd.CommandMetaData) AccountCache(com.google.gerrit.server.account.AccountCache) GroupResource(com.google.gerrit.server.group.GroupResource) IdString(com.google.gerrit.extensions.restapi.IdString) Inject(com.google.inject.Inject) ArrayList(java.util.ArrayList) GroupsCollection(com.google.gerrit.server.group.GroupsCollection) Argument(org.kohsuke.args4j.Argument) Account(com.google.gerrit.reviewdb.client.Account) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) AddIncludedGroups(com.google.gerrit.server.group.AddIncludedGroups) AddMembers(com.google.gerrit.server.group.AddMembers) MoreObjects(com.google.common.base.MoreObjects) IOException(java.io.IOException) Option(org.kohsuke.args4j.Option) Collectors.joining(java.util.stream.Collectors.joining) TopLevelResource(com.google.gerrit.extensions.restapi.TopLevelResource) Collectors.toList(java.util.stream.Collectors.toList) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) List(java.util.List) DeleteIncludedGroups(com.google.gerrit.server.group.DeleteIncludedGroups) SshCommand(com.google.gerrit.sshd.SshCommand) DeleteMembers(com.google.gerrit.server.group.DeleteMembers) GroupCache(com.google.gerrit.server.account.GroupCache) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IdString(com.google.gerrit.extensions.restapi.IdString)

Example 2 with GroupResource

use of com.google.gerrit.server.group.GroupResource in project gerrit by GerritCodeReview.

the class SetMembersCommand method reportMembersAction.

private void reportMembersAction(String action, GroupResource group, List<Account.Id> accountIdList) throws UnsupportedEncodingException, IOException {
    String names = accountIdList.stream().map(accountId -> MoreObjects.firstNonNull(accountCache.get(accountId).getAccount().getPreferredEmail(), "n/a")).collect(joining(", "));
    out.write(String.format("Members %s group %s: %s\n", action, group.getName(), names).getBytes(ENC));
}
Also used : CommandMetaData(com.google.gerrit.sshd.CommandMetaData) AccountCache(com.google.gerrit.server.account.AccountCache) GroupResource(com.google.gerrit.server.group.GroupResource) IdString(com.google.gerrit.extensions.restapi.IdString) Inject(com.google.inject.Inject) ArrayList(java.util.ArrayList) GroupsCollection(com.google.gerrit.server.group.GroupsCollection) Argument(org.kohsuke.args4j.Argument) Account(com.google.gerrit.reviewdb.client.Account) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) AddIncludedGroups(com.google.gerrit.server.group.AddIncludedGroups) AddMembers(com.google.gerrit.server.group.AddMembers) MoreObjects(com.google.common.base.MoreObjects) IOException(java.io.IOException) Option(org.kohsuke.args4j.Option) Collectors.joining(java.util.stream.Collectors.joining) TopLevelResource(com.google.gerrit.extensions.restapi.TopLevelResource) Collectors.toList(java.util.stream.Collectors.toList) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) List(java.util.List) DeleteIncludedGroups(com.google.gerrit.server.group.DeleteIncludedGroups) SshCommand(com.google.gerrit.sshd.SshCommand) DeleteMembers(com.google.gerrit.server.group.DeleteMembers) GroupCache(com.google.gerrit.server.account.GroupCache) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IdString(com.google.gerrit.extensions.restapi.IdString)

Example 3 with GroupResource

use of com.google.gerrit.server.group.GroupResource in project gerrit by GerritCodeReview.

the class RenameGroupCommand method run.

@Override
protected void run() throws Failure {
    try {
        GroupResource rsrc = groups.parse(TopLevelResource.INSTANCE, IdString.fromDecoded(groupName));
        PutName.Input input = new PutName.Input();
        input.name = newGroupName;
        putName.apply(rsrc, input);
    } catch (RestApiException | OrmException | IOException | NoSuchGroupException e) {
        throw die(e);
    }
}
Also used : OrmException(com.google.gwtorm.server.OrmException) PutName(com.google.gerrit.server.group.PutName) IOException(java.io.IOException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) GroupResource(com.google.gerrit.server.group.GroupResource) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException)

Example 4 with GroupResource

use of com.google.gerrit.server.group.GroupResource in project gerrit by GerritCodeReview.

the class AgreementJson method format.

public AgreementInfo format(ContributorAgreement ca) {
    AgreementInfo info = new AgreementInfo();
    info.name = ca.getName();
    info.description = ca.getDescription();
    info.url = ca.getAgreementUrl();
    GroupReference autoVerifyGroup = ca.getAutoVerify();
    if (autoVerifyGroup != null && self.get().isIdentifiedUser()) {
        IdentifiedUser user = identifiedUserFactory.create(self.get().getAccountId());
        try {
            GroupControl gc = genericGroupControlFactory.controlFor(user, autoVerifyGroup.getUUID());
            GroupResource group = new GroupResource(gc);
            info.autoVerifyGroup = groupJson.format(group);
        } catch (NoSuchGroupException | OrmException e) {
            log.warn("autoverify group \"" + autoVerifyGroup.getName() + "\" does not exist, referenced in CLA \"" + ca.getName() + "\"");
        }
    }
    return info;
}
Also used : GroupControl(com.google.gerrit.server.account.GroupControl) OrmException(com.google.gwtorm.server.OrmException) AgreementInfo(com.google.gerrit.extensions.common.AgreementInfo) GroupReference(com.google.gerrit.common.data.GroupReference) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) GroupResource(com.google.gerrit.server.group.GroupResource) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException)

Example 5 with GroupResource

use of com.google.gerrit.server.group.GroupResource in project gerrit by GerritCodeReview.

the class SetMembersCommand method run.

@Override
protected void run() throws UnloggedFailure, Failure, Exception {
    try {
        for (AccountGroup.UUID groupUuid : groups) {
            GroupResource resource = groupsCollection.parse(TopLevelResource.INSTANCE, IdString.fromUrl(groupUuid.get()));
            if (!accountsToRemove.isEmpty()) {
                deleteMembers.apply(resource, fromMembers(accountsToRemove));
                reportMembersAction("removed from", resource, accountsToRemove);
            }
            if (!groupsToRemove.isEmpty()) {
                deleteIncludedGroups.apply(resource, fromGroups(groupsToRemove));
                reportGroupsAction("excluded from", resource, groupsToRemove);
            }
            if (!accountsToAdd.isEmpty()) {
                addMembers.apply(resource, fromMembers(accountsToAdd));
                reportMembersAction("added to", resource, accountsToAdd);
            }
            if (!groupsToInclude.isEmpty()) {
                addIncludedGroups.apply(resource, fromGroups(groupsToInclude));
                reportGroupsAction("included to", resource, groupsToInclude);
            }
        }
    } catch (RestApiException e) {
        throw die(e.getMessage());
    }
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) GroupResource(com.google.gerrit.server.group.GroupResource)

Aggregations

GroupResource (com.google.gerrit.server.group.GroupResource)5 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)4 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)3 IOException (java.io.IOException)3 MoreObjects (com.google.common.base.MoreObjects)2 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)2 IdString (com.google.gerrit.extensions.restapi.IdString)2 TopLevelResource (com.google.gerrit.extensions.restapi.TopLevelResource)2 Account (com.google.gerrit.reviewdb.client.Account)2 AccountCache (com.google.gerrit.server.account.AccountCache)2 GroupCache (com.google.gerrit.server.account.GroupCache)2 AddIncludedGroups (com.google.gerrit.server.group.AddIncludedGroups)2 AddMembers (com.google.gerrit.server.group.AddMembers)2 DeleteIncludedGroups (com.google.gerrit.server.group.DeleteIncludedGroups)2 DeleteMembers (com.google.gerrit.server.group.DeleteMembers)2 GroupsCollection (com.google.gerrit.server.group.GroupsCollection)2 CommandMetaData (com.google.gerrit.sshd.CommandMetaData)2 SshCommand (com.google.gerrit.sshd.SshCommand)2 OrmException (com.google.gwtorm.server.OrmException)2 Inject (com.google.inject.Inject)2