Search in sources :

Example 1 with NotifyConfig

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;
}
Also used : Account(com.google.gerrit.entities.Account) ProjectWatchKey(com.google.gerrit.server.account.ProjectWatches.ProjectWatchKey) AccountState(com.google.gerrit.server.account.AccountState) QueryParseException(com.google.gerrit.index.query.QueryParseException) ImmutableSet(com.google.common.collect.ImmutableSet) NotifyConfig(com.google.gerrit.entities.NotifyConfig) ProjectState(com.google.gerrit.server.project.ProjectState) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with NotifyConfig

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());
    }
}
Also used : NotifyType(com.google.gerrit.entities.NotifyConfig.NotifyType) Address(com.google.gerrit.entities.Address) ArrayList(java.util.ArrayList) NotifyConfig(com.google.gerrit.entities.NotifyConfig) GroupReference(com.google.gerrit.entities.GroupReference)

Example 3 with NotifyConfig

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);
}
Also used : NotifyConfig(com.google.gerrit.entities.NotifyConfig) Test(org.junit.Test)

Aggregations

NotifyConfig (com.google.gerrit.entities.NotifyConfig)3 ImmutableSet (com.google.common.collect.ImmutableSet)1 Account (com.google.gerrit.entities.Account)1 Address (com.google.gerrit.entities.Address)1 GroupReference (com.google.gerrit.entities.GroupReference)1 NotifyType (com.google.gerrit.entities.NotifyConfig.NotifyType)1 QueryParseException (com.google.gerrit.index.query.QueryParseException)1 AccountState (com.google.gerrit.server.account.AccountState)1 ProjectWatchKey (com.google.gerrit.server.account.ProjectWatches.ProjectWatchKey)1 ProjectState (com.google.gerrit.server.project.ProjectState)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Test (org.junit.Test)1