Search in sources :

Example 1 with QueryParseException

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

the class QueryBuilder method intRangeQuery.

private Query intRangeQuery(IndexPredicate<V> p) throws QueryParseException {
    if (p instanceof IntegerRangePredicate) {
        IntegerRangePredicate<V> r = (IntegerRangePredicate<V>) p;
        String name = r.getField().getName();
        int minimum = r.getMinimumValue();
        int maximum = r.getMaximumValue();
        if (minimum == maximum) {
            // Just fall back to a standard integer query.
            return intTermQuery.get(name, minimum);
        }
        return intRangeTermQuery.get(name, minimum, maximum);
    }
    throw new QueryParseException("not an integer range: " + p);
}
Also used : IntegerRangePredicate(com.google.gerrit.index.query.IntegerRangePredicate) LongPoint(org.apache.lucene.document.LongPoint) IntPoint(org.apache.lucene.document.IntPoint) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Example 2 with QueryParseException

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

the class QueryBuilder method and.

private Query and(Predicate<V> p) throws QueryParseException {
    try {
        BooleanQuery.Builder b = new BooleanQuery.Builder();
        List<Query> not = Lists.newArrayListWithCapacity(p.getChildCount());
        for (int i = 0; i < p.getChildCount(); i++) {
            Predicate<V> c = p.getChild(i);
            if (c instanceof NotPredicate) {
                Predicate<V> n = c.getChild(0);
                if (n instanceof TimestampRangePredicate) {
                    b.add(notTimestamp((TimestampRangePredicate<V>) n), MUST);
                } else {
                    not.add(toQuery(n));
                }
            } else {
                b.add(toQuery(c), MUST);
            }
        }
        for (Query q : not) {
            b.add(q, MUST_NOT);
        }
        return b.build();
    } catch (BooleanQuery.TooManyClauses e) {
        throw new QueryParseException("cannot create query for index: " + p, e);
    }
}
Also used : TimestampRangePredicate(com.google.gerrit.index.query.TimestampRangePredicate) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) RegexpQuery(org.apache.lucene.search.RegexpQuery) LegacyNumericRangeQuery(org.apache.lucene.search.LegacyNumericRangeQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) NotPredicate(com.google.gerrit.index.query.NotPredicate) LongPoint(org.apache.lucene.document.LongPoint) IntPoint(org.apache.lucene.document.IntPoint) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Example 3 with QueryParseException

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

the class AbandonUtil method abandonInactiveOpenChanges.

public void abandonInactiveOpenChanges(BatchUpdate.Factory updateFactory) {
    if (cfg.getAbandonAfter() <= 0) {
        return;
    }
    try {
        String query = "status:new age:" + TimeUnit.MILLISECONDS.toMinutes(cfg.getAbandonAfter()) + "m";
        if (!cfg.getAbandonIfMergeable()) {
            query += " -is:mergeable";
        }
        List<ChangeData> changesToAbandon = queryProvider.get().enforceVisibility(false).query(queryBuilderProvider.get().parse(query)).entities();
        ImmutableListMultimap.Builder<Project.NameKey, ChangeData> builder = ImmutableListMultimap.builder();
        for (ChangeData cd : changesToAbandon) {
            builder.put(cd.project(), cd);
        }
        int count = 0;
        ListMultimap<Project.NameKey, ChangeData> abandons = builder.build();
        String message = cfg.getAbandonMessage();
        for (Project.NameKey project : abandons.keySet()) {
            Collection<ChangeData> changes = getValidChanges(abandons.get(project), query);
            try {
                batchAbandon.batchAbandon(updateFactory, project, internalUser, changes, message);
                count += changes.size();
            } catch (Exception e) {
                StringBuilder msg = new StringBuilder("Failed to auto-abandon inactive change(s):");
                for (ChangeData change : changes) {
                    msg.append(" ").append(change.getId().get());
                }
                msg.append(".");
                logger.atSevere().withCause(e).log("%s", msg);
            }
        }
        logger.atInfo().log("Auto-Abandoned %d of %d changes.", count, changesToAbandon.size());
    } catch (QueryParseException | StorageException e) {
        logger.atSevere().withCause(e).log("Failed to query inactive open changes for auto-abandoning.");
    }
}
Also used : ChangeData(com.google.gerrit.server.query.change.ChangeData) StorageException(com.google.gerrit.exceptions.StorageException) QueryParseException(com.google.gerrit.index.query.QueryParseException) QueryParseException(com.google.gerrit.index.query.QueryParseException) Project(com.google.gerrit.entities.Project) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) StorageException(com.google.gerrit.exceptions.StorageException)

Example 4 with QueryParseException

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

the class SubmitRequirementsEvaluatorImpl method evaluateExpression.

@Override
public SubmitRequirementExpressionResult evaluateExpression(SubmitRequirementExpression expression, ChangeData changeData) {
    try {
        Predicate<ChangeData> predicate = queryBuilder.get().parse(expression.expressionString());
        PredicateResult predicateResult = evaluatePredicateTree(predicate, changeData);
        return SubmitRequirementExpressionResult.create(expression, predicateResult);
    } catch (QueryParseException | SubmitRequirementEvaluationException e) {
        return SubmitRequirementExpressionResult.error(expression, e.getMessage());
    }
}
Also used : PredicateResult(com.google.gerrit.entities.SubmitRequirementExpressionResult.PredicateResult) ChangeData(com.google.gerrit.server.query.change.ChangeData) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Example 5 with QueryParseException

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

the class IsWatchedByPredicate method filters.

protected static List<Predicate<ChangeData>> filters(ChangeQueryBuilder.Arguments args) throws QueryParseException {
    List<Predicate<ChangeData>> r = new ArrayList<>();
    ChangeQueryBuilder builder = new ChangeQueryBuilder(args);
    for (ProjectWatchKey w : getWatches(args)) {
        Predicate<ChangeData> f = null;
        if (w.filter() != null) {
            try {
                f = builder.parse(w.filter());
                if (QueryBuilder.find(f, IsWatchedByPredicate.class) != null) {
                    // another user is filtering on. :-)
                    continue;
                }
            } catch (QueryParseException e) {
                continue;
            }
        }
        Predicate<ChangeData> p;
        if (w.project().equals(args.allProjectsName)) {
            p = null;
        } else {
            p = builder.project(w.project().get());
        }
        if (p != null && f != null) {
            r.add(and(p, f));
        } else if (p != null) {
            r.add(p);
        } else if (f != null) {
            r.add(f);
        } else {
            r.add(builder.statusOpen());
        }
    }
    if (r.isEmpty()) {
        return ImmutableList.of(ChangeIndexPredicate.none());
    }
    return ImmutableList.of(or(r));
}
Also used : ProjectWatchKey(com.google.gerrit.server.account.ProjectWatches.ProjectWatchKey) ArrayList(java.util.ArrayList) AndPredicate(com.google.gerrit.index.query.AndPredicate) Predicate(com.google.gerrit.index.query.Predicate) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Aggregations

QueryParseException (com.google.gerrit.index.query.QueryParseException)30 Account (com.google.gerrit.entities.Account)7 StorageException (com.google.gerrit.exceptions.StorageException)6 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)6 ArrayList (java.util.ArrayList)6 Predicate (com.google.gerrit.index.query.Predicate)5 AccountState (com.google.gerrit.server.account.AccountState)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 IOException (java.io.IOException)5 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)5 Repository (org.eclipse.jgit.lib.Repository)4 FluentLogger (com.google.common.flogger.FluentLogger)3 GroupReference (com.google.gerrit.entities.GroupReference)3 Project (com.google.gerrit.entities.Project)3 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)3 LimitPredicate (com.google.gerrit.index.query.LimitPredicate)3 Inject (com.google.inject.Inject)3 Provider (com.google.inject.Provider)3 Collections (java.util.Collections)3 List (java.util.List)3