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