Search in sources :

Example 11 with Post

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

the class ArchiveEntryService method updateArchiveEntryPost.

@Override
public ArchiveEntry updateArchiveEntryPost(final ArchiveEntry archiveEntry, final Post post) {
    ArchiveEntry updated = null;
    if (Boolean.TRUE.equals(post.listed) && post.published != null) {
        updated = provide().transact(new Work<ArchiveEntry>() {

            @Override
            public ArchiveEntry run() {
                ArchiveEntry latest = getArchiveEntry(archiveEntry.id);
                if (latest.postKeys == null) {
                    latest.postKeys = new ArrayList<Key<Post>>();
                }
                boolean found = false;
                for (Key<Post> key : latest.postKeys) {
                    if (DataTypeHelper.<Post>same(key, post)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    latest.postKeys.add(Key.create(post));
                }
                provide().save().entity(latest).now();
                return latest;
            }
        });
    }
    return updated;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) Work(com.googlecode.objectify.Work) ArchiveEntry(com.willshex.blogwt.shared.api.datatype.ArchiveEntry) Key(com.googlecode.objectify.Key)

Example 12 with Post

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

the class PostService method linkAll.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.post.IPostService#linkAll() */
@Override
public void linkAll() {
    Pager pager = PagerHelper.createDefaultPager();
    List<Post> posts = null;
    Post last = null;
    do {
        posts = getPosts(Boolean.FALSE, Boolean.FALSE, pager.start, pager.count, PostSortType.PostSortTypePublished, SortDirectionType.SortDirectionTypeDescending);
        if (posts != null && posts.size() > 0) {
            for (int i = 0, next = -1, previous = 1; i < posts.size(); i++, previous++, next++) {
                if (i == 0 && last != null) {
                    posts.get(i).nextSlug = last.slug;
                    last.previousSlug = posts.get(i).slug;
                    updatePost(last, null);
                    last = null;
                }
                if (next >= 0) {
                    posts.get(i).nextSlug = posts.get(next).slug;
                }
                if (previous < posts.size()) {
                    posts.get(i).previousSlug = posts.get(previous).slug;
                } else if (previous == posts.size()) {
                    last = posts.get(i);
                }
                // last will get updated twice for all but last page
                updatePost(posts.get(i), null);
            }
        }
        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 13 with Post

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

the class PostService method deletePost.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.post.IPostService#deletePost(com.
	 * willshex.blogwt.shared.api.datatype.Post) */
@Override
public void deletePost(Post post) {
    deleteFromTags(post, post.tags);
    deleteFromArchive(post);
    String previousSlug = null, nextSlug = null;
    Post previousPost = null, nextPost = null;
    if (post.published != null && Boolean.TRUE.equals(post.listed)) {
        previousSlug = post.previousSlug;
        nextSlug = post.nextSlug;
    }
    provide().delete().entity(post).now();
    provide().delete().key(post.contentKey).now();
    SearchHelper.deleteSearch(getName() + post.id.toString());
    if (previousSlug != null && nextSlug != null) {
        previousPost = getSlugPost(previousSlug);
        nextPost = getSlugPost(nextSlug);
        previousPost.nextSlug = nextPost.slug;
        nextPost.previousSlug = previousPost.slug;
        updatePost(previousPost, null);
        updatePost(nextPost, null);
    } else if (previousSlug != null) {
        previousPost = getSlugPost(previousSlug);
        previousPost.nextSlug = null;
        updatePost(previousPost, null);
    } else if (nextSlug != null) {
        nextPost = getSlugPost(nextSlug);
        nextPost.previousSlug = null;
        updatePost(nextPost, null);
    }
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post)

Example 14 with Post

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

the class PostService method index.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.blogwt.server.service.search.IIndex#index(java.lang.Long) */
@Override
public void index(Long id) {
    Post post = getPost(id);
    if (post.authorKey != null) {
        post.author = UserServiceProvider.provide().getUser(keyToId(post.authorKey));
    }
    if (post.contentKey != null) {
        post.content = loadContent().id(keyToId(post.contentKey)).now();
    }
    SearchHelper.indexDocument(toDocument(post));
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post)

Example 15 with Post

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

the class PostService method search.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.search.ISearch#search(java.lang.
	 * String, java.lang.Integer, java.lang.Integer, java.lang.String,
	 * com.willshex.blogwt.shared.api.SortDirectionType) */
@Override
public List<Post> search(String query, Integer start, Integer count, String sortBy, SortDirectionType direction) {
    Results<ScoredDocument> matches = SearchHelper.getIndex().search(query);
    List<Post> posts = new ArrayList<Post>();
    String id;
    Post post;
    int limit = SearchHelper.SHORT_SEARCH_LIMIT;
    final String postServiceName = getName();
    for (ScoredDocument scoredDocument : matches) {
        if (limit == 0) {
            break;
        }
        if ((id = scoredDocument.getId()).startsWith(postServiceName)) {
            post = getPost(Long.valueOf(id.replace(postServiceName, "")));
            if (post != null) {
                posts.add(post);
            }
        }
        limit--;
    }
    return posts;
}
Also used : ScoredDocument(com.google.appengine.api.search.ScoredDocument) Post(com.willshex.blogwt.shared.api.datatype.Post) ArrayList(java.util.ArrayList)

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