Search in sources :

Example 41 with Post

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

the class PostService method clearLinks.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.post.IPostService#clearLinks() */
@Override
public void clearLinks() {
    Pager pager = PagerHelper.createDefaultPager();
    List<Post> posts = null;
    do {
        posts = getPosts(Boolean.FALSE, Boolean.FALSE, pager.start, pager.count, PostSortType.PostSortTypePublished, SortDirectionType.SortDirectionTypeDescending);
        if (posts != null) {
            for (Post post : posts) {
                post.nextSlug = null;
                post.previousSlug = null;
            }
            provide().save().entities(posts).now();
        }
        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)

Example 42 with Post

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

the class PostService method getUserViewablePartialSlugPosts.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.post.IPostService#
	 * getUserViewablePartialSlugPosts(java.lang.String,
	 * 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> getUserViewablePartialSlugPosts(String partialSlug, 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);
    }
    if (partialSlug != null) {
        query = SearchHelper.addStartsWith("slug", partialSlug.toLowerCase(), query);
    }
    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 43 with Post

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

the class PostService method getLastPublishedPost.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.blogwt.server.service.post.IPostService#getLastPublishedPost
	 * () */
@Override
public Post getLastPublishedPost() {
    Post last = null;
    List<Post> posts = getPosts(Boolean.FALSE, Boolean.FALSE, Integer.valueOf(0), Integer.valueOf(1), PostSortType.PostSortTypePublished, SortDirectionType.SortDirectionTypeDescending);
    if (posts != null && posts.size() != 0) {
        last = posts.get(0);
    }
    return last;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post)

Example 44 with Post

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

the class PostService method addPost.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.blogwt.server.service.post.IPostService#addPost(com.willshex
	 * .blogwt.shared.api.datatype.Post) */
@Override
public Post addPost(Post post) {
    if (post.created == null) {
        post.created = new Date();
    }
    post.slug = nextPostSlug(PostHelper.slugify(post.title));
    post.authorKey = Key.create(post.author);
    if (post.content.created == null) {
        post.content.created = post.created;
    }
    post.contentKey = provide().save().entity(post.content).now();
    Post previousPost = null;
    // just been published
    if (post.published != null && post.previousSlug == null) {
        previousPost = getLastPublishedPost();
        if (previousPost != null) {
            post.previousSlug = previousPost.slug;
            previousPost.nextSlug = post.slug;
        }
    }
    Key<Post> key = provide().save().entity(post).now();
    post.id = keyToId(key);
    post.content.postKey = key;
    provide().save().entity(post.content).now();
    updateTags(post);
    ArchiveEntryServiceProvider.provide().archivePost(post);
    SearchHelper.queueToIndex(getName(), post.id);
    if (previousPost != null) {
        updatePost(previousPost, null);
    }
    return post;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) Date(java.util.Date)

Example 45 with Post

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

the class TagService method generateTags.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.tag.ITagService#generateTags() */
@Override
public void generateTags() {
    Map<String, Tag> tagLookup = new HashMap<String, Tag>();
    List<Post> posts;
    Tag tag;
    Pager pager = PagerHelper.createDefaultPager();
    do {
        posts = PostServiceProvider.provide().getPosts(Boolean.FALSE, Boolean.FALSE, pager.start, pager.count, PostSortType.PostSortTypePublished, SortDirectionType.SortDirectionTypeDescending);
        if (posts != null) {
            PagerHelper.moveForward(pager);
            for (Post post : posts) {
                if (post.tags != null) {
                    for (String postTag : post.tags) {
                        tag = tagLookup.get(postTag.toLowerCase());
                        if (tag == null) {
                            tag = new Tag().name(postTag.toLowerCase()).posts(new ArrayList<Post>());
                            tagLookup.put(tag.name, tag);
                        }
                        tag.posts.add(post);
                    }
                }
            }
        }
    } while (posts != null && posts.size() >= pager.count.intValue());
    if (tagLookup.size() > 0) {
        addTagBatch(tagLookup.values());
    }
}
Also used : HashMap(java.util.HashMap) Post(com.willshex.blogwt.shared.api.datatype.Post) Pager(com.willshex.blogwt.shared.api.Pager) ArrayList(java.util.ArrayList) Tag(com.willshex.blogwt.shared.api.datatype.Tag)

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