use of com.google.gerrit.index.query.Predicate in project gerrit by GerritCodeReview.
the class AbstractFakeIndex method getSource.
@Override
public DataSource<V> getSource(Predicate<V> p, QueryOptions opts) {
List<V> results;
synchronized (indexedDocuments) {
results = indexedDocuments.values().stream().map(doc -> valueFor(doc)).filter(doc -> p.asMatchable().match(doc)).sorted(sortingComparator()).skip(opts.start()).limit(opts.limit()).collect(toImmutableList());
}
return new DataSource<>() {
@Override
public int getCardinality() {
return results.size();
}
@Override
public ResultSet<V> read() {
return new ListResultSet<>(results);
}
@Override
public ResultSet<FieldBundle> readRaw() {
ImmutableList.Builder<FieldBundle> fieldBundles = ImmutableList.builder();
for (V result : results) {
ImmutableListMultimap.Builder<String, Object> fields = ImmutableListMultimap.builder();
for (FieldDef<V, ?> field : getSchema().getFields().values()) {
if (field.get(result) == null) {
continue;
}
if (field.isRepeatable()) {
fields.putAll(field.getName(), (Iterable<?>) field.get(result));
} else {
fields.put(field.getName(), field.get(result));
}
}
fieldBundles.add(new FieldBundle(fields.build()));
}
return new ListResultSet<>(fieldBundles.build());
}
};
}
use of com.google.gerrit.index.query.Predicate 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));
}
use of com.google.gerrit.index.query.Predicate in project gerrit by GerritCodeReview.
the class ChangeQueryBuilder method getAuthorOrCommitterFullTextPredicate.
private Predicate<ChangeData> getAuthorOrCommitterFullTextPredicate(String who, Function<String, Predicate<ChangeData>> fullPredicateFunc) throws QueryParseException {
if (isSelf(who)) {
IdentifiedUser me = args.getIdentifiedUser();
List<Predicate<ChangeData>> predicates = me.getEmailAddresses().stream().map(fullPredicateFunc).collect(toList());
return Predicate.or(predicates);
}
Set<String> parts = SchemaUtil.getNameParts(who);
if (parts.isEmpty()) {
throw error("invalid value");
}
List<Predicate<ChangeData>> predicates = parts.stream().map(fullPredicateFunc).collect(toList());
return Predicate.and(predicates);
}
use of com.google.gerrit.index.query.Predicate in project gerrit by GerritCodeReview.
the class LabelPredicate method predicates.
protected static List<Predicate<ChangeData>> predicates(Args args) {
String v = args.value;
List<Integer> counts = getCounts(args.count, args.countOp);
try {
MagicLabelVote mlv = MagicLabelVote.parseWithEquals(v);
List<Predicate<ChangeData>> result = Lists.newArrayListWithCapacity(counts.size());
if (counts.isEmpty()) {
result.add(magicLabelPredicate(args, mlv, /* count= */
null));
} else {
counts.forEach(count -> result.add(magicLabelPredicate(args, mlv, count)));
}
return result;
} catch (IllegalArgumentException e) {
// Try next format.
}
Parsed parsed = null;
try {
LabelVote lv = LabelVote.parse(v);
parsed = new Parsed(lv.label(), "=", lv.value());
} catch (IllegalArgumentException e) {
// Try next format.
}
try {
LabelVote lv = LabelVote.parseWithEquals(v);
parsed = new Parsed(lv.label(), "=", lv.value());
} catch (IllegalArgumentException e) {
// Try next format.
}
Range range;
if (parsed == null) {
range = RangeUtil.getRange(v, -MAX_LABEL_VALUE, MAX_LABEL_VALUE);
if (range == null) {
range = new Range(v, 1, 1);
}
} else {
range = RangeUtil.getRange(parsed.label, parsed.test, parsed.numericValue, -MAX_LABEL_VALUE, MAX_LABEL_VALUE);
}
String prefix = range.prefix;
int min = range.min;
int max = range.max;
List<Predicate<ChangeData>> r = Lists.newArrayListWithCapacity((counts.isEmpty() ? 1 : counts.size()) * (max - min + 1));
for (int i = min; i <= max; i++) {
if (counts.isEmpty()) {
r.add(onePredicate(args, prefix, i, /* count= */
null));
} else {
for (int count : counts) {
r.add(onePredicate(args, prefix, i, count));
}
}
}
return r;
}
use of com.google.gerrit.index.query.Predicate in project gerrit by GerritCodeReview.
the class ChangeQueryBuilder method ownerin.
@Operator
public Predicate<ChangeData> ownerin(String group) throws QueryParseException, IOException {
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 OwnerinPredicate(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.owner(id));
}
return Predicate.or(p);
}
Aggregations