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);
}
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);
}
}
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.");
}
}
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());
}
}
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));
}
Aggregations