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