Search in sources :

Example 26 with Post

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);
    }
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 27 with 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);
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) HashMap(java.util.HashMap) Post(com.willshex.blogwt.shared.api.datatype.Post) ArrayList(java.util.ArrayList) Permission(com.willshex.blogwt.shared.api.datatype.Permission) InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Tag(com.willshex.blogwt.shared.api.datatype.Tag) AuthorisationException(com.willshex.blogwt.server.api.exception.AuthorisationException) Key(com.googlecode.objectify.Key)

Example 28 with Post

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);
        }
    });
}
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)

Example 29 with Post

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;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) ArrayList(java.util.ArrayList) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 30 with Post

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;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Aggregations

Post (com.willshex.blogwt.shared.api.datatype.Post)52 JsonElement (com.google.gson.JsonElement)11 ArrayList (java.util.ArrayList)11 Pager (com.willshex.blogwt.shared.api.Pager)10 Key (com.googlecode.objectify.Key)8 Page (com.willshex.blogwt.shared.api.datatype.Page)7 Date (java.util.Date)6 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)5 HashMap (java.util.HashMap)5 Tag (com.willshex.blogwt.shared.api.datatype.Tag)4 User (com.willshex.blogwt.shared.api.datatype.User)4 ArchiveEntry (com.willshex.blogwt.shared.api.datatype.ArchiveEntry)3 PostContent (com.willshex.blogwt.shared.api.datatype.PostContent)3 ScoredDocument (com.google.appengine.api.search.ScoredDocument)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 EditPageWizardPage (com.willshex.blogwt.client.wizard.page.EditPageWizardPage)2 SelectPostWizardPage (com.willshex.blogwt.client.wizard.page.SelectPostWizardPage)2 GetPostRequest (com.willshex.blogwt.shared.api.blog.call.GetPostRequest)2 MarkdownProcessor (org.markdown4j.server.MarkdownProcessor)2 Document (com.google.appengine.api.search.Document)1