Search in sources :

Example 36 with Post

use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.

the class PageService method addPage.

@Override
public Page addPage(Page page) {
    if (page.created == null) {
        page.created = new Date();
    }
    page.ownerKey = Key.create(page.owner);
    page.postKeys = new ArrayList<Key<Post>>();
    for (Post post : page.posts) {
        page.postKeys.add(Key.create(post));
    }
    if (page.parent != null) {
        page.parentKey = Key.create(page.parent);
    }
    Key<Page> key = provide().save().entity(page).now();
    page.id = keyToId(key);
    SearchHelper.queueToIndex(getName(), page.id);
    return page;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) Page(com.willshex.blogwt.shared.api.datatype.Page) Date(java.util.Date) Key(com.googlecode.objectify.Key)

Example 37 with Post

use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.

the class PageService method populatePostContents.

private void populatePostContents(List<Page> pages) {
    List<Post> posts = new ArrayList<Post>();
    for (Page page : pages) {
        posts.addAll(PersistenceHelper.batchLookup(PostServiceProvider.provide(), page.postKeys));
    }
    // FIXME: just load in one go (batcg)
    for (Post post : posts) {
        post.content = PostServiceProvider.provide().getPostContent(post);
    }
    Map<Long, Post> postLookup = new HashMap<Long, Post>();
    for (Post post : posts) {
        postLookup.put(post.id, post);
    }
    List<Post> pagePosts;
    for (Page page : pages) {
        pagePosts = new ArrayList<Post>();
        for (Key<Post> key : page.postKeys) {
            pagePosts.add(postLookup.get(keyToId(key)));
        }
        page.posts = pagePosts;
    }
}
Also used : HashMap(java.util.HashMap) Post(com.willshex.blogwt.shared.api.datatype.Post) ArrayList(java.util.ArrayList) Page(com.willshex.blogwt.shared.api.datatype.Page)

Example 38 with Post

use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.

the class PageService method toDocument.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.blogwt.server.service.search.IIndex#toDocument(java.lang.
	 * Object) */
@Override
public Document toDocument(Page page) {
    Document document = null;
    if (page != null) {
        Document.Builder documentBuilder = Document.newBuilder();
        documentBuilder.setId(getName() + page.id.toString()).addField(Field.newBuilder().setName("owner").setAtom(page.owner.username)).addField(Field.newBuilder().setName("owner").setText(UserHelper.name(page.owner))).addField(Field.newBuilder().setName("created").setDate(page.created)).addField(Field.newBuilder().setName("title").setText(page.title));
        if (page.posts != null) {
            StringBuilder body = new StringBuilder();
            for (Post post : page.posts) {
                body.append(post.content.body).append("\n\n");
            }
            documentBuilder.addField(Field.newBuilder().setName("body").setText(body.toString()));
        }
        document = documentBuilder.build();
    }
    return document;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) Document(com.google.appengine.api.search.Document) ScoredDocument(com.google.appengine.api.search.ScoredDocument)

Example 39 with Post

use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.

the class PostService method getUserViewablePosts.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.blogwt.server.service.post.IPostService#getUserViewablePosts
	 * (com.willshex.blogwt.shared.api.datatype.User, java.lang.Boolean,
	 * java.lang.Boolean, java.lang.Integer, java.lang.Integer,
	 * com.willshex.blogwt.shared.api.datatype.PostSortType,
	 * com.willshex.blogwt.shared.api.SortDirectionType) */
@Override
public List<Post> getUserViewablePosts(User user, Boolean showAll, Boolean includeContents, Integer start, Integer count, PostSortType sortBy, SortDirectionType sortDirection) {
    Query<Post> query = load();
    if (user != null && user.id != null) {
        query = query.filter(PostSortType.PostSortTypeAuthor.toString() + "Key", user);
    }
    if (showAll == null || !showAll.booleanValue()) {
        query = query.filter(PostSortType.PostSortTypeListed.toString(), Boolean.TRUE);
    }
    if (start != null) {
        query = query.offset(start.intValue());
    }
    if (count != null) {
        query = query.limit(count.intValue());
    }
    if (sortBy != null) {
        String condition = sortBy.toString();
        if (sortDirection != null) {
            switch(sortDirection) {
                case SortDirectionTypeDescending:
                    condition = "-" + condition;
                    break;
                default:
                    break;
            }
        }
        query = query.order(condition);
    }
    List<Post> posts = query.list();
    if (Boolean.TRUE.equals(includeContents)) {
        List<Long> postContentIds = new ArrayList<Long>();
        for (Post post : posts) {
            postContentIds.add(keyToId(post.contentKey));
        }
        Map<Long, PostContent> contents = loadContent().ids(postContentIds);
        for (Post post : posts) {
            post.content = contents.get(keyToId(post.contentKey));
        }
    }
    return posts;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) ArrayList(java.util.ArrayList) PostContent(com.willshex.blogwt.shared.api.datatype.PostContent)

Example 40 with Post

use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.

the class PostService method indexAll.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.search.IIndex#indexAll() */
@Override
public void indexAll() {
    Pager pager = PagerHelper.createDefaultPager();
    List<Post> posts = null;
    do {
        posts = getPosts(Boolean.FALSE, Boolean.FALSE, pager.start, pager.count, null, null);
        for (Post post : posts) {
            SearchHelper.queueToIndex(getName(), post.id);
        }
        PagerHelper.moveForward(pager);
    } while (posts != null && posts.size() >= pager.count.intValue());
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) Pager(com.willshex.blogwt.shared.api.Pager)

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