Search in sources :

Example 1 with RestApi

use of com.google.gerrit.plugin.client.rpc.RestApi in project gerrit by GerritCodeReview.

the class GroupSuggestOracle method requestSuggestions.

@Override
public void requestSuggestions(final Request req, final Callback done) {
    if (req.getQuery().length() < chars) {
        responseEmptySuggestion(req, done);
        return;
    }
    RestApi rest = new RestApi("/groups/").addParameter("suggest", req.getQuery());
    if (req.getLimit() > 0) {
        rest.addParameter("n", req.getLimit());
    }
    rest.get(new AsyncCallback<NativeMap<JavaScriptObject>>() {

        @Override
        public void onSuccess(NativeMap<JavaScriptObject> result) {
            List<String> keys = result.sortedKeys();
            List<Suggestion> suggestions = new ArrayList<>(keys.size());
            for (String g : keys) {
                suggestions.add(new HighlightSuggestion(req.getQuery(), g));
            }
            done.onSuggestionsReady(req, new Response(suggestions));
        }

        @Override
        public void onFailure(Throwable caught) {
            responseEmptySuggestion(req, done);
        }
    });
}
Also used : RestApi(com.google.gerrit.plugin.client.rpc.RestApi) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) HighlightSuggestion(com.google.gerrit.client.ui.HighlightSuggestion) List(java.util.List) ArrayList(java.util.ArrayList) NativeMap(com.google.gerrit.client.rpc.NativeMap)

Aggregations

NativeMap (com.google.gerrit.client.rpc.NativeMap)1 HighlightSuggestion (com.google.gerrit.client.ui.HighlightSuggestion)1 RestApi (com.google.gerrit.plugin.client.rpc.RestApi)1 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1