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;
}
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());
}
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);
}
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()));
}
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);
}
Aggregations