Search in sources :

Example 1 with PatchedContent

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

Example 2 with PatchedContent

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

Example 3 with PatchedContent

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()));
    }
}
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 4 with PatchedContent

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;
}
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 5 with PatchedContent

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;
}
Also used : ContentPatchLog(run.halo.app.model.entity.ContentPatchLog) 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 Category (run.halo.app.model.entity.Category)6 ContentPatchLog (run.halo.app.model.entity.ContentPatchLog)6 Tag (run.halo.app.model.entity.Tag)6 Date (java.util.Date)4 Test (org.junit.jupiter.api.Test)4 Transactional (org.springframework.transaction.annotation.Transactional)4 PostCategory (run.halo.app.model.entity.PostCategory)4 PostMeta (run.halo.app.model.entity.PostMeta)4 PostTag (run.halo.app.model.entity.PostTag)4 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