Search in sources :

Example 16 with PatchedContent

use of run.halo.app.model.entity.Content.PatchedContent in project halo by ruibaby.

the class SheetServiceImpl method getWithLatestContentById.

@Override
public Sheet getWithLatestContentById(Integer postId) {
    Sheet sheet = getById(postId);
    Content sheetContent = getContentById(postId);
    // Use the head pointer stored in the post content.
    PatchedContent patchedContent = sheetContentPatchLogService.getPatchedContentById(sheetContent.getHeadPatchLogId());
    sheet.setContent(patchedContent);
    return sheet;
}
Also used : PatchedContent(run.halo.app.model.entity.Content.PatchedContent) Content(run.halo.app.model.entity.Content) Sheet(run.halo.app.model.entity.Sheet) PatchedContent(run.halo.app.model.entity.Content.PatchedContent)

Example 17 with PatchedContent

use of run.halo.app.model.entity.Content.PatchedContent in project halo by ruibaby.

the class BasePostServiceImpl method createOrUpdateBy.

/**
 * @param post post for article
 * @return post with handled data
 */
@Override
@Transactional(rollbackFor = Exception.class)
public POST createOrUpdateBy(POST post) {
    Assert.notNull(post, "Post must not be null");
    PatchedContent postContent = post.getContent();
    // word count stat
    post.setWordCount(htmlFormatWordCount(postContent.getContent()));
    POST savedPost;
    // Create or update post
    if (ServiceUtils.isEmptyId(post.getId())) {
        // The sheet will be created
        savedPost = create(post);
        contentService.createOrUpdateDraftBy(post.getId(), postContent.getContent(), postContent.getOriginalContent());
    } else {
        // The sheet will be updated
        // Set edit time
        post.setEditTime(DateUtils.now());
        contentService.createOrUpdateDraftBy(post.getId(), postContent.getContent(), postContent.getOriginalContent());
        // Update it
        savedPost = update(post);
    }
    if (PostStatus.PUBLISHED.equals(post.getStatus()) || PostStatus.INTIMATE.equals(post.getStatus())) {
        contentService.publishContent(post.getId());
    }
    return savedPost;
}
Also used : PatchedContent(run.halo.app.model.entity.Content.PatchedContent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with PatchedContent

use of run.halo.app.model.entity.Content.PatchedContent in project halo by ruibaby.

the class ContentPatchLogServiceImplTest method getPatchedContentById.

@Test
public void getPatchedContentById() {
    PatchedContent patchedContent = contentPatchLogService.getPatchedContentById(2);
    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 : PatchedContent(run.halo.app.model.entity.Content.PatchedContent) Test(org.junit.jupiter.api.Test)

Example 19 with PatchedContent

use of run.halo.app.model.entity.Content.PatchedContent in project halo by ruibaby.

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)

Example 20 with PatchedContent

use of run.halo.app.model.entity.Content.PatchedContent in project halo by ruibaby.

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)

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