Search in sources :

Example 21 with PatchedContent

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;
}
Also used : SheetMeta(run.halo.app.model.entity.SheetMeta) SheetDetailVO(run.halo.app.model.vo.SheetDetailVO) PatchedContent(run.halo.app.model.entity.Content.PatchedContent) NonNull(org.springframework.lang.NonNull)

Example 22 with PatchedContent

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()));
    }
}
Also used : PatchedContent(run.halo.app.model.entity.Content.PatchedContent) Content(run.halo.app.model.entity.Content) PatchedContent(run.halo.app.model.entity.Content.PatchedContent)

Example 23 with PatchedContent

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;
}
Also used : Category(run.halo.app.model.entity.Category) PostMeta(run.halo.app.model.entity.PostMeta) PostDetailVO(run.halo.app.model.vo.PostDetailVO) Tag(run.halo.app.model.entity.Tag) PatchedContent(run.halo.app.model.entity.Content.PatchedContent) NonNull(org.springframework.lang.NonNull)

Example 24 with PatchedContent

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;
}
Also used : SheetMeta(run.halo.app.model.entity.SheetMeta) SheetDetailVO(run.halo.app.model.vo.SheetDetailVO) PatchedContent(run.halo.app.model.entity.Content.PatchedContent) NonNull(org.springframework.lang.NonNull)

Example 25 with PatchedContent

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");
}
Also used : ContentPatchLog(run.halo.app.model.entity.ContentPatchLog) PatchedContent(run.halo.app.model.entity.Content.PatchedContent) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

PatchedContent (run.halo.app.model.entity.Content.PatchedContent)30 Content (run.halo.app.model.entity.Content)10 NonNull (org.springframework.lang.NonNull)8 ContentPatchLog (run.halo.app.model.entity.ContentPatchLog)6 Category (run.halo.app.model.entity.Category)5 Tag (run.halo.app.model.entity.Tag)5 Date (java.util.Date)4 Test (org.junit.jupiter.api.Test)4 Transactional (org.springframework.transaction.annotation.Transactional)4 PostMeta (run.halo.app.model.entity.PostMeta)4 PostCategory (run.halo.app.model.entity.PostCategory)3 PostTag (run.halo.app.model.entity.PostTag)3 Post (run.halo.app.model.entity.Post)2 Sheet (run.halo.app.model.entity.Sheet)2 SheetMeta (run.halo.app.model.entity.SheetMeta)2 PostDetailVO (run.halo.app.model.vo.PostDetailVO)2 PostMarkdownVO (run.halo.app.model.vo.PostMarkdownVO)2 SheetDetailVO (run.halo.app.model.vo.SheetDetailVO)2