Search in sources :

Example 31 with InternalGroup

use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.

the class GroupConfig method onSave.

// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Override
protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException {
    checkLoaded();
    if (!groupCreation.isPresent() && !groupDelta.isPresent()) {
        // Group was neither created nor changed. -> A new commit isn't necessary.
        return false;
    }
    if (!allowSaveEmptyName && getNewName().equals(Optional.of(""))) {
        throw new ConfigInvalidException(String.format("Name of the group %s must be defined", groupUuid.get()));
    }
    // Commit timestamps are internally truncated to seconds. To return the correct 'createdOn' time
    // for new groups, we explicitly need to truncate the timestamp here.
    Instant commitTimestamp = TimeUtil.truncateToSecond(groupDelta.flatMap(GroupDelta::getUpdatedOn).orElseGet(TimeUtil::now));
    commit.setAuthor(new PersonIdent(commit.getAuthor(), Date.from(commitTimestamp)));
    commit.setCommitter(new PersonIdent(commit.getCommitter(), Date.from(commitTimestamp)));
    InternalGroup updatedGroup = updateGroup(commitTimestamp);
    String commitMessage = createCommitMessage(loadedGroup, updatedGroup);
    commit.setMessage(commitMessage);
    loadedGroup = Optional.of(updatedGroup);
    groupCreation = Optional.empty();
    groupDelta = Optional.empty();
    return true;
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Instant(java.time.Instant) InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 32 with InternalGroup

use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.

the class Groups method getExternalGroupsFromNoteDb.

private static Stream<AccountGroup.UUID> getExternalGroupsFromNoteDb(AllUsersName allUsersName, Repository allUsersRepo, ImmutableList<Ref> internalGroupsRefs) throws IOException, ConfigInvalidException {
    ImmutableSet.Builder<AccountGroup.UUID> allSubgroups = ImmutableSet.builder();
    for (Ref internalGroupRef : internalGroupsRefs) {
        AccountGroup.UUID uuid = AccountGroup.UUID.fromRef(internalGroupRef.getName());
        if (uuid == null) {
            logger.atWarning().log("Failed to get the group UUID from ref: %s", internalGroupRef.getName());
            continue;
        }
        Optional<InternalGroup> group = getGroupFromNoteDb(allUsersName, allUsersRepo, uuid, internalGroupRef.getObjectId());
        group.map(InternalGroup::getSubgroups).ifPresent(allSubgroups::addAll);
    }
    return allSubgroups.build().stream().filter(groupUuid -> !groupUuid.isInternalGroup());
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ImmutableSet(com.google.common.collect.ImmutableSet) AccountGroup(com.google.gerrit.entities.AccountGroup) InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 33 with InternalGroup

use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.

the class GroupsIT method getGroup.

@Test
public void getGroup() throws Exception {
    InternalGroup adminGroup = adminGroup();
    testGetGroup(adminGroup.getGroupUUID().get(), adminGroup);
    testGetGroup(adminGroup.getName(), adminGroup);
    testGetGroup(adminGroup.getId().get(), adminGroup);
}
Also used : InternalGroup(com.google.gerrit.entities.InternalGroup) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 34 with InternalGroup

use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.

the class GroupsIT method allGroupInfoFieldsSetCorrectly.

@Test
public void allGroupInfoFieldsSetCorrectly() throws Exception {
    InternalGroup adminGroup = adminGroup();
    Map<String, GroupInfo> groups = gApi.groups().list().addGroup(adminGroup.getName()).getAsMap();
    assertThatMap(groups).keys().containsExactly("Administrators");
    assertGroupInfo(adminGroup, Iterables.getOnlyElement(groups.values()));
}
Also used : GroupAssert.assertGroupInfo(com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) InternalGroup(com.google.gerrit.entities.InternalGroup) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 35 with InternalGroup

use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.

the class GroupConfigTest method createdOnDefaultsToNow.

@Test
public void createdOnDefaultsToNow() throws Exception {
    // Git timestamps are only precise to the second.
    Instant testStart = TimeUtil.truncateToSecond(TimeUtil.now());
    InternalGroupCreation groupCreation = InternalGroupCreation.builder().setGroupUUID(groupUuid).setNameKey(groupName).setId(groupId).build();
    createGroup(groupCreation);
    Optional<InternalGroup> group = loadGroup(groupCreation.getGroupUUID());
    assertThatGroup(group).value().createdOn().isAtLeast(testStart);
}
Also used : Instant(java.time.Instant) InternalGroup(com.google.gerrit.entities.InternalGroup) Test(org.junit.Test)

Aggregations

InternalGroup (com.google.gerrit.entities.InternalGroup)41 AccountGroup (com.google.gerrit.entities.AccountGroup)18 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)6 AccountGroupMemberAudit (com.google.gerrit.entities.AccountGroupMemberAudit)5 GroupReference (com.google.gerrit.entities.GroupReference)5 Account (com.google.gerrit.entities.Account)4 AccountGroupByIdAudit (com.google.gerrit.entities.AccountGroupByIdAudit)4 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)4 Instant (java.time.Instant)4 GroupDescription (com.google.gerrit.entities.GroupDescription)3 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)3 InternalGroupDescription (com.google.gerrit.server.group.InternalGroupDescription)3 GroupDelta (com.google.gerrit.server.group.db.GroupDelta)3 HashSet (java.util.HashSet)3 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 ConsistencyProblemInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo)2 TraceTimer (com.google.gerrit.server.logging.TraceContext.TraceTimer)2 IOException (java.io.IOException)2 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)2