Search in sources :

Example 1 with GroupDelta

use of com.google.gerrit.server.group.db.GroupDelta 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 GroupDelta

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

the class PutOptions method apply.

@Override
public Response<GroupOptionsInfo> apply(GroupResource resource, GroupOptionsInfo input) throws NotInternalGroupException, AuthException, BadRequestException, ResourceNotFoundException, IOException, ConfigInvalidException {
    GroupDescription.Internal internalGroup = resource.asInternalGroup().orElseThrow(NotInternalGroupException::new);
    if (!resource.getControl().isOwner()) {
        throw new AuthException("Not group owner");
    }
    if (input == null) {
        throw new BadRequestException("options are required");
    }
    if (input.visibleToAll == null) {
        input.visibleToAll = false;
    }
    if (internalGroup.isVisibleToAll() != input.visibleToAll) {
        AccountGroup.UUID groupUuid = internalGroup.getGroupUUID();
        GroupDelta groupDelta = GroupDelta.builder().setVisibleToAll(input.visibleToAll).build();
        try {
            groupsUpdateProvider.get().updateGroup(groupUuid, groupDelta);
        } catch (NoSuchGroupException e) {
            throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
        }
    }
    GroupOptionsInfo options = new GroupOptionsInfo();
    if (input.visibleToAll) {
        options.visibleToAll = true;
    }
    return Response.ok(options);
}
Also used : GroupDescription(com.google.gerrit.entities.GroupDescription) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) AuthException(com.google.gerrit.extensions.restapi.AuthException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) GroupOptionsInfo(com.google.gerrit.extensions.common.GroupOptionsInfo) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException)

Example 3 with GroupDelta

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

the class PutName method renameGroup.

private void renameGroup(GroupDescription.Internal group, String newName) throws ResourceConflictException, ResourceNotFoundException, IOException, ConfigInvalidException {
    AccountGroup.UUID groupUuid = group.getGroupUUID();
    GroupDelta groupDelta = GroupDelta.builder().setName(AccountGroup.nameKey(newName)).build();
    try {
        groupsUpdateProvider.get().updateGroup(groupUuid, groupDelta);
    } catch (NoSuchGroupException e) {
        throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
    } catch (DuplicateKeyException e) {
        throw new ResourceConflictException("group with name " + newName + " 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) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException) DuplicateKeyException(com.google.gerrit.exceptions.DuplicateKeyException)

Example 4 with GroupDelta

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

the class GroupsUpdateIT method groupUpdateFailsWithExceptionForNotExistingGroup.

@Test
public void groupUpdateFailsWithExceptionForNotExistingGroup() throws Exception {
    GroupDelta groupDelta = GroupDelta.builder().setDescription("A description for the group").build();
    assertThrows(NoSuchGroupException.class, () -> updateGroup(AccountGroup.uuid("nonexistent-group-UUID"), groupDelta));
}
Also used : GroupDelta(com.google.gerrit.server.group.db.GroupDelta) Test(org.junit.Test)

Example 5 with GroupDelta

use of com.google.gerrit.server.group.db.GroupDelta 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)

Aggregations

GroupDelta (com.google.gerrit.server.group.db.GroupDelta)20 AccountGroup (com.google.gerrit.entities.AccountGroup)12 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)12 GroupDescription (com.google.gerrit.entities.GroupDescription)8 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)8 Sets (com.google.common.collect.Sets)7 AuthException (com.google.gerrit.extensions.restapi.AuthException)7 GroupsUpdate (com.google.gerrit.server.group.db.GroupsUpdate)7 Inject (com.google.inject.Inject)7 Provider (com.google.inject.Provider)7 Singleton (com.google.inject.Singleton)7 IOException (java.io.IOException)7 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)7 Set (java.util.Set)6 Account (com.google.gerrit.entities.Account)5 Response (com.google.gerrit.extensions.restapi.Response)5 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)5 UserInitiated (com.google.gerrit.server.UserInitiated)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5