use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class GetPostActionHandler method handle.
/* (non-Javadoc)
*
* @see
* com.willshex.gson.web.service.server.ActionHandler#handle(com.willshex.
* gson.web.service.shared.Request,
* com.willshex.gson.web.service.shared.Response) */
@Override
protected void handle(GetPostRequest input, GetPostResponse output) throws Exception {
ApiValidator.request(input, GetPostRequest.class);
ApiValidator.accessCode(input.accessCode, "input.accessCode");
if (input.session != null) {
try {
output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
} catch (InputValidationException ex) {
output.session = input.session = null;
}
}
Post post = PostValidator.lookup(input.post, "input.post");
if (post != null) {
output.post = PostValidator.viewable(post, output.session, "input.post");
output.post.author = UserServiceProvider.provide().getUser(keyToId(output.post.authorKey));
UserHelper.stripSensitive(output.post.author);
output.post.content = PostServiceProvider.provide().getPostContent(output.post);
}
}
use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class GetPostsActionHandler method handle.
/* (non-Javadoc)
*
* @see
* com.willshex.gson.web.service.server.ActionHandler#handle(com.willshex.
* gson.web.service.shared.Request,
* com.willshex.gson.web.service.shared.Response) */
@Override
protected void handle(GetPostsRequest input, GetPostsResponse output) throws Exception {
ApiValidator.request(input, GetPostsRequest.class);
ApiValidator.accessCode(input.accessCode, "input.accessCode");
Boolean showAll = Boolean.TRUE.equals(input.showAll) ? Boolean.TRUE : Boolean.FALSE;
if (input.session != null) {
try {
output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
List<Permission> permissions = new ArrayList<Permission>();
Permission postPermission = PermissionServiceProvider.provide().getCodePermission(PermissionHelper.MANAGE_POSTS);
permissions.add(postPermission);
try {
UserValidator.authorisation(input.session.user, permissions, "input.session.user");
} catch (AuthorisationException aEx) {
showAll = Boolean.FALSE;
}
} catch (InputValidationException ex) {
output.session = input.session = null;
showAll = Boolean.FALSE;
}
} else {
showAll = Boolean.FALSE;
}
if (!showAll) {
input.pager.sortBy = PostSortType.PostSortTypePublished.toString();
}
if (input.includePostContents == null) {
input.includePostContents = Boolean.FALSE;
}
boolean postsForTag = false, postsForArchiveEntry = false, postsForQuery = false;
if (input.tag != null && input.tag.length() > 0) {
postsForTag = true;
Tag tag = TagServiceProvider.provide().getSlugTag(input.tag);
if (tag != null) {
output.posts = PersistenceHelper.batchLookup(PostServiceProvider.provide(), tag.postKeys);
}
}
if (!postsForTag && input.archiveEntry != null) {
postsForTag = true;
if (input.archiveEntry.posts != null) {
output.posts = input.archiveEntry.posts = PostValidator.lookupAll(input.archiveEntry.posts, "input.archiveEntry.posts");
} else {
input.archiveEntry = ArchiveEntryValidator.lookup(input.archiveEntry, "input.archiveEntry");
output.posts = PersistenceHelper.batchLookup(PostServiceProvider.provide(), input.archiveEntry.postKeys);
}
}
if (!postsForTag && !postsForArchiveEntry && input.query != null) {
postsForQuery = true;
if (input.session != null && input.session.user != null) {
output.posts = PostServiceProvider.provide().getUserViewablePartialSlugPosts(input.query, input.session.user, showAll, input.includePostContents, input.pager.start, input.pager.count, PostSortType.fromString(input.pager.sortBy), input.pager.sortDirection);
} else {
output.posts = PostServiceProvider.provide().getPartialSlugPosts(input.query, showAll, input.includePostContents, input.pager.start, input.pager.count, PostSortType.PostSortTypePublished, SortDirectionType.SortDirectionTypeDescending);
}
}
if (!postsForTag && !postsForArchiveEntry && !postsForQuery) {
output.posts = PostServiceProvider.provide().getPosts(showAll, input.includePostContents, input.pager.start, input.pager.count, PostSortType.fromString(input.pager.sortBy), input.pager.sortDirection);
}
if (output.posts != null) {
Map<Key<User>, User> users = new HashMap<Key<User>, User>();
for (Post post : output.posts) {
if (users.get(post.authorKey) == null) {
users.put(post.authorKey, UserHelper.stripSensitive(UserServiceProvider.provide().getUser(keyToId(post.authorKey))));
}
post.author = users.get(post.authorKey);
}
}
output.pager = PagerHelper.moveForward(input.pager);
}
use of com.willshex.blogwt.shared.api.datatype.Post 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);
}
});
}
use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class PageValidator method validate.
public static Page validate(Page page, String name) throws InputValidationException {
if (page == null)
throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
List<Post> posts = new ArrayList<Post>();
for (Post post : page.posts) {
posts.add(PostValidator.lookup(post, name + ".posts[n]"));
}
page.posts = posts;
if (page.parent != null) {
page.parent = lookup(page.parent, name + ".parent");
}
page.owner = UserValidator.lookup(page.owner, name + ".owner");
return page;
}
use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class PostValidator method lookup.
public static Post lookup(Post post, String name) throws InputValidationException {
if (post == null)
throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
boolean isIdLookup = false, isSlugLookup = false;
if (post.id != null) {
isIdLookup = true;
} else if (post.slug != null) {
isSlugLookup = true;
}
if (!(isIdLookup || isSlugLookup))
throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
Post lookupPost;
if (isIdLookup) {
lookupPost = PostServiceProvider.provide().getPost(post.id);
} else {
lookupPost = PostServiceProvider.provide().getSlugPost(post.slug);
}
if (lookupPost == null)
throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
return lookupPost;
}
Aggregations