use of com.google.gerrit.server.query.QueryParseException in project gerrit by GerritCodeReview.
the class ChangeQueryBuilder method query.
@Operator
public Predicate<ChangeData> query(String name) throws QueryParseException {
try (Repository git = args.repoManager.openRepository(args.allUsersName)) {
VersionedAccountQueries q = VersionedAccountQueries.forUser(self());
q.load(git);
String query = q.getQueryList().getQuery(name);
if (query != null) {
return parse(query);
}
} catch (RepositoryNotFoundException e) {
throw new QueryParseException("Unknown named query (no " + args.allUsersName + " repo): " + name, e);
} catch (IOException | ConfigInvalidException e) {
throw new QueryParseException("Error parsing named query: " + name, e);
}
throw new QueryParseException("Unknown named query: " + name);
}
use of com.google.gerrit.server.query.QueryParseException in project gerrit by GerritCodeReview.
the class ChangeQueryBuilder method destination.
@Operator
public Predicate<ChangeData> destination(String name) throws QueryParseException {
try (Repository git = args.repoManager.openRepository(args.allUsersName)) {
VersionedAccountDestinations d = VersionedAccountDestinations.forUser(self());
d.load(git);
Set<Branch.NameKey> destinations = d.getDestinationList().getDestinations(name);
if (destinations != null) {
return new DestinationPredicate(destinations, name);
}
} catch (RepositoryNotFoundException e) {
throw new QueryParseException("Unknown named destination (no " + args.allUsersName + " repo): " + name, e);
} catch (IOException | ConfigInvalidException e) {
throw new QueryParseException("Error parsing named destination: " + name, e);
}
throw new QueryParseException("Unknown named destination: " + name);
}
use of com.google.gerrit.server.query.QueryParseException in project gerrit by GerritCodeReview.
the class ChangeQueryBuilder method reviewerByState.
public Predicate<ChangeData> reviewerByState(String who, ReviewerStateInternal state, boolean forDefaultField) throws QueryParseException, OrmException {
Predicate<ChangeData> reviewerByEmailPredicate = null;
if (args.index.getSchema().hasField(ChangeField.REVIEWER_BY_EMAIL)) {
Address address = Address.tryParse(who);
if (address != null) {
reviewerByEmailPredicate = ReviewerByEmailPredicate.forState(args, 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(args, id, state)).collect(toList()));
}
} catch (QueryParseException e) {
// 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.server.query.QueryParseException in project gerrit by GerritCodeReview.
the class ChangeQueryBuilder method label.
@Operator
public Predicate<ChangeData> label(String name) throws QueryParseException, OrmException {
Set<Account.Id> accounts = null;
AccountGroup.UUID group = null;
// Parse for:
// label:CodeReview=1,user=jsmith or
// label:CodeReview=1,jsmith or
// label:CodeReview=1,group=android_approvers or
// label:CodeReview=1,android_approvers
// user/groups without a label will first attempt to match user
// Special case: votes by owners can be tracked with ",owner":
// label:Code-Review+2,owner
// label:Code-Review+2,user=owner
String[] splitReviewer = name.split(",", 2);
// remove all but the vote piece, e.g.'CodeReview=1'
name = splitReviewer[0];
if (splitReviewer.length == 2) {
// process the user/group piece
PredicateArgs lblArgs = new PredicateArgs(splitReviewer[1]);
for (Map.Entry<String, String> pair : lblArgs.keyValue.entrySet()) {
if (pair.getKey().equalsIgnoreCase(ARG_ID_USER)) {
if (pair.getValue().equals(ARG_ID_OWNER)) {
accounts = Collections.singleton(OWNER_ACCOUNT_ID);
} else {
accounts = parseAccount(pair.getValue());
}
} else if (pair.getKey().equalsIgnoreCase(ARG_ID_GROUP)) {
group = parseGroup(pair.getValue()).getUUID();
} else {
throw new QueryParseException("Invalid argument identifier '" + pair.getKey() + "'");
}
}
for (String value : lblArgs.positional) {
if (accounts != null || group != null) {
throw new QueryParseException("more than one user/group specified (" + value + ")");
}
try {
if (value.equals(ARG_ID_OWNER)) {
accounts = Collections.singleton(OWNER_ACCOUNT_ID);
} else {
accounts = parseAccount(value);
}
} catch (QueryParseException qpex) {
// (accounts get precedence)
try {
group = parseGroup(value).getUUID();
} catch (QueryParseException e) {
throw error("Neither user nor group " + value + " found", e);
}
}
}
}
// expand a group predicate into multiple user predicates
if (group != null) {
Set<Account.Id> allMembers = args.listMembers.get().setRecursive(true).apply(group).stream().map(a -> new Account.Id(a._accountId)).collect(toSet());
int maxLimit = args.indexConfig.maxLimit();
if (allMembers.size() > maxLimit) {
// limit the number of query terms otherwise Gerrit will barf
accounts = ImmutableSet.copyOf(Iterables.limit(allMembers, maxLimit));
} else {
accounts = allMembers;
}
}
// If the vote piece looks like Code-Review=NEED with a valid non-numeric
// submit record status, interpret as a submit record query.
int eq = name.indexOf('=');
if (args.getSchema().hasField(ChangeField.SUBMIT_RECORD) && eq > 0) {
String statusName = name.substring(eq + 1).toUpperCase();
if (!isInt(statusName)) {
SubmitRecord.Label.Status status = Enums.getIfPresent(SubmitRecord.Label.Status.class, statusName).orNull();
if (status == null) {
throw error("Invalid label status " + statusName + " in " + name);
}
return SubmitRecordPredicate.create(name.substring(0, eq), status, accounts);
}
}
return new LabelPredicate(args, name, accounts, group);
}
Aggregations