use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.
the class ProjectConfig method mapGroupReferences.
private Map<String, GroupReference> mapGroupReferences() {
Collection<GroupReference> references = groupList.references();
Map<String, GroupReference> result = new HashMap<>(references.size());
for (GroupReference ref : references) {
result.put(ref.getName(), ref);
}
return result;
}
use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.
the class ProjectConfig method saveNotifySections.
private void saveNotifySections(Config rc, Set<AccountGroup.UUID> keepGroups) {
for (NotifyConfig nc : sort(notifySections.values())) {
List<String> email = new ArrayList<>();
for (GroupReference gr : nc.getGroups()) {
if (gr.getUUID() != null) {
keepGroups.add(gr.getUUID());
}
email.add(new PermissionRule(gr).asString(false));
}
Collections.sort(email);
List<String> addrs = new ArrayList<>();
for (Address addr : nc.getAddresses()) {
addrs.add(addr.toString());
}
Collections.sort(addrs);
email.addAll(addrs);
set(rc, NOTIFY, nc.getName(), KEY_HEADER, nc.getHeader(), NotifyConfig.Header.BCC);
if (email.isEmpty()) {
rc.unset(NOTIFY, nc.getName(), KEY_EMAIL);
} else {
rc.setStringList(NOTIFY, nc.getName(), KEY_EMAIL, email);
}
if (nc.getNotify().equals(EnumSet.of(NotifyType.ALL))) {
rc.unset(NOTIFY, nc.getName(), KEY_TYPE);
} else {
List<String> types = Lists.newArrayListWithCapacity(4);
for (NotifyType t : NotifyType.values()) {
if (nc.isNotify(t)) {
types.add(StringUtils.toLowerCase(t.name()));
}
}
rc.setStringList(NOTIFY, nc.getName(), KEY_TYPE, types);
}
set(rc, NOTIFY, nc.getName(), KEY_FILTER, nc.getFilter());
}
}
use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.
the class ProjectConfig method updateGroupNames.
/**
* Check all GroupReferences use current group name, repairing stale ones.
*
* @param groupBackend cache to use when looking up group information by UUID.
* @return true if one or more group names was stale.
*/
public boolean updateGroupNames(GroupBackend groupBackend) {
boolean dirty = false;
for (GroupReference ref : groupList.references()) {
GroupDescription.Basic g = groupBackend.get(ref.getUUID());
if (g != null && !g.getName().equals(ref.getName())) {
dirty = true;
ref.setName(g.getName());
}
}
return dirty;
}
use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.
the class RenameGroupOp method run.
@Override
public void run() {
Iterable<Project.NameKey> names = tryingAgain ? retryOn : projectCache.all();
for (Project.NameKey projectName : names) {
ProjectConfig config = projectCache.get(projectName).getConfig();
GroupReference ref = config.getGroup(uuid);
if (ref == null || newName.equals(ref.getName())) {
continue;
}
try (MetaDataUpdate md = metaDataUpdateFactory.create(projectName)) {
rename(md);
} catch (RepositoryNotFoundException noProject) {
continue;
} catch (ConfigInvalidException | IOException err) {
log.error("Cannot rename group " + oldName + " in " + projectName, err);
}
}
// another attempt. If it doesn't update after that, give up.
if (!retryOn.isEmpty() && !tryingAgain) {
tryingAgain = true;
@SuppressWarnings("unused") Future<?> possiblyIgnoredError = start(5, TimeUnit.MINUTES);
}
}
use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.
the class ProjectConfig method loadNotifySections.
/**
* Parses the [notify] sections out of the configuration file.
*
* <pre>
* [notify "reviewers"]
* email = group Reviewers
* type = new_changes
*
* [notify "dev-team"]
* email = dev-team@example.com
* filter = branch:master
*
* [notify "qa"]
* email = qa@example.com
* filter = branch:\"^(maint|stable)-.*\"
* type = submitted_changes
* </pre>
*/
private void loadNotifySections(Config rc, Map<String, GroupReference> groupsByName) {
notifySections = new HashMap<>();
for (String sectionName : rc.getSubsections(NOTIFY)) {
NotifyConfig n = new NotifyConfig();
n.setName(sectionName);
n.setFilter(rc.getString(NOTIFY, sectionName, KEY_FILTER));
EnumSet<NotifyType> types = EnumSet.noneOf(NotifyType.class);
types.addAll(ConfigUtil.getEnumList(rc, NOTIFY, sectionName, KEY_TYPE, NotifyType.ALL));
n.setTypes(types);
n.setHeader(rc.getEnum(NOTIFY, sectionName, KEY_HEADER, NotifyConfig.Header.BCC));
for (String dst : rc.getStringList(NOTIFY, sectionName, KEY_EMAIL)) {
if (dst.startsWith("group ")) {
String groupName = dst.substring(6).trim();
GroupReference ref = groupsByName.get(groupName);
if (ref == null) {
ref = new GroupReference(null, groupName);
groupsByName.put(ref.getName(), ref);
}
if (ref.getUUID() != null) {
n.addEmail(ref);
} else {
error(new ValidationError(PROJECT_CONFIG, "group \"" + ref.getName() + "\" not in " + GroupList.FILE_NAME));
}
} else if (dst.startsWith("user ")) {
error(new ValidationError(PROJECT_CONFIG, dst + " not supported"));
} else {
try {
n.addEmail(Address.parse(dst));
} catch (IllegalArgumentException err) {
error(new ValidationError(PROJECT_CONFIG, "notify section \"" + sectionName + "\" has invalid email \"" + dst + "\""));
}
}
}
notifySections.put(sectionName, n);
}
}
Aggregations