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;
}
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);
}
});
}
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());
}
});
}
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());
}
}
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>'" + tag + "'</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());
}
}
}
Aggregations