Search in sources :

Example 1 with InternalGroupCreation

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

the class GroupOperationsImpl method createNewGroup.

private AccountGroup.UUID createNewGroup(TestGroupCreation groupCreation) throws ConfigInvalidException, IOException {
    InternalGroupCreation internalGroupCreation = toInternalGroupCreation(groupCreation);
    GroupDelta groupDelta = toGroupDelta(groupCreation);
    InternalGroup internalGroup = groupsUpdate.createGroup(internalGroupCreation, groupDelta);
    return internalGroup.getGroupUUID();
}
Also used : GroupDelta(com.google.gerrit.server.group.db.GroupDelta) InternalGroupCreation(com.google.gerrit.server.group.db.InternalGroupCreation) InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 2 with InternalGroupCreation

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

the class GroupsUpdateIT method groupCreationIsRetriedWhenFailedDueToConcurrentNameModification.

@Test
public void groupCreationIsRetriedWhenFailedDueToConcurrentNameModification() throws Exception {
    InternalGroupCreation groupCreation = getGroupCreation("users", "users-UUID");
    GroupDelta groupDelta = GroupDelta.builder().setMemberModification(new CreateAnotherGroupOnceAsSideEffectOfMemberModification("verifiers")).build();
    createGroup(groupCreation, groupDelta);
    Stream<String> allGroupNames = getAllGroupNames();
    assertThat(allGroupNames).containsAtLeast("users", "verifiers");
}
Also used : GroupDelta(com.google.gerrit.server.group.db.GroupDelta) InternalGroupCreation(com.google.gerrit.server.group.db.InternalGroupCreation) Test(org.junit.Test)

Example 3 with InternalGroupCreation

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

the class SchemaCreatorImpl method createBatchUsersGroup.

private void createBatchUsersGroup(Sequences seqs, Repository allUsersRepo, GroupReference groupReference, AccountGroup.UUID adminsGroupUuid) throws IOException, ConfigInvalidException {
    InternalGroupCreation groupCreation = getGroupCreation(seqs, groupReference);
    GroupDelta groupDelta = GroupDelta.builder().setDescription("Users who perform batch actions on Gerrit").setOwnerGroupUUID(adminsGroupUuid).build();
    createGroup(allUsersRepo, groupCreation, groupDelta);
}
Also used : GroupDelta(com.google.gerrit.server.group.db.GroupDelta) InternalGroupCreation(com.google.gerrit.server.group.db.InternalGroupCreation)

Example 4 with InternalGroupCreation

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

the class CreateGroup method createGroup.

private InternalGroup createGroup(CreateGroupArgs createGroupArgs) throws ResourceConflictException, IOException, ConfigInvalidException {
    String nameLower = createGroupArgs.getGroupName().toLowerCase(Locale.US);
    for (String name : systemGroupBackend.getNames()) {
        if (name.toLowerCase(Locale.US).equals(nameLower)) {
            throw new ResourceConflictException("group '" + name + "' already exists");
        }
    }
    for (String name : systemGroupBackend.getReservedNames()) {
        if (name.toLowerCase(Locale.US).equals(nameLower)) {
            throw new ResourceConflictException("group name '" + name + "' is reserved");
        }
    }
    AccountGroup.Id groupId = AccountGroup.id(sequences.nextGroupId());
    AccountGroup.UUID uuid = MoreObjects.firstNonNull(createGroupArgs.uuid, GroupUuid.make(createGroupArgs.getGroupName(), self.get().newCommitterIdent(TimeUtil.now(), serverTimeZone)));
    InternalGroupCreation groupCreation = InternalGroupCreation.builder().setGroupUUID(uuid).setNameKey(createGroupArgs.getGroup()).setId(groupId).build();
    GroupDelta.Builder groupDeltaBuilder = GroupDelta.builder().setVisibleToAll(createGroupArgs.visibleToAll);
    if (createGroupArgs.ownerGroupUuid != null) {
        Optional<InternalGroup> ownerGroup = groupCache.get(createGroupArgs.ownerGroupUuid);
        ownerGroup.map(InternalGroup::getGroupUUID).ifPresent(groupDeltaBuilder::setOwnerGroupUUID);
    }
    if (createGroupArgs.groupDescription != null) {
        groupDeltaBuilder.setDescription(createGroupArgs.groupDescription);
    }
    groupDeltaBuilder.setMemberModification(members -> ImmutableSet.copyOf(createGroupArgs.initialMembers));
    try {
        return groupsUpdateProvider.get().createGroup(groupCreation, groupDeltaBuilder.build());
    } catch (DuplicateKeyException e) {
        throw new ResourceConflictException("group '" + createGroupArgs.getGroupName() + "' already exists", e);
    }
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) IdString(com.google.gerrit.extensions.restapi.IdString) InternalGroupCreation(com.google.gerrit.server.group.db.InternalGroupCreation) DuplicateKeyException(com.google.gerrit.exceptions.DuplicateKeyException) InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 5 with InternalGroupCreation

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

the class SchemaCreatorImpl method createAdminsGroup.

private void createAdminsGroup(Sequences seqs, Repository allUsersRepo, GroupReference groupReference) throws IOException, ConfigInvalidException {
    InternalGroupCreation groupCreation = getGroupCreation(seqs, groupReference);
    GroupDelta groupDelta = GroupDelta.builder().setDescription("Gerrit Site Administrators").build();
    createGroup(allUsersRepo, groupCreation, groupDelta);
}
Also used : GroupDelta(com.google.gerrit.server.group.db.GroupDelta) InternalGroupCreation(com.google.gerrit.server.group.db.InternalGroupCreation)

Aggregations

GroupDelta (com.google.gerrit.server.group.db.GroupDelta)6 InternalGroupCreation (com.google.gerrit.server.group.db.InternalGroupCreation)6 InternalGroup (com.google.gerrit.entities.InternalGroup)2 AccountGroup (com.google.gerrit.entities.AccountGroup)1 DuplicateKeyException (com.google.gerrit.exceptions.DuplicateKeyException)1 IdString (com.google.gerrit.extensions.restapi.IdString)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 Test (org.junit.Test)1