Search in sources :

Example 1 with SearchAllResponse

use of com.willshex.blogwt.shared.api.search.call.SearchAllResponse in project blogwt by billy1380.

the class SearchService method searchAll.

public Request searchAll(SearchAllRequest input, AsyncSuccess<SearchAllRequest, SearchAllResponse> onSuccess, AsyncFailure<SearchAllRequest> onFailure) {
    Request handle = null;
    try {
        handle = sendRequest(SearchMethodSearchAll, input, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                try {
                    SearchAllResponse outputParameter = new SearchAllResponse();
                    parseResponse(response, outputParameter);
                    if (onSuccess != null) {
                        onSuccess.call(input, outputParameter);
                    }
                    onCallSuccess(SearchService.this, SearchMethodSearchAll, input, outputParameter);
                } catch (JSONException | HttpException exception) {
                    if (onFailure != null) {
                        onFailure.call(input, exception);
                    }
                    onCallFailure(SearchService.this, SearchMethodSearchAll, input, exception);
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                if (onFailure != null) {
                    onFailure.call(input, exception);
                }
                onCallFailure(SearchService.this, SearchMethodSearchAll, input, exception);
            }
        });
        onCallStart(SearchService.this, SearchMethodSearchAll, input, handle);
    } catch (RequestException exception) {
        if (onFailure != null) {
            onFailure.call(input, exception);
        }
        onCallFailure(SearchService.this, SearchMethodSearchAll, input, exception);
    }
    return handle;
}
Also used : Response(com.google.gwt.http.client.Response) SearchAllResponse(com.willshex.blogwt.shared.api.search.call.SearchAllResponse) SearchAllResponse(com.willshex.blogwt.shared.api.search.call.SearchAllResponse) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) SearchAllRequest(com.willshex.blogwt.shared.api.search.call.SearchAllRequest) JSONException(com.google.gwt.json.client.JSONException) HttpException(com.willshex.gson.web.service.client.HttpException) RequestException(com.google.gwt.http.client.RequestException)

Example 2 with SearchAllResponse

use of com.willshex.blogwt.shared.api.search.call.SearchAllResponse in project blogwt by billy1380.

the class SearchController method fetchSearchResults.

private void fetchSearchResults(String query) {
    final SearchAllRequest input = ApiHelper.setAccessCode(new SearchAllRequest());
    input.session = SessionController.get().sessionForApiCall();
    input.query = query;
    if (searchAllRequest != null) {
        searchAllRequest.cancel();
    }
    searchAllRequest = ApiHelper.createSearchClient().searchAll(input, new AsyncCallback<SearchAllResponse>() {

        @Override
        public void onSuccess(SearchAllResponse output) {
            searchAllRequest = null;
            if (output.status == StatusType.StatusTypeSuccess) {
                List<SearchResult> results = new ArrayList<SearchController.SearchResult>();
                if (output.posts != null) {
                    for (Post post : output.posts) {
                        results.add(new SearchResult(post));
                    }
                }
                if (output.pages != null) {
                    for (Page page : output.pages) {
                        results.add(new SearchResult(page));
                    }
                }
                if (output.users != null) {
                    for (User user : output.users) {
                        results.add(new SearchResult(user));
                    }
                }
                updateRowCount(results.size(), true);
                updateRowData(0, results);
            }
            DefaultEventBus.get().fireEventFromSource(new SearchAllSuccess(input, output), SearchController.this);
        }

        @Override
        public void onFailure(Throwable caught) {
            searchAllRequest = null;
            DefaultEventBus.get().fireEventFromSource(new SearchAllFailure(input, caught), SearchController.this);
        }
    });
}
Also used : SearchAllResponse(com.willshex.blogwt.shared.api.search.call.SearchAllResponse) SearchAllFailure(com.willshex.blogwt.client.api.search.event.SearchAllEventHandler.SearchAllFailure) SearchAllSuccess(com.willshex.blogwt.client.api.search.event.SearchAllEventHandler.SearchAllSuccess) User(com.willshex.blogwt.shared.api.datatype.User) Post(com.willshex.blogwt.shared.api.datatype.Post) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) Page(com.willshex.blogwt.shared.api.datatype.Page) SearchAllRequest(com.willshex.blogwt.shared.api.search.call.SearchAllRequest)

Aggregations

SearchAllRequest (com.willshex.blogwt.shared.api.search.call.SearchAllRequest)2 SearchAllResponse (com.willshex.blogwt.shared.api.search.call.SearchAllResponse)2 Request (com.google.gwt.http.client.Request)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1 RequestException (com.google.gwt.http.client.RequestException)1 Response (com.google.gwt.http.client.Response)1 JSONException (com.google.gwt.json.client.JSONException)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 SearchAllFailure (com.willshex.blogwt.client.api.search.event.SearchAllEventHandler.SearchAllFailure)1 SearchAllSuccess (com.willshex.blogwt.client.api.search.event.SearchAllEventHandler.SearchAllSuccess)1 Page (com.willshex.blogwt.shared.api.datatype.Page)1 Post (com.willshex.blogwt.shared.api.datatype.Post)1 User (com.willshex.blogwt.shared.api.datatype.User)1 HttpException (com.willshex.gson.web.service.client.HttpException)1 ArrayList (java.util.ArrayList)1