Search in sources :

Example 11 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput in project gerrit by GerritCodeReview.

the class Schema_150_to_151_Test method createGroup.

private AccountGroup.Id createGroup(String name) throws Exception {
    GroupInput groupInput = new GroupInput();
    groupInput.name = name;
    GroupInfo groupInfo = createGroupFactory.create(name).apply(TopLevelResource.INSTANCE, groupInput);
    return new Id(groupInfo.groupId);
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) Id(com.google.gerrit.reviewdb.client.AccountGroup.Id)

Example 12 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput in project gerrit by GerritCodeReview.

the class CreateGroup method apply.

@Override
public GroupInfo apply(TopLevelResource resource, GroupInput input) throws AuthException, BadRequestException, UnprocessableEntityException, ResourceConflictException, OrmException, IOException {
    if (input == null) {
        input = new GroupInput();
    }
    if (input.name != null && !name.equals(input.name)) {
        throw new BadRequestException("name must match URL");
    }
    AccountGroup.Id ownerId = owner(input);
    CreateGroupArgs args = new CreateGroupArgs();
    args.setGroupName(name);
    args.groupDescription = Strings.emptyToNull(input.description);
    args.visibleToAll = MoreObjects.firstNonNull(input.visibleToAll, defaultVisibleToAll);
    args.ownerGroupId = ownerId;
    if (input.members != null && !input.members.isEmpty()) {
        List<Account.Id> members = new ArrayList<>();
        for (String nameOrEmailOrId : input.members) {
            Account a = addMembers.findAccount(nameOrEmailOrId);
            if (!a.isActive()) {
                throw new UnprocessableEntityException(String.format("Account Inactive: %s", nameOrEmailOrId));
            }
            members.add(a.getId());
        }
        args.initialMembers = members;
    } else {
        args.initialMembers = ownerId == null ? Collections.singleton(self.get().getAccountId()) : Collections.<Account.Id>emptySet();
    }
    for (GroupCreationValidationListener l : groupCreationValidationListeners) {
        try {
            l.validateNewGroup(args);
        } catch (ValidationException e) {
            throw new ResourceConflictException(e.getMessage(), e);
        }
    }
    return json.format(GroupDescriptions.forAccountGroup(createGroup(args)));
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) Account(com.google.gerrit.reviewdb.client.Account) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) ValidationException(com.google.gerrit.server.validators.ValidationException) GroupCreationValidationListener(com.google.gerrit.server.validators.GroupCreationValidationListener) ArrayList(java.util.ArrayList) CreateGroupArgs(com.google.gerrit.server.account.CreateGroupArgs) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException)

Example 13 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput in project gerrit by GerritCodeReview.

the class CreateGroupCommand method createGroup.

private GroupResource createGroup() throws RestApiException, OrmException, IOException {
    GroupInput input = new GroupInput();
    input.description = groupDescription;
    input.visibleToAll = visibleToAll;
    if (ownerGroupId != null) {
        input.ownerId = String.valueOf(ownerGroupId.get());
    }
    GroupInfo group = createGroupFactory.create(groupName).apply(TopLevelResource.INSTANCE, input);
    return groups.parse(TopLevelResource.INSTANCE, IdString.fromUrl(group.id));
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) GroupInfo(com.google.gerrit.extensions.common.GroupInfo)

Aggregations

GroupInput (com.google.gerrit.extensions.api.groups.GroupInput)13 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)4 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 Test (org.junit.Test)3 GroupAssert.assertGroupInfo (com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo)2 RestSession (com.google.gerrit.acceptance.RestSession)1 TestAccount (com.google.gerrit.acceptance.TestAccount)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)1 Account (com.google.gerrit.reviewdb.client.Account)1 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)1 Id (com.google.gerrit.reviewdb.client.AccountGroup.Id)1 CreateGroupArgs (com.google.gerrit.server.account.CreateGroupArgs)1 GroupCreationValidationListener (com.google.gerrit.server.validators.GroupCreationValidationListener)1 ValidationException (com.google.gerrit.server.validators.ValidationException)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1