Search in sources :

Example 1 with VersionedAccountDestinations

use of com.google.gerrit.server.account.VersionedAccountDestinations in project gerrit by GerritCodeReview.

the class ChangeQueryBuilder method destination.

@Operator
public Predicate<ChangeData> destination(String value) throws QueryParseException {
    // [name=]<name>[,user=<user>] || [user=<user>,][name=]<name>
    PredicateArgs inputArgs = new PredicateArgs(value);
    String name = null;
    Account.Id account = null;
    try (Repository git = args.repoManager.openRepository(args.allUsersName)) {
        // [name=]<name>
        if (inputArgs.keyValue.containsKey(ARG_ID_NAME)) {
            name = inputArgs.keyValue.get(ARG_ID_NAME).value();
        } else if (inputArgs.positional.size() == 1) {
            name = Iterables.getOnlyElement(inputArgs.positional);
        } else if (inputArgs.positional.size() > 1) {
            throw new QueryParseException("Error parsing named destination: " + value);
        }
        // [,user=<user>]
        if (inputArgs.keyValue.containsKey(ARG_ID_USER)) {
            Set<Account.Id> accounts = parseAccount(inputArgs.keyValue.get(ARG_ID_USER).value());
            if (accounts != null && accounts.size() > 1) {
                throw error(String.format("\"%s\" resolves to multiple accounts", inputArgs.keyValue.get(ARG_ID_USER)));
            }
            account = (accounts == null ? self() : Iterables.getOnlyElement(accounts));
        } else {
            account = self();
        }
        VersionedAccountDestinations d = VersionedAccountDestinations.forUser(account);
        d.load(args.allUsersName, git);
        Set<BranchNameKey> destinations = d.getDestinationList().getDestinations(name);
        if (destinations != null && !destinations.isEmpty()) {
            return new DestinationPredicate(destinations, value);
        }
    } 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: " + value, e);
    }
    throw new QueryParseException("Unknown named destination: " + name);
}
Also used : Account(com.google.gerrit.entities.Account) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException) VersionedAccountDestinations(com.google.gerrit.server.account.VersionedAccountDestinations) QueryParseException(com.google.gerrit.index.query.QueryParseException) Repository(org.eclipse.jgit.lib.Repository) BranchNameKey(com.google.gerrit.entities.BranchNameKey)

Aggregations

Account (com.google.gerrit.entities.Account)1 BranchNameKey (com.google.gerrit.entities.BranchNameKey)1 QueryParseException (com.google.gerrit.index.query.QueryParseException)1 VersionedAccountDestinations (com.google.gerrit.server.account.VersionedAccountDestinations)1 IOException (java.io.IOException)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)1 Repository (org.eclipse.jgit.lib.Repository)1