Search in sources :

Example 16 with Post

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

the class PostService method updatePost.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.post.IPostService#updatePost(com.
	 * willshex.blogwt.shared.api.datatype.Post, java.util.Collection) */
@Override
public Post updatePost(Post post, Collection<String> removedTags) {
    post.slug = PostHelper.slugify(post.title);
    if (post.content != null) {
        if (post.content.created == null) {
            post.content.created = post.created;
        }
        if (post.content.postKey == null) {
            post.content.postKey = Key.create(post);
        }
        provide().save().entity(post.content).now();
    }
    String previousSlug = null, nextSlug = null;
    Post previousPost = null, nextPost = null;
    if (Boolean.TRUE.equals(post.listed) && post.published != null) {
        if (post.previousSlug == null && post.nextSlug == null) {
            previousPost = getPreviousPost(post);
            nextPost = getNextPost(post);
            if (previousPost != null) {
                post.previousSlug = previousPost.slug;
                previousPost.nextSlug = post.slug;
            }
            if (nextPost != null) {
                post.nextSlug = nextPost.slug;
                nextPost.previousSlug = post.slug;
            }
        }
    } else {
        previousSlug = post.previousSlug;
        nextSlug = post.nextSlug;
        post.previousSlug = null;
        post.nextSlug = null;
    }
    provide().save().entity(post).now();
    updateTags(post);
    if (removedTags != null) {
        deleteFromTags(post, removedTags);
    }
    if (Boolean.TRUE.equals(post.listed)) {
        ArchiveEntryServiceProvider.provide().archivePost(post);
    } else {
        deleteFromArchive(post);
        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);
        }
    }
    SearchHelper.queueToIndex(getName(), post.id);
    if (previousPost != null) {
        updatePost(previousPost, null);
    }
    return post;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post)

Example 17 with Post

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

the class TagService method addTagBatch.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.tag.ITagService#addTagBatch(java.
	 * util.Collection) */
@Override
public void addTagBatch(Collection<Tag> tags) {
    for (Tag tag : tags) {
        if (tag.created == null) {
            tag.created = new Date();
        }
        tag.name = tag.name.toLowerCase();
        tag.slug = PostHelper.slugify(tag.name);
        if (tag.posts != null) {
            for (Post post : tag.posts) {
                if (tag.postKeys == null) {
                    tag.postKeys = new ArrayList<Key<Post>>();
                }
                tag.postKeys.add(Key.create(post));
            }
        }
    }
    provide().save().entities(tags).now();
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) Tag(com.willshex.blogwt.shared.api.datatype.Tag) Date(java.util.Date) Key(com.googlecode.objectify.Key)

Example 18 with Post

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

the class CreatePostRequest method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("post")) {
        JsonElement jsonPost = jsonObject.get("post");
        if (jsonPost != null) {
            post = new Post();
            post.fromJson(jsonPost.getAsJsonObject());
        }
    }
    if (jsonObject.has("publish")) {
        JsonElement jsonPublish = jsonObject.get("publish");
        if (jsonPublish != null) {
            publish = Boolean.valueOf(jsonPublish.getAsBoolean());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Post(com.willshex.blogwt.shared.api.datatype.Post)

Example 19 with Post

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

the class GetPostResponse method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("post")) {
        JsonElement jsonPost = jsonObject.get("post");
        if (jsonPost != null) {
            post = new Post();
            post.fromJson(jsonPost.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Post(com.willshex.blogwt.shared.api.datatype.Post)

Example 20 with Post

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

the class GetRelatedPostsResponse method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("posts")) {
        JsonElement jsonPosts = jsonObject.get("posts");
        if (jsonPosts != null) {
            posts = new Post();
            posts.fromJson(jsonPosts.getAsJsonObject());
        }
    }
    if (jsonObject.has("pager")) {
        JsonElement jsonPager = jsonObject.get("pager");
        if (jsonPager != null) {
            pager = new Pager();
            pager.fromJson(jsonPager.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) 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