Search in sources :

Example 1 with GetPostsResponse

use of com.willshex.blogwt.shared.api.blog.call.GetPostsResponse in project blogwt by billy1380.

the class BlogService method getPosts.

public Request getPosts(GetPostsRequest input, AsyncSuccess<GetPostsRequest, GetPostsResponse> onSuccess, AsyncFailure<GetPostsRequest> onFailure) {
    Request handle = null;
    try {
        handle = sendRequest(BlogMethodGetPosts, input, new RequestCallback() {

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

            @Override
            public void onError(Request request, Throwable exception) {
                if (onFailure != null) {
                    onFailure.call(input, exception);
                }
                onCallFailure(BlogService.this, BlogMethodGetPosts, input, exception);
            }
        });
        onCallStart(BlogService.this, BlogMethodGetPosts, input, handle);
    } catch (RequestException exception) {
        if (onFailure != null) {
            onFailure.call(input, exception);
        }
        onCallFailure(BlogService.this, BlogMethodGetPosts, input, exception);
    }
    return handle;
}
Also used : GetRatingsResponse(com.willshex.blogwt.shared.api.blog.call.GetRatingsResponse) UpdatePropertiesResponse(com.willshex.blogwt.shared.api.blog.call.UpdatePropertiesResponse) SubmitRatingResponse(com.willshex.blogwt.shared.api.blog.call.SubmitRatingResponse) UpdatePostResponse(com.willshex.blogwt.shared.api.blog.call.UpdatePostResponse) GetTagsResponse(com.willshex.blogwt.shared.api.blog.call.GetTagsResponse) DeleteResourceResponse(com.willshex.blogwt.shared.api.blog.call.DeleteResourceResponse) GetArchiveEntriesResponse(com.willshex.blogwt.shared.api.blog.call.GetArchiveEntriesResponse) Response(com.google.gwt.http.client.Response) GetPostResponse(com.willshex.blogwt.shared.api.blog.call.GetPostResponse) SetupBlogResponse(com.willshex.blogwt.shared.api.blog.call.SetupBlogResponse) GetResourcesResponse(com.willshex.blogwt.shared.api.blog.call.GetResourcesResponse) CreatePostResponse(com.willshex.blogwt.shared.api.blog.call.CreatePostResponse) GetRelatedPostsResponse(com.willshex.blogwt.shared.api.blog.call.GetRelatedPostsResponse) GetResourceResponse(com.willshex.blogwt.shared.api.blog.call.GetResourceResponse) GetPostsResponse(com.willshex.blogwt.shared.api.blog.call.GetPostsResponse) UpdateResourceResponse(com.willshex.blogwt.shared.api.blog.call.UpdateResourceResponse) DeletePostResponse(com.willshex.blogwt.shared.api.blog.call.DeletePostResponse) GetPropertiesResponse(com.willshex.blogwt.shared.api.blog.call.GetPropertiesResponse) RequestCallback(com.google.gwt.http.client.RequestCallback) UpdatePostRequest(com.willshex.blogwt.shared.api.blog.call.UpdatePostRequest) GetResourcesRequest(com.willshex.blogwt.shared.api.blog.call.GetResourcesRequest) GetResourceRequest(com.willshex.blogwt.shared.api.blog.call.GetResourceRequest) DeleteResourceRequest(com.willshex.blogwt.shared.api.blog.call.DeleteResourceRequest) GetRelatedPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetRelatedPostsRequest) GetTagsRequest(com.willshex.blogwt.shared.api.blog.call.GetTagsRequest) UpdatePropertiesRequest(com.willshex.blogwt.shared.api.blog.call.UpdatePropertiesRequest) GetRatingsRequest(com.willshex.blogwt.shared.api.blog.call.GetRatingsRequest) DeletePostRequest(com.willshex.blogwt.shared.api.blog.call.DeletePostRequest) SubmitRatingRequest(com.willshex.blogwt.shared.api.blog.call.SubmitRatingRequest) CreatePostRequest(com.willshex.blogwt.shared.api.blog.call.CreatePostRequest) GetArchiveEntriesRequest(com.willshex.blogwt.shared.api.blog.call.GetArchiveEntriesRequest) Request(com.google.gwt.http.client.Request) UpdateResourceRequest(com.willshex.blogwt.shared.api.blog.call.UpdateResourceRequest) GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) GetPropertiesRequest(com.willshex.blogwt.shared.api.blog.call.GetPropertiesRequest) GetPostRequest(com.willshex.blogwt.shared.api.blog.call.GetPostRequest) SetupBlogRequest(com.willshex.blogwt.shared.api.blog.call.SetupBlogRequest) JSONException(com.google.gwt.json.client.JSONException) HttpException(com.willshex.gson.web.service.client.HttpException) RequestException(com.google.gwt.http.client.RequestException) GetPostsResponse(com.willshex.blogwt.shared.api.blog.call.GetPostsResponse)

Example 2 with GetPostsResponse

use of com.willshex.blogwt.shared.api.blog.call.GetPostsResponse in project blogwt by billy1380.

the class PostController method fetchPosts.

private void fetchPosts() {
    final GetPostsRequest input = ApiHelper.setAccessCode(new GetPostsRequest());
    input.session = SessionController.get().sessionForApiCall();
    input.includePostContents = Boolean.FALSE;
    input.archiveEntry = archiveEntry;
    input.showAll = Boolean.valueOf(isAdminMode);
    if (SessionController.get().isValidSession()) {
        pager.sortBy = PostSortType.PostSortTypeCreated.toString();
    } else {
        pager.sortBy = PostSortType.PostSortTypePublished.toString();
    }
    input.pager = pager;
    input.tag = tag;
    if (getPostsRequest != null) {
        getPostsRequest.cancel();
    }
    getPostsRequest = ApiHelper.createBlogClient().getPosts(input, new AsyncCallback<GetPostsResponse>() {

        @Override
        public void onSuccess(GetPostsResponse output) {
            getPostsRequest = null;
            if (output.status == StatusType.StatusTypeSuccess) {
                if (output.posts != null && output.posts.size() > 0) {
                    pager = output.pager;
                    updateRowCount(input.pager.count == null ? 0 : input.pager.count.intValue(), input.pager.count == null || input.pager.count.intValue() == 0);
                    updateRowData(input.pager.start.intValue(), output.posts);
                } else {
                    updateRowCount(input.pager.start.intValue(), true);
                    updateRowData(input.pager.start.intValue(), Collections.<Post>emptyList());
                }
            }
            DefaultEventBus.get().fireEventFromSource(new GetPostsSuccess(input, output), PostController.this);
        }

        @Override
        public void onFailure(Throwable caught) {
            getPostsRequest = null;
            DefaultEventBus.get().fireEventFromSource(new GetPostsFailure(input, caught), PostController.this);
        }
    });
}
Also used : GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetPostsSuccess(com.willshex.blogwt.client.api.blog.event.GetPostsEventHandler.GetPostsSuccess) GetPostsResponse(com.willshex.blogwt.shared.api.blog.call.GetPostsResponse) GetPostsFailure(com.willshex.blogwt.client.api.blog.event.GetPostsEventHandler.GetPostsFailure)

Example 3 with GetPostsResponse

use of com.willshex.blogwt.shared.api.blog.call.GetPostsResponse in project blogwt by billy1380.

the class PostOracle method lookup.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.blogwt.client.oracle.SuggestOracle#lookup(com.google.gwt
	 * .user.client.ui.SuggestOracle.Request,
	 * com.google.gwt.user.client.ui.SuggestOracle.Callback) */
@Override
protected void lookup(final Request request, final Callback callback) {
    final GetPostsRequest input = ApiHelper.setAccessCode(new GetPostsRequest());
    input.session = SessionController.get().sessionForApiCall();
    input.includePostContents = Boolean.FALSE;
    input.query = request.getQuery();
    input.pager = PagerHelper.createDefaultPager();
    input.pager.count = Integer.valueOf(request.getLimit());
    input.showAll = Boolean.TRUE;
    if (getPostsRequest != null) {
        getPostsRequest.cancel();
    }
    getPostsRequest = ApiHelper.createBlogClient().getPosts(input, new AsyncCallback<GetPostsResponse>() {

        @Override
        public void onSuccess(GetPostsResponse output) {
            if (output.status == StatusType.StatusTypeSuccess && output.pager != null) {
                foundItems(request, callback, output.posts);
            } else {
                foundItems(request, callback, Collections.<Post>emptyList());
            }
        }

        @Override
        public void onFailure(Throwable caught) {
            GWT.log("Error getting posts with query " + input.query, caught);
            foundItems(request, callback, Collections.<Post>emptyList());
        }
    });
}
Also used : GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetPostsResponse(com.willshex.blogwt.shared.api.blog.call.GetPostsResponse)

Example 4 with GetPostsResponse

use of com.willshex.blogwt.shared.api.blog.call.GetPostsResponse in project blogwt by billy1380.

the class StaticPosts method appendPage.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.page.StaticTemplate#appendPage(java.lang.
	 * StringBuffer) */
@Override
protected void appendPage(StringBuffer markup) {
    markup.append("<h2>Blog</h2>");
    GetPostsRequest input = input(GetPostsRequest.class).pager(PagerHelper.createDefaultPager().sortBy(PostSortType.PostSortTypePublished.toString()));
    GetPostsResponse output = new GetPostsActionHandler().handle(input);
    if (output.status == StatusType.StatusTypeSuccess && output.posts != null) {
        showPosts(output.posts, markup);
    } else {
        markup.append(output.error.toString());
    }
}
Also used : GetPostsActionHandler(com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler) GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) GetPostsResponse(com.willshex.blogwt.shared.api.blog.call.GetPostsResponse)

Example 5 with GetPostsResponse

use of com.willshex.blogwt.shared.api.blog.call.GetPostsResponse in project blogwt by billy1380.

the class StaticTag method appendPage.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.page.StaticTemplate#appendPage(java.lang.
	 * StringBuffer) */
@Override
protected void appendPage(StringBuffer markup) {
    String tag;
    if ((tag = stack.getAction()) != null) {
        markup.append("<h2>Posts tagged with <strong>&apos;" + tag + "&apos;</strong></h2>");
        GetPostsRequest input = input(GetPostsRequest.class).pager(PagerHelper.createDefaultPager()).tag(tag);
        GetPostsResponse output = (new GetPostsActionHandler()).handle(input);
        if (output.status == StatusType.StatusTypeSuccess && output.posts != null) {
            showPosts(output.posts, markup);
        } else {
            markup.append(output.error.toString());
        }
    }
}
Also used : GetPostsActionHandler(com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler) GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) GetPostsResponse(com.willshex.blogwt.shared.api.blog.call.GetPostsResponse)

Aggregations

GetPostsRequest (com.willshex.blogwt.shared.api.blog.call.GetPostsRequest)5 GetPostsResponse (com.willshex.blogwt.shared.api.blog.call.GetPostsResponse)5 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 GetPostsActionHandler (com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler)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 GetPostsFailure (com.willshex.blogwt.client.api.blog.event.GetPostsEventHandler.GetPostsFailure)1 GetPostsSuccess (com.willshex.blogwt.client.api.blog.event.GetPostsEventHandler.GetPostsSuccess)1 CreatePostRequest (com.willshex.blogwt.shared.api.blog.call.CreatePostRequest)1 CreatePostResponse (com.willshex.blogwt.shared.api.blog.call.CreatePostResponse)1 DeletePostRequest (com.willshex.blogwt.shared.api.blog.call.DeletePostRequest)1 DeletePostResponse (com.willshex.blogwt.shared.api.blog.call.DeletePostResponse)1 DeleteResourceRequest (com.willshex.blogwt.shared.api.blog.call.DeleteResourceRequest)1 DeleteResourceResponse (com.willshex.blogwt.shared.api.blog.call.DeleteResourceResponse)1 GetArchiveEntriesRequest (com.willshex.blogwt.shared.api.blog.call.GetArchiveEntriesRequest)1 GetArchiveEntriesResponse (com.willshex.blogwt.shared.api.blog.call.GetArchiveEntriesResponse)1 GetPostRequest (com.willshex.blogwt.shared.api.blog.call.GetPostRequest)1