use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class GroupNameNotes method ensureOldNameIsPresent.
private void ensureOldNameIsPresent(NoteMap noteMap) throws IOException, ConfigInvalidException {
if (oldGroupName.isPresent()) {
AccountGroup.NameKey oldName = oldGroupName.get();
ObjectId noteKey = getNoteKey(oldName);
ObjectId noteDataBlobId = noteMap.get(noteKey);
if (noteDataBlobId == null) {
throw new ConfigInvalidException(String.format("Group name '%s' doesn't exist in the list of all names", oldName));
}
GroupReference group = getGroupReference(reader, noteDataBlobId);
AccountGroup.UUID foundUuid = group.getUUID();
if (!Objects.equals(groupUuid, foundUuid)) {
throw new ConfigInvalidException(String.format("Name '%s' points to UUID '%s' and not to '%s'", oldName, foundUuid, groupUuid));
}
}
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class RenameGroupOp method rename.
private void rename(MetaDataUpdate md) throws IOException, ConfigInvalidException {
boolean success = false;
for (int attempts = 0; !success && attempts < MAX_TRIES; attempts++) {
ProjectConfig config = projectConfigFactory.read(md);
// The group isn't referenced, or its name has been fixed already.
//
GroupReference ref = config.getGroup(uuid);
if (ref == null || newName.equals(ref.getName())) {
projectCache.evictAndReindex(config.getProject());
return;
}
config.renameGroup(uuid, newName);
md.getCommitBuilder().setAuthor(author);
md.setMessage("Rename group " + oldName + " to " + newName + "\n");
try {
config.commit(md);
projectCache.evictAndReindex(config.getProject());
success = true;
} catch (IOException e) {
logger.atSevere().withCause(e).log("Could not commit rename of group %s to %s in %s", oldName, newName, md.getProjectName().get());
try {
Thread.sleep(25);
} catch (InterruptedException wakeUp) {
continue;
}
}
}
if (!success) {
if (tryingAgain) {
logger.atWarning().log("Could not rename group %s to %s in %s", oldName, newName, md.getProjectName().get());
} else {
retryOn.add(md.getProjectName());
}
}
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class ReviewersUtil method suggestAccountGroups.
private List<SuggestedReviewerInfo> suggestAccountGroups(SuggestReviewers suggestReviewers, ProjectState projectState, VisibilityControl visibilityControl, int limit) throws IOException {
try (Timer0.Context ctx = metrics.queryGroupsLatency.start()) {
List<SuggestedReviewerInfo> groups = new ArrayList<>();
for (GroupReference g : suggestAccountGroups(suggestReviewers, projectState)) {
GroupAsReviewer result = suggestGroupAsReviewer(suggestReviewers, projectState.getProject(), g, visibilityControl);
if (result.allowed || result.allowedWithConfirmation) {
GroupBaseInfo info = new GroupBaseInfo();
info.id = Url.encode(g.getUUID().get());
info.name = g.getName();
SuggestedReviewerInfo suggestedReviewerInfo = new SuggestedReviewerInfo();
suggestedReviewerInfo.group = info;
suggestedReviewerInfo.count = result.size;
if (result.allowedWithConfirmation) {
suggestedReviewerInfo.confirm = true;
}
groups.add(suggestedReviewerInfo);
if (groups.size() >= limit) {
break;
}
}
}
return groups;
}
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class AgreementJson method format.
public AgreementInfo format(ContributorAgreement ca) throws PermissionBackendException {
AgreementInfo info = new AgreementInfo();
info.name = ca.getName();
info.description = ca.getDescription();
info.url = ca.getAgreementUrl();
GroupReference autoVerifyGroup = ca.getAutoVerify();
if (autoVerifyGroup != null && self.get().isIdentifiedUser()) {
IdentifiedUser user = identifiedUserFactory.create(self.get().getAccountId());
try {
GroupControl gc = genericGroupControlFactory.controlFor(user, autoVerifyGroup.getUUID());
GroupResource group = new GroupResource(gc);
info.autoVerifyGroup = groupJson.format(group);
} catch (NoSuchGroupException | StorageException e) {
logger.atWarning().log("autoverify group \"%s\" does not exist, referenced in CLA \"%s\"", autoVerifyGroup.getName(), ca.getName());
}
}
return info;
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class GroupNameNotesTest method emptyGroupName.
@Test
public void emptyGroupName() throws Exception {
GroupReference g = newGroup("");
updateAllGroups(newPersonIdent(), g);
assertThat(GroupNameNotes.loadAllGroups(repo)).containsExactly(g);
assertThat(readNameNote(g)).isEqualTo("[group]\n\tuuid = -1\n\tname = \n");
}
Aggregations