use of run.halo.app.model.entity.PostMeta in project halo by halo-dev.
the class PostServiceImpl method createOrUpdate.
private PostDetailVO createOrUpdate(@NonNull Post post, Set<Integer> tagIds, Set<Integer> categoryIds, Set<PostMeta> metas) {
Assert.notNull(post, "Post param must not be null");
post = super.createOrUpdateBy(post);
postTagService.removeByPostId(post.getId());
postCategoryService.removeByPostId(post.getId());
// List all tags
List<Tag> tags = tagService.listAllByIds(tagIds);
// List all categories
List<Category> categories = categoryService.listAllByIds(categoryIds);
// Create post tags
List<PostTag> postTags = postTagService.mergeOrCreateByIfAbsent(post.getId(), ServiceUtils.fetchProperty(tags, Tag::getId));
log.debug("Created post tags: [{}]", postTags);
// Create post categories
List<PostCategory> postCategories = postCategoryService.mergeOrCreateByIfAbsent(post.getId(), ServiceUtils.fetchProperty(categories, Category::getId));
log.debug("Created post categories: [{}]", postCategories);
// Create post meta data
List<PostMeta> postMetaList = postMetaService.createOrUpdateByPostId(post.getId(), metas);
log.debug("Created post metas: [{}]", postMetaList);
// Publish post updated event.
applicationContext.publishEvent(new PostUpdatedEvent(this, post));
// get draft content by head patch log id
Content postContent = postContentService.getById(post.getId());
post.setContent(postContentPatchLogService.getPatchedContentById(postContent.getHeadPatchLogId()));
// Convert to post detail vo
return postAssembler.convertTo(post, tags, categories, postMetaList);
}
use of run.halo.app.model.entity.PostMeta in project halo by halo-dev.
the class PostServiceImpl method removeById.
@Override
@Transactional(rollbackFor = Exception.class)
public Post removeById(Integer postId) {
Assert.notNull(postId, "Post id must not be null");
log.debug("Removing post: [{}]", postId);
// Remove post tags
List<PostTag> postTags = postTagService.removeByPostId(postId);
log.debug("Removed post tags: [{}]", postTags);
// Remove post categories
List<PostCategory> postCategories = postCategoryService.removeByPostId(postId);
log.debug("Removed post categories: [{}]", postCategories);
// Remove metas
List<PostMeta> metas = postMetaService.removeByPostId(postId);
log.debug("Removed post metas: [{}]", metas);
// Remove post comments
List<PostComment> postComments = postCommentService.removeByPostId(postId);
log.debug("Removed post comments: [{}]", postComments);
// Remove post content
Content postContent = postContentService.removeById(postId);
log.debug("Removed post content: [{}]", postContent);
Post deletedPost = super.removeById(postId);
deletedPost.setContent(PatchedContent.of(postContent));
// Log it
eventPublisher.publishEvent(new LogEvent(this, postId.toString(), LogType.POST_DELETED, deletedPost.getTitle()));
return deletedPost;
}
use of run.halo.app.model.entity.PostMeta in project halo by halo-dev.
the class PostServiceImpl method exportMarkdown.
@Override
public String exportMarkdown(Post post) {
Assert.notNull(post, "Post must not be null");
StringBuilder content = new StringBuilder("---\n");
content.append("type: ").append("post").append("\n");
content.append("title: ").append(post.getTitle()).append("\n");
content.append("permalink: ").append(post.getSlug()).append("\n");
content.append("thumbnail: ").append(post.getThumbnail()).append("\n");
content.append("status: ").append(post.getStatus()).append("\n");
content.append("date: ").append(post.getCreateTime()).append("\n");
content.append("updated: ").append(post.getEditTime()).append("\n");
content.append("comments: ").append(!post.getDisallowComment()).append("\n");
List<Tag> tags = postTagService.listTagsBy(post.getId());
if (tags.size() > 0) {
content.append("tags:").append("\n");
for (Tag tag : tags) {
content.append(" - ").append(tag.getName()).append("\n");
}
}
List<Category> categories = postCategoryService.listCategoriesBy(post.getId());
if (categories.size() > 0) {
content.append("categories:").append("\n");
for (Category category : categories) {
content.append(" - ").append(category.getName()).append("\n");
}
}
List<PostMeta> metas = postMetaService.listBy(post.getId());
if (metas.size() > 0) {
content.append("metas:").append("\n");
for (PostMeta postMeta : metas) {
content.append(" - ").append(postMeta.getKey()).append(" : ").append(postMeta.getValue()).append("\n");
}
}
content.append("---\n\n");
PatchedContent postContent = post.getContent();
content.append(postContent.getOriginalContent());
return content.toString();
}
use of run.halo.app.model.entity.PostMeta in project halo by halo-dev.
the class PostAssembler method convertToListVo.
/**
* Converts to a page of post list vo.
*
* @param postPage post page must not be null
* @return a page of post list vo
*/
@NonNull
public Page<PostListVO> convertToListVo(Page<Post> postPage) {
Assert.notNull(postPage, "Post page must not be null");
List<Post> posts = postPage.getContent();
Set<Integer> postIds = ServiceUtils.fetchProperty(posts, Post::getId);
// Get tag list map
Map<Integer, List<Tag>> tagListMap = postTagService.listTagListMapBy(postIds);
// Get category list map
Map<Integer, List<Category>> categoryListMap = postCategoryService.listCategoryListMap(postIds);
// Get comment count
Map<Integer, Long> commentCountMap = postCommentService.countByStatusAndPostIds(CommentStatus.PUBLISHED, postIds);
// Get post meta list map
Map<Integer, List<PostMeta>> postMetaListMap = postMetaService.listPostMetaAsMap(postIds);
return postPage.map(post -> {
PostListVO postListVO = new PostListVO().convertFrom(post);
generateAndSetSummaryIfAbsent(post, postListVO);
Optional.ofNullable(tagListMap.get(post.getId())).orElseGet(LinkedList::new);
// Set tags
postListVO.setTags(Optional.ofNullable(tagListMap.get(post.getId())).orElseGet(LinkedList::new).stream().filter(Objects::nonNull).map(tagService::convertTo).collect(Collectors.toList()));
// Set categories
postListVO.setCategories(Optional.ofNullable(categoryListMap.get(post.getId())).orElseGet(LinkedList::new).stream().filter(Objects::nonNull).map(categoryService::convertTo).collect(Collectors.toList()));
// Set post metas
List<PostMeta> metas = Optional.ofNullable(postMetaListMap.get(post.getId())).orElseGet(LinkedList::new);
postListVO.setMetas(postMetaService.convertToMap(metas));
// Set comment count
postListVO.setCommentCount(commentCountMap.getOrDefault(post.getId(), 0L));
postListVO.setFullPath(buildFullPath(post));
// Post currently drafting in process
Boolean isInProcess = contentService.draftingInProgress(post.getId());
postListVO.setInProgress(isInProcess);
return postListVO;
});
}
use of run.halo.app.model.entity.PostMeta in project halo by halo-dev.
the class PostParam method getPostMetas.
public Set<PostMeta> getPostMetas() {
Set<PostMeta> postMetaSet = new HashSet<>();
if (CollectionUtils.isEmpty(metas)) {
return postMetaSet;
}
for (PostMetaParam postMetaParam : metas) {
PostMeta postMeta = postMetaParam.convertTo();
postMetaSet.add(postMeta);
}
return postMetaSet;
}
Aggregations