Search in sources :

Example 11 with Predicate

use of com.google.gerrit.index.query.Predicate in project gerrit by GerritCodeReview.

the class ChangeQueryBuilder method reviewerByState.

public Predicate<ChangeData> reviewerByState(String who, ReviewerStateInternal state, boolean forDefaultField) throws QueryParseException, IOException, ConfigInvalidException {
    Predicate<ChangeData> reviewerByEmailPredicate = null;
    Address address = Address.tryParse(who);
    if (address != null) {
        reviewerByEmailPredicate = ReviewerByEmailPredicate.forState(address, state);
    }
    Predicate<ChangeData> reviewerPredicate = null;
    try {
        Set<Account.Id> accounts = parseAccount(who);
        if (!forDefaultField || accounts.size() <= MAX_ACCOUNTS_PER_DEFAULT_FIELD) {
            reviewerPredicate = Predicate.or(accounts.stream().map(id -> ReviewerPredicate.forState(id, state)).collect(toList()));
        } else {
            logger.atFine().log("Skipping reviewer predicate for %s in default field query" + " because the number of matched accounts (%d) exceeds the limit of %d", who, accounts.size(), MAX_ACCOUNTS_PER_DEFAULT_FIELD);
        }
    } catch (QueryParseException e) {
        logger.atFine().log("Parsing %s as account failed: %s", who, e.getMessage());
        // Propagate this exception only if we can't use 'who' to query by email
        if (reviewerByEmailPredicate == null) {
            throw e;
        }
    }
    if (reviewerPredicate != null && reviewerByEmailPredicate != null) {
        return Predicate.or(reviewerPredicate, reviewerByEmailPredicate);
    } else if (reviewerPredicate != null) {
        return reviewerPredicate;
    } else if (reviewerByEmailPredicate != null) {
        return reviewerByEmailPredicate;
    } else {
        return Predicate.any();
    }
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) GroupBackend(com.google.gerrit.server.account.GroupBackend) Arrays(java.util.Arrays) ProjectCache(com.google.gerrit.server.project.ProjectCache) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) Inject(com.google.inject.Inject) OperatorAliasConfig(com.google.gerrit.server.config.OperatorAliasConfig) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) Config(org.eclipse.jgit.lib.Config) ChangeTriplet(com.google.gerrit.server.change.ChangeTriplet) VersionedAccountQueries(com.google.gerrit.server.account.VersionedAccountQueries) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) ProvisionException(com.google.inject.ProvisionException) Splitter(com.google.common.base.Splitter) Collectors.toSet(java.util.stream.Collectors.toSet) FieldDef(com.google.gerrit.index.FieldDef) Schema(com.google.gerrit.index.Schema) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) Collection(java.util.Collection) LimitPredicate(com.google.gerrit.index.query.LimitPredicate) Account(com.google.gerrit.entities.Account) Set(java.util.Set) SubmitRecord(com.google.gerrit.entities.SubmitRecord) BranchNameKey(com.google.gerrit.entities.BranchNameKey) GroupReference(com.google.gerrit.entities.GroupReference) Objects(java.util.Objects) List(java.util.List) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) CHANGE_ID_PATTERN(com.google.gerrit.entities.Change.CHANGE_ID_PATTERN) ChangeData.asChanges(com.google.gerrit.server.query.change.ChangeData.asChanges) PluginSetContext(com.google.gerrit.server.plugincontext.PluginSetContext) SubmitDryRun(com.google.gerrit.server.submit.SubmitDryRun) Optional(java.util.Optional) Providers(com.google.inject.util.Providers) Pattern(java.util.regex.Pattern) SchemaUtil(com.google.gerrit.index.SchemaUtil) ValOp(com.google.gerrit.server.query.change.PredicateArgs.ValOp) FluentLogger(com.google.common.flogger.FluentLogger) QueryRequiresAuthException(com.google.gerrit.index.query.QueryRequiresAuthException) ChangeIndexRewriter(com.google.gerrit.server.index.change.ChangeIndexRewriter) AccountCache(com.google.gerrit.server.account.AccountCache) Iterables(com.google.common.collect.Iterables) IndexConfig(com.google.gerrit.index.IndexConfig) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) MergeabilityComputationBehavior(com.google.gerrit.server.change.MergeabilityComputationBehavior) GroupBackends(com.google.gerrit.server.account.GroupBackends) HasOperandAliasConfig(com.google.gerrit.server.config.HasOperandAliasConfig) CommentsUtil(com.google.gerrit.server.CommentsUtil) Function(java.util.function.Function) Enums(com.google.common.base.Enums) GroupMembers(com.google.gerrit.server.account.GroupMembers) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) AccountResolver.isSelf(com.google.gerrit.server.account.AccountResolver.isSelf) GroupDescription(com.google.gerrit.entities.GroupDescription) QueryParseException(com.google.gerrit.index.query.QueryParseException) UnresolvableAccountException(com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) Address(com.google.gerrit.entities.Address) Predicate(com.google.gerrit.index.query.Predicate) QueryBuilder(com.google.gerrit.index.query.QueryBuilder) AccountGroup(com.google.gerrit.entities.AccountGroup) CurrentUser(com.google.gerrit.server.CurrentUser) AccountResolver(com.google.gerrit.server.account.AccountResolver) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) SubmitRule(com.google.gerrit.server.rules.SubmitRule) NotSignedInException(com.google.gerrit.exceptions.NotSignedInException) ExperimentFeatures(com.google.gerrit.server.experiments.ExperimentFeatures) PatchListCache(com.google.gerrit.server.patch.PatchListCache) StorageException(com.google.gerrit.exceptions.StorageException) IOException(java.io.IOException) VersionedAccountDestinations(com.google.gerrit.server.account.VersionedAccountDestinations) Ints(com.google.common.primitives.Ints) ChildProjects(com.google.gerrit.server.project.ChildProjects) ChangeField(com.google.gerrit.server.index.change.ChangeField) Collectors.toList(java.util.stream.Collectors.toList) Provider(com.google.inject.Provider) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) Project(com.google.gerrit.entities.Project) ChangeIndexCollection(com.google.gerrit.server.index.change.ChangeIndexCollection) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AccountState(com.google.gerrit.server.account.AccountState) ChangeIndex(com.google.gerrit.server.index.change.ChangeIndex) Collections(java.util.Collections) GERRIT_BACKEND_REQUEST_FEATURE_COMPUTE_FROM_ALL_USERS_REPOSITORY(com.google.gerrit.server.experiments.ExperimentFeaturesConstants.GERRIT_BACKEND_REQUEST_FEATURE_COMPUTE_FROM_ALL_USERS_REPOSITORY) Repository(org.eclipse.jgit.lib.Repository) StarredChangesUtil(com.google.gerrit.server.StarredChangesUtil) Address(com.google.gerrit.entities.Address) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Example 12 with Predicate

use of com.google.gerrit.index.query.Predicate in project gerrit by GerritCodeReview.

the class ChangeQueryBuilder method conflicts.

@Operator
public Predicate<ChangeData> conflicts(String value) throws QueryParseException {
    if (!args.conflictsPredicateEnabled) {
        throw new QueryParseException("'conflicts:' operator is not supported by server");
    }
    List<Change> changes = parseChange(value);
    List<Predicate<ChangeData>> or = new ArrayList<>(changes.size());
    for (Change c : changes) {
        or.add(ConflictsPredicate.create(args, value, c));
    }
    return Predicate.or(or);
}
Also used : ArrayList(java.util.ArrayList) Change(com.google.gerrit.entities.Change) QueryParseException(com.google.gerrit.index.query.QueryParseException) LimitPredicate(com.google.gerrit.index.query.LimitPredicate) Predicate(com.google.gerrit.index.query.Predicate)

Example 13 with Predicate

use of com.google.gerrit.index.query.Predicate in project gerrit by GerritCodeReview.

the class ChangeQueryBuilder method uploaderin.

@Operator
public Predicate<ChangeData> uploaderin(String group) throws QueryParseException, IOException {
    checkFieldAvailable(ChangeField.UPLOADER, "uploaderin");
    GroupReference g = GroupBackends.findBestSuggestion(args.groupBackend, group);
    if (g == null) {
        throw error("Group " + group + " not found");
    }
    AccountGroup.UUID groupId = g.getUUID();
    GroupDescription.Basic groupDescription = args.groupBackend.get(groupId);
    if (!(groupDescription instanceof GroupDescription.Internal)) {
        return new UploaderinPredicate(args.userFactory, groupId);
    }
    Set<Account.Id> accounts = getMembers(groupId);
    List<Predicate<ChangeData>> p = Lists.newArrayListWithCapacity(accounts.size());
    for (Account.Id id : accounts) {
        p.add(ChangePredicates.uploader(id));
    }
    return Predicate.or(p);
}
Also used : Account(com.google.gerrit.entities.Account) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) LimitPredicate(com.google.gerrit.index.query.LimitPredicate) Predicate(com.google.gerrit.index.query.Predicate) GroupDescription(com.google.gerrit.entities.GroupDescription) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupReference(com.google.gerrit.entities.GroupReference)

Example 14 with Predicate

use of com.google.gerrit.index.query.Predicate in project gerrit by GerritCodeReview.

the class ParentProjectPredicate method predicates.

protected static ImmutableList<Predicate<ChangeData>> predicates(ProjectCache projectCache, ChildProjects childProjects, String value) {
    Optional<ProjectState> projectState = projectCache.get(Project.nameKey(value));
    if (!projectState.isPresent()) {
        return ImmutableList.of();
    }
    ImmutableList.Builder<Predicate<ChangeData>> r = ImmutableList.builder();
    r.add(ChangePredicates.project(projectState.get().getNameKey()));
    try {
        for (ProjectInfo p : childProjects.list(projectState.get().getNameKey())) {
            r.add(ChangePredicates.project(Project.nameKey(p.name)));
        }
    } catch (PermissionBackendException e) {
        logger.atWarning().withCause(e).log("cannot check permissions to expand child projects");
    }
    return r.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) ProjectState(com.google.gerrit.server.project.ProjectState) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) Predicate(com.google.gerrit.index.query.Predicate) OrPredicate(com.google.gerrit.index.query.OrPredicate)

Aggregations

Predicate (com.google.gerrit.index.query.Predicate)14 LimitPredicate (com.google.gerrit.index.query.LimitPredicate)6 ImmutableList (com.google.common.collect.ImmutableList)5 Account (com.google.gerrit.entities.Account)5 Change (com.google.gerrit.entities.Change)5 Project (com.google.gerrit.entities.Project)5 QueryParseException (com.google.gerrit.index.query.QueryParseException)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 ArrayList (java.util.ArrayList)5 AccountGroup (com.google.gerrit.entities.AccountGroup)4 GroupReference (com.google.gerrit.entities.GroupReference)4 Inject (com.google.inject.Inject)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 Repository (org.eclipse.jgit.lib.Repository)4 GroupDescription (com.google.gerrit.entities.GroupDescription)3 RefNames (com.google.gerrit.entities.RefNames)3 StorageException (com.google.gerrit.exceptions.StorageException)3