use of run.halo.app.model.entity.Content.PatchedContent in project halo by ruibaby.
the class SheetAssembler method convertTo.
@NonNull
public SheetDetailVO convertTo(@NonNull Sheet sheet, List<SheetMeta> metas) {
Assert.notNull(sheet, "Sheet must not be null");
// Convert to base detail vo
SheetDetailVO sheetDetailVO = new SheetDetailVO().convertFrom(sheet);
Set<Long> metaIds = ServiceUtils.fetchProperty(metas, SheetMeta::getId);
// Get sheet meta ids
sheetDetailVO.setMetaIds(metaIds);
sheetDetailVO.setMetas(sheetMetaService.convertTo(metas));
generateAndSetSummaryIfAbsent(sheet, sheetDetailVO);
sheetDetailVO.setCommentCount(sheetCommentService.countByStatusAndPostId(CommentStatus.PUBLISHED, sheet.getId()));
sheetDetailVO.setFullPath(buildFullPath(sheet));
PatchedContent sheetContent = sheet.getContent();
sheetDetailVO.setContent(sheetContent.getContent());
sheetDetailVO.setOriginalContent(sheetContent.getOriginalContent());
// Sheet currently drafting in process
Boolean inProgress = contentService.draftingInProgress(sheet.getId());
sheetDetailVO.setInProgress(inProgress);
return sheetDetailVO;
}
use of run.halo.app.model.entity.Content.PatchedContent in project halo by halo-dev.
the class BasePostAssembler 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 = contentService.getByIdOfNullable(post.getId());
if (postContent != null) {
postVo.setSummary(generateSummary(postContent.getContent()));
} else {
postVo.setSummary(StringUtils.EMPTY);
}
} else {
postVo.setSummary(generateSummary(patchedContent.getContent()));
}
}
use of run.halo.app.model.entity.Content.PatchedContent in project halo by halo-dev.
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 halo-dev.
the class SheetAssembler method convertTo.
@NonNull
public SheetDetailVO convertTo(@NonNull Sheet sheet, List<SheetMeta> metas) {
Assert.notNull(sheet, "Sheet must not be null");
// Convert to base detail vo
SheetDetailVO sheetDetailVO = new SheetDetailVO().convertFrom(sheet);
Set<Long> metaIds = ServiceUtils.fetchProperty(metas, SheetMeta::getId);
// Get sheet meta ids
sheetDetailVO.setMetaIds(metaIds);
sheetDetailVO.setMetas(sheetMetaService.convertTo(metas));
generateAndSetSummaryIfAbsent(sheet, sheetDetailVO);
sheetDetailVO.setCommentCount(sheetCommentService.countByStatusAndPostId(CommentStatus.PUBLISHED, sheet.getId()));
sheetDetailVO.setFullPath(buildFullPath(sheet));
PatchedContent sheetContent = sheet.getContent();
sheetDetailVO.setContent(sheetContent.getContent());
sheetDetailVO.setOriginalContent(sheetContent.getOriginalContent());
// Sheet currently drafting in process
Boolean inProgress = contentService.draftingInProgress(sheet.getId());
sheetDetailVO.setInProgress(inProgress);
return sheetDetailVO;
}
use of run.halo.app.model.entity.Content.PatchedContent in project halo by halo-dev.
the class ContentPatchLogServiceImplTest method applyPatch.
@Test
public void applyPatch() {
ContentPatchLog contentPatchLogV2 = new ContentPatchLog();
contentPatchLogV2.setId(2);
contentPatchLogV2.setSourceId(1);
contentPatchLogV2.setPostId(2);
contentPatchLogV2.setVersion(2);
contentPatchLogV2.setStatus(PostStatus.DRAFT);
contentPatchLogV2.setCreateTime(new Date());
contentPatchLogV2.setUpdateTime(new Date());
contentPatchLogV2.setContentDiff("[{\"source\":{\"position\":2,\"lines\":[]," + "\"changePosition\":null},\"target\":{\"position\":2," + "\"lines\":[\"<p>造化钟神秀,阴阳割昏晓。</p>\"],\"changePosition\":null},\"type\":\"INSERT\"}]");
contentPatchLogV2.setOriginalContentDiff("[{\"source\":{\"position\":4,\"lines\":[]," + "\"changePosition\":null},\"target\":{\"position\":4,\"lines\":[\"造化钟神秀,阴阳割昏晓。\"," + "\"\"],\"changePosition\":null},\"type\":\"INSERT\"}]");
PatchedContent patchedContent = contentPatchLogService.applyPatch(contentPatchLogV2);
assertThat(patchedContent).isNotNull();
assertThat(patchedContent.getContent()).isEqualTo("<p>望岳</p>\n" + "<p>岱宗夫如何,齐鲁青未了。</p>\n" + "<p>造化钟神秀,阴阳割昏晓。</p>\n");
assertThat(patchedContent.getOriginalContent()).isEqualTo("望岳\n\n岱宗夫如何,齐鲁青未了。\n" + "\n造化钟神秀,阴阳割昏晓。\n");
}
Aggregations