use of run.halo.app.model.entity.Content.PatchedContent in project halo by ruibaby.
the class BasePost method getContent.
/**
* Gets post content.
*
* @return a {@link PatchedContent} if present,otherwise an empty object
*/
@NonNull
public PatchedContent getContent() {
if (this.content == null) {
PatchedContent patchedContent = new PatchedContent();
patchedContent.setOriginalContent("");
patchedContent.setContent("");
return patchedContent;
}
return content;
}
use of run.halo.app.model.entity.Content.PatchedContent in project halo by ruibaby.
the class BasePostDetailDTO method convertFrom.
@Override
@NonNull
@SuppressWarnings("unchecked")
public <T extends BasePostMinimalDTO> T convertFrom(@NonNull BasePost domain) {
BasePostDetailDTO postDetailDTO = super.convertFrom(domain);
PatchedContent content = domain.getContent();
postDetailDTO.setContent(content.getContent());
postDetailDTO.setOriginalContent(content.getOriginalContent());
return (T) postDetailDTO;
}
use of run.halo.app.model.entity.Content.PatchedContent in project halo by ruibaby.
the class BasePostServiceImpl method generateAndSetSummaryIfAbsent.
protected <T extends BasePostSimpleDTO> void generateAndSetSummaryIfAbsent(POST post, T postVo) {
Assert.notNull(post, "The post must not be null.");
if (StringUtils.isNotBlank(postVo.getSummary())) {
return;
}
PatchedContent patchedContent = post.getContentOfNullable();
if (patchedContent == null) {
Content postContent = getContentById(post.getId());
postVo.setSummary(generateSummary(postContent.getContent()));
} else {
postVo.setSummary(generateSummary(patchedContent.getContent()));
}
}
use of run.halo.app.model.entity.Content.PatchedContent in project halo by ruibaby.
the class PostAssembler method convertTo.
/**
* Converts to post detail vo.
*
* @param post post must not be null
* @param tags tags
* @param categories categories
* @param postMetaList postMetaList
* @return post detail vo
*/
@NonNull
public PostDetailVO convertTo(@NonNull Post post, @Nullable List<Tag> tags, @Nullable List<Category> categories, List<PostMeta> postMetaList) {
Assert.notNull(post, "Post must not be null");
// Convert to base detail vo
PostDetailVO postDetailVO = new PostDetailVO().convertFrom(post);
generateAndSetSummaryIfAbsent(post, postDetailVO);
// Extract ids
Set<Integer> tagIds = ServiceUtils.fetchProperty(tags, Tag::getId);
Set<Integer> categoryIds = ServiceUtils.fetchProperty(categories, Category::getId);
Set<Long> metaIds = ServiceUtils.fetchProperty(postMetaList, PostMeta::getId);
// Get post tag ids
postDetailVO.setTagIds(tagIds);
postDetailVO.setTags(tagService.convertTo(tags));
// Get post category ids
postDetailVO.setCategoryIds(categoryIds);
postDetailVO.setCategories(categoryService.convertTo(categories));
// Get post meta ids
postDetailVO.setMetaIds(metaIds);
postDetailVO.setMetas(postMetaService.convertTo(postMetaList));
postDetailVO.setCommentCount(postCommentService.countByStatusAndPostId(CommentStatus.PUBLISHED, post.getId()));
postDetailVO.setFullPath(buildFullPath(post));
PatchedContent postContent = post.getContent();
postDetailVO.setContent(postContent.getContent());
postDetailVO.setOriginalContent(postContent.getOriginalContent());
// Post currently drafting in process
Boolean inProgress = contentService.draftingInProgress(post.getId());
postDetailVO.setInProgress(inProgress);
return postDetailVO;
}
use of run.halo.app.model.entity.Content.PatchedContent in project halo by ruibaby.
the class ContentPatchLogServiceImpl method applyPatch.
@Override
public PatchedContent applyPatch(ContentPatchLog patchLog) {
Assert.notNull(patchLog, "The contentRecord must not be null.");
Assert.notNull(patchLog.getVersion(), "The contentRecord.version must not be null.");
Assert.notNull(patchLog.getPostId(), "The contentRecord.postId must not be null.");
PatchedContent patchedContent = new PatchedContent();
if (patchLog.getVersion() == BASE_VERSION) {
patchedContent.setContent(patchLog.getContentDiff());
patchedContent.setOriginalContent(patchLog.getOriginalContentDiff());
return patchedContent;
}
ContentPatchLog baseContentRecord = contentPatchLogRepository.findByPostIdAndVersion(patchLog.getPostId(), BASE_VERSION);
String content = PatchUtils.restoreContent(patchLog.getContentDiff(), baseContentRecord.getContentDiff());
patchedContent.setContent(content);
String originalContent = PatchUtils.restoreContent(patchLog.getOriginalContentDiff(), baseContentRecord.getOriginalContentDiff());
patchedContent.setOriginalContent(originalContent);
return patchedContent;
}
Aggregations