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;
}
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;
}
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");
}
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");
}
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()));
}
}
Aggregations