Search in sources :

Example 6 with ProjectWatchKey

use of com.google.gerrit.server.account.WatchConfig.ProjectWatchKey in project gerrit by GerritCodeReview.

the class ProjectWatch method getWatchers.

/** Returns all watchers that are relevant */
public final Watchers getWatchers(NotifyType type, boolean includeWatchersFromNotifyConfig) throws OrmException {
    Watchers matching = new Watchers();
    Set<Account.Id> projectWatchers = new HashSet<>();
    for (AccountState a : args.accountQueryProvider.get().byWatchedProject(project)) {
        Account.Id accountId = a.getAccount().getId();
        for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e : a.getProjectWatches().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, Set<NotifyType>> e : a.getProjectWatches().entrySet()) {
            if (args.allProjectsName.equals(e.getKey().project())) {
                Account.Id accountId = a.getAccount().getId();
                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().getNotifyConfigs()) {
            if (nc.isNotify(type)) {
                try {
                    add(matching, nc);
                } catch (QueryParseException e) {
                    log.warn("Project {} has invalid notify {} filter \"{}\": {}", state.getProject().getName(), nc.getName(), nc.getFilter(), e.getMessage());
                }
            }
        }
    }
    return matching;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) HashSet(java.util.HashSet) Set(java.util.Set) ProjectWatchKey(com.google.gerrit.server.account.WatchConfig.ProjectWatchKey) AccountState(com.google.gerrit.server.account.AccountState) QueryParseException(com.google.gerrit.server.query.QueryParseException) ProjectState(com.google.gerrit.server.project.ProjectState) NotifyConfig(com.google.gerrit.server.git.NotifyConfig) Map(java.util.Map) HashSet(java.util.HashSet)

Example 7 with ProjectWatchKey

use of com.google.gerrit.server.account.WatchConfig.ProjectWatchKey in project gerrit by GerritCodeReview.

the class AccountCacheImpl method missing.

private static AccountState missing(Account.Id accountId) {
    Account account = new Account(accountId, TimeUtil.nowTs());
    account.setActive(false);
    Set<AccountGroup.UUID> anon = ImmutableSet.of();
    return new AccountState(account, anon, Collections.emptySet(), new HashMap<ProjectWatchKey, Set<NotifyType>>());
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ProjectWatchKey(com.google.gerrit.server.account.WatchConfig.ProjectWatchKey)

Aggregations

ProjectWatchKey (com.google.gerrit.server.account.WatchConfig.ProjectWatchKey)7 Set (java.util.Set)6 Account (com.google.gerrit.reviewdb.client.Account)5 NotifyType (com.google.gerrit.server.account.WatchConfig.NotifyType)3 EnumSet (java.util.EnumSet)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ProjectWatchInfo (com.google.gerrit.extensions.client.ProjectWatchInfo)2 Project (com.google.gerrit.reviewdb.client.Project)2 QueryParseException (com.google.gerrit.server.query.QueryParseException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 AccountState (com.google.gerrit.server.account.AccountState)1 WatchConfig (com.google.gerrit.server.account.WatchConfig)1 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)1 NotifyConfig (com.google.gerrit.server.git.NotifyConfig)1 ProjectState (com.google.gerrit.server.project.ProjectState)1 AndPredicate (com.google.gerrit.server.query.AndPredicate)1