use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class PageService method addPage.
@Override
public Page addPage(Page page) {
if (page.created == null) {
page.created = new Date();
}
page.ownerKey = Key.create(page.owner);
page.postKeys = new ArrayList<Key<Post>>();
for (Post post : page.posts) {
page.postKeys.add(Key.create(post));
}
if (page.parent != null) {
page.parentKey = Key.create(page.parent);
}
Key<Page> key = provide().save().entity(page).now();
page.id = keyToId(key);
SearchHelper.queueToIndex(getName(), page.id);
return page;
}
use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class PageService method populatePostContents.
private void populatePostContents(List<Page> pages) {
List<Post> posts = new ArrayList<Post>();
for (Page page : pages) {
posts.addAll(PersistenceHelper.batchLookup(PostServiceProvider.provide(), page.postKeys));
}
// FIXME: just load in one go (batcg)
for (Post post : posts) {
post.content = PostServiceProvider.provide().getPostContent(post);
}
Map<Long, Post> postLookup = new HashMap<Long, Post>();
for (Post post : posts) {
postLookup.put(post.id, post);
}
List<Post> pagePosts;
for (Page page : pages) {
pagePosts = new ArrayList<Post>();
for (Key<Post> key : page.postKeys) {
pagePosts.add(postLookup.get(keyToId(key)));
}
page.posts = pagePosts;
}
}
use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class PageService method toDocument.
/* (non-Javadoc)
*
* @see
* com.willshex.blogwt.server.service.search.IIndex#toDocument(java.lang.
* Object) */
@Override
public Document toDocument(Page page) {
Document document = null;
if (page != null) {
Document.Builder documentBuilder = Document.newBuilder();
documentBuilder.setId(getName() + page.id.toString()).addField(Field.newBuilder().setName("owner").setAtom(page.owner.username)).addField(Field.newBuilder().setName("owner").setText(UserHelper.name(page.owner))).addField(Field.newBuilder().setName("created").setDate(page.created)).addField(Field.newBuilder().setName("title").setText(page.title));
if (page.posts != null) {
StringBuilder body = new StringBuilder();
for (Post post : page.posts) {
body.append(post.content.body).append("\n\n");
}
documentBuilder.addField(Field.newBuilder().setName("body").setText(body.toString()));
}
document = documentBuilder.build();
}
return document;
}
use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class PostService method getUserViewablePosts.
/* (non-Javadoc)
*
* @see
* com.willshex.blogwt.server.service.post.IPostService#getUserViewablePosts
* (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> getUserViewablePosts(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);
}
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 indexAll.
/* (non-Javadoc)
*
* @see com.willshex.blogwt.server.service.search.IIndex#indexAll() */
@Override
public void indexAll() {
Pager pager = PagerHelper.createDefaultPager();
List<Post> posts = null;
do {
posts = getPosts(Boolean.FALSE, Boolean.FALSE, pager.start, pager.count, null, null);
for (Post post : posts) {
SearchHelper.queueToIndex(getName(), post.id);
}
PagerHelper.moveForward(pager);
} while (posts != null && posts.size() >= pager.count.intValue());
}
Aggregations