Search in sources :

Example 1 with QueryChanges

use of com.google.gerrit.server.query.change.QueryChanges in project gerrit by GerritCodeReview.

the class ChangesImpl method get.

private List<ChangeInfo> get(final QueryRequest q) throws RestApiException {
    QueryChanges qc = queryProvider.get();
    if (q.getQuery() != null) {
        qc.addQuery(q.getQuery());
    }
    qc.setLimit(q.getLimit());
    qc.setStart(q.getStart());
    for (ListChangesOption option : q.getOptions()) {
        qc.addOption(option);
    }
    try {
        List<?> result = qc.apply(TopLevelResource.INSTANCE);
        if (result.isEmpty()) {
            return ImmutableList.of();
        }
        // Check type safety of result; the extension API should be safer than the
        // REST API in this case, since it's intended to be used in Java.
        Object first = checkNotNull(result.iterator().next());
        checkState(first instanceof ChangeInfo);
        @SuppressWarnings("unchecked") List<ChangeInfo> infos = (List<ChangeInfo>) result;
        return ImmutableList.copyOf(infos);
    } catch (Exception e) {
        throw asRestApiException("Cannot query changes", e);
    }
}
Also used : ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) QueryChanges(com.google.gerrit.server.query.change.QueryChanges) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 2 with QueryChanges

use of com.google.gerrit.server.query.change.QueryChanges in project gerrit by GerritCodeReview.

the class StarredChanges method list.

@Override
public RestView<AccountResource> list() throws ResourceNotFoundException {
    return new RestReadView<AccountResource>() {

        @Override
        public Object apply(AccountResource self) throws BadRequestException, AuthException, OrmException {
            QueryChanges query = changes.list();
            query.addQuery("starredby:" + self.getUser().getAccountId().get());
            return query.apply(TopLevelResource.INSTANCE);
        }
    };
}
Also used : RestReadView(com.google.gerrit.extensions.restapi.RestReadView) QueryChanges(com.google.gerrit.server.query.change.QueryChanges)

Aggregations

QueryChanges (com.google.gerrit.server.query.change.QueryChanges)2 ImmutableList (com.google.common.collect.ImmutableList)1 ListChangesOption (com.google.gerrit.extensions.client.ListChangesOption)1 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 RestReadView (com.google.gerrit.extensions.restapi.RestReadView)1 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)1 List (java.util.List)1