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