use of com.google.gerrit.entities.NotifyConfig in project gerrit by GerritCodeReview.
the class ProjectWatch method getWatchers.
/**
* Returns all watchers that are relevant
*/
public final Watchers getWatchers(NotifyConfig.NotifyType type, boolean includeWatchersFromNotifyConfig) {
Watchers matching = new Watchers();
Set<Account.Id> projectWatchers = new HashSet<>();
for (AccountState a : args.accountQueryProvider.get().byWatchedProject(project)) {
Account.Id accountId = a.account().id();
for (Map.Entry<ProjectWatchKey, ImmutableSet<NotifyConfig.NotifyType>> e : a.projectWatches().entrySet()) {
if (project.equals(e.getKey().project()) && add(matching, accountId, e.getKey(), e.getValue(), type)) {
// We only want to prevent matching All-Projects if this filter hits
projectWatchers.add(accountId);
}
}
}
for (AccountState a : args.accountQueryProvider.get().byWatchedProject(args.allProjectsName)) {
for (Map.Entry<ProjectWatchKey, ImmutableSet<NotifyConfig.NotifyType>> e : a.projectWatches().entrySet()) {
if (args.allProjectsName.equals(e.getKey().project())) {
Account.Id accountId = a.account().id();
if (!projectWatchers.contains(accountId)) {
add(matching, accountId, e.getKey(), e.getValue(), type);
}
}
}
}
if (!includeWatchersFromNotifyConfig) {
return matching;
}
for (ProjectState state : projectState.tree()) {
for (NotifyConfig nc : state.getConfig().getNotifySections().values()) {
if (nc.isNotify(type)) {
try {
add(matching, state.getNameKey(), nc);
} catch (QueryParseException e) {
logger.atInfo().log("Project %s has invalid notify %s filter \"%s\": %s", state.getName(), nc.getName(), nc.getFilter(), e.getMessage());
}
}
}
}
return matching;
}
use of com.google.gerrit.entities.NotifyConfig in project gerrit by GerritCodeReview.
the class ProjectConfig method saveNotifySections.
private void saveNotifySections(Config rc, Set<AccountGroup.UUID> keepGroups) {
unsetSection(rc, NOTIFY);
for (NotifyConfig nc : sort(notifySections.values())) {
nc.getGroups().stream().map(GroupReference::getUUID).filter(Objects::nonNull).forEach(keepGroups::add);
List<String> email = nc.getGroups().stream().map(gr -> PermissionRule.create(gr).asString(false)).sorted().collect(toList());
// Separate stream operation so that emails list contains 2 sorted sub-lists.
nc.getAddresses().stream().map(Address::toString).sorted().forEach(email::add);
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(Sets.immutableEnumSet(NotifyType.ALL))) {
rc.unset(NOTIFY, nc.getName(), KEY_TYPE);
} else {
List<String> types = new ArrayList<>(4);
for (NotifyType t : NotifyType.values()) {
if (nc.isNotify(t)) {
types.add(t.name().toLowerCase(Locale.US));
}
}
rc.setStringList(NOTIFY, nc.getName(), KEY_TYPE, types);
}
set(rc, NOTIFY, nc.getName(), KEY_FILTER, nc.getFilter());
}
}
use of com.google.gerrit.entities.NotifyConfig in project gerrit by GerritCodeReview.
the class NotifyConfigSerializerTest method roundTripWithMinimalValues.
@Test
public void roundTripWithMinimalValues() {
NotifyConfig autoValue = NotifyConfig.builder().setName("foo-bar").build();
assertThat(deserialize(serialize(autoValue))).isEqualTo(autoValue);
}
Aggregations