From f9a629c38f0acd053ed437d259765490202d9445 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Sun, 28 Mar 2021 20:22:54 +0800 Subject: [PATCH] feat: #1036 (#1331) * feat: #1036 * revert: BaseCommentRepository. --- .../admin/api/DataProcessController.java | 50 ----- .../halo/app/model/dto/BaseCommentDTO.java | 1 + .../model/properties/CommentProperties.java | 5 + .../halo/app/service/AttachmentService.java | 9 - .../halo/app/service/DataProcessService.java | 20 -- .../run/halo/app/service/OptionService.java | 9 - .../run/halo/app/service/PhotoService.java | 9 - .../halo/app/service/ThemeSettingService.java | 9 - .../app/service/base/BaseCommentService.java | 34 ---- .../app/service/base/BasePostService.java | 10 - .../service/impl/AttachmentServiceImpl.java | 19 +- .../service/impl/BaseCommentServiceImpl.java | 182 ++++++++---------- .../app/service/impl/BasePostServiceImpl.java | 20 -- .../service/impl/DataProcessServiceImpl.java | 74 ------- .../impl/JournalCommentServiceImpl.java | 15 +- .../app/service/impl/OptionServiceImpl.java | 19 +- .../app/service/impl/PhotoServiceImpl.java | 21 +- .../service/impl/PostCommentServiceImpl.java | 33 ++-- .../service/impl/SheetCommentServiceImpl.java | 43 +++-- .../service/impl/ThemeSettingServiceImpl.java | 14 -- 20 files changed, 150 insertions(+), 446 deletions(-) delete mode 100644 src/main/java/run/halo/app/controller/admin/api/DataProcessController.java delete mode 100644 src/main/java/run/halo/app/service/DataProcessService.java delete mode 100644 src/main/java/run/halo/app/service/impl/DataProcessServiceImpl.java diff --git a/src/main/java/run/halo/app/controller/admin/api/DataProcessController.java b/src/main/java/run/halo/app/controller/admin/api/DataProcessController.java deleted file mode 100644 index 2e6ec122a..000000000 --- a/src/main/java/run/halo/app/controller/admin/api/DataProcessController.java +++ /dev/null @@ -1,50 +0,0 @@ -//package run.halo.app.controller.admin.api; -// -//import io.swagger.annotations.ApiOperation; -//import org.springframework.web.bind.annotation.*; -//import run.halo.app.service.DataProcessService; -//import run.halo.app.service.ThemeSettingService; -// -///** -// * @author ryanwang -// * @date 2019-12-29 -// */ -//@RestController -//@RequestMapping("/api/admin/data/process") -//public class DataProcessController { -// -// private final DataProcessService dataProcessService; -// -// private final ThemeSettingService themeSettingService; -// -// public DataProcessController(DataProcessService dataProcessService, -// ThemeSettingService themeSettingService) { -// this.dataProcessService = dataProcessService; -// this.themeSettingService = themeSettingService; -// } -// -// @PutMapping("url/replace") -// @ApiOperation("Replace url in all table.") -// public void replaceUrl(@RequestParam("oldUrl") String oldUrl, -// @RequestParam("newUrl") String newUrl) { -// dataProcessService.replaceAllUrl(oldUrl, newUrl); -// } -// -// @DeleteMapping("themes/settings/inactivated") -// @ApiOperation("Delete inactivated theme settings.") -// public void deleteInactivatedThemeSettings() { -// themeSettingService.deleteInactivated(); -// } -// -// @DeleteMapping("tags/unused") -// @ApiOperation("Delete unused tags") -// public void deleteUnusedTags() { -// // TODO -// } -// -// @DeleteMapping("categories/unused") -// @ApiOperation("Delete unused categories") -// public void deleteUnusedCategories() { -// // TODO -// } -//} diff --git a/src/main/java/run/halo/app/model/dto/BaseCommentDTO.java b/src/main/java/run/halo/app/model/dto/BaseCommentDTO.java index eef45e0a6..6522fe5bd 100644 --- a/src/main/java/run/halo/app/model/dto/BaseCommentDTO.java +++ b/src/main/java/run/halo/app/model/dto/BaseCommentDTO.java @@ -46,4 +46,5 @@ public class BaseCommentDTO implements OutputConverter { * @return list of type. */ List listAllType(); - - /** - * Replace attachment url in batch. - * - * @param oldUrl old blog url. - * @param newUrl new blog url. - * @return replaced attachments. - */ - List replaceUrl(@NonNull String oldUrl, @NonNull String newUrl); } diff --git a/src/main/java/run/halo/app/service/DataProcessService.java b/src/main/java/run/halo/app/service/DataProcessService.java deleted file mode 100644 index adf9d253d..000000000 --- a/src/main/java/run/halo/app/service/DataProcessService.java +++ /dev/null @@ -1,20 +0,0 @@ -package run.halo.app.service; - -import org.springframework.lang.NonNull; - -/** - * Data process service interface. - * - * @author ryanwang - * @date 2019-12-29 - */ -public interface DataProcessService { - - /** - * Replace all url. - * - * @param oldUrl old url must not be null. - * @param newUrl new url must not be null. - */ - void replaceAllUrl(@NonNull String oldUrl, @NonNull String newUrl); -} diff --git a/src/main/java/run/halo/app/service/OptionService.java b/src/main/java/run/halo/app/service/OptionService.java index 6a50704c8..94bbc4c0b 100755 --- a/src/main/java/run/halo/app/service/OptionService.java +++ b/src/main/java/run/halo/app/service/OptionService.java @@ -468,15 +468,6 @@ public interface OptionService extends CrudService { */ Boolean isEnabledAbsolutePath(); - /** - * Replace option url in batch. - * - * @param oldUrl old blog url. - * @param newUrl new blog url. - * @return replaced options. - */ - List replaceUrl(@NonNull String oldUrl, @NonNull String newUrl); - /** * Converts to option output dto. * diff --git a/src/main/java/run/halo/app/service/PhotoService.java b/src/main/java/run/halo/app/service/PhotoService.java index 0654d04c5..7c1adc081 100644 --- a/src/main/java/run/halo/app/service/PhotoService.java +++ b/src/main/java/run/halo/app/service/PhotoService.java @@ -79,13 +79,4 @@ public interface PhotoService extends CrudService { * @return list of teams */ List listAllTeams(); - - /** - * Replace photo url in batch. - * - * @param oldUrl old blog url. - * @param newUrl new blog url. - * @return replaced photos. - */ - List replaceUrl(@NonNull String oldUrl, @NonNull String newUrl); } diff --git a/src/main/java/run/halo/app/service/ThemeSettingService.java b/src/main/java/run/halo/app/service/ThemeSettingService.java index 9d584265b..85a44ed1f 100644 --- a/src/main/java/run/halo/app/service/ThemeSettingService.java +++ b/src/main/java/run/halo/app/service/ThemeSettingService.java @@ -56,15 +56,6 @@ public interface ThemeSettingService extends CrudService @NonNull Map listAsMapBy(@NonNull String themeId); - /** - * Replace theme setting url in batch. - * - * @param oldUrl old blog url. - * @param newUrl new blog url. - * @return replaced theme settings. - */ - List replaceUrl(@NonNull String oldUrl, @NonNull String newUrl); - /** * Delete unused theme setting. */ diff --git a/src/main/java/run/halo/app/service/base/BaseCommentService.java b/src/main/java/run/halo/app/service/base/BaseCommentService.java index a2263a9e9..ddacd7b57 100644 --- a/src/main/java/run/halo/app/service/base/BaseCommentService.java +++ b/src/main/java/run/halo/app/service/base/BaseCommentService.java @@ -296,38 +296,4 @@ public interface BaseCommentService @NonNull List listChildrenBy(@NonNull Integer targetId, @NonNull Long commentParentId, @NonNull Sort sort); - - /** - * Filters comment ip address. - * - * @param comment comment dto must not be null - */ - @Deprecated - T filterIpAddress(@NonNull T comment); - - /** - * Filters comment ip address. - * - * @param comments comment dto list - */ - @Deprecated - List filterIpAddress(@Nullable List comments); - - /** - * Filters comment ip address. - * - * @param commentPage comment page - */ - @Deprecated - Page filterIpAddress(@NonNull Page commentPage); - - /** - * Replace comment url in batch. - * - * @param oldUrl old blog url. - * @param newUrl new blog url. - * @return replaced comments. - */ - List replaceUrl(@NonNull String oldUrl, @NonNull String newUrl); - } diff --git a/src/main/java/run/halo/app/service/base/BasePostService.java b/src/main/java/run/halo/app/service/base/BasePostService.java index 4f0aa73af..23502dcd5 100644 --- a/src/main/java/run/halo/app/service/base/BasePostService.java +++ b/src/main/java/run/halo/app/service/base/BasePostService.java @@ -297,16 +297,6 @@ public interface BasePostService extends CrudService updateStatusByIds(@NonNull List ids, @NonNull PostStatus status); - /** - * Replace post blog url in batch. - * - * @param oldUrl old blog url. - * @param newUrl new blog url. - * @return replaced posts. - */ - @NonNull - List replaceUrl(@NonNull String oldUrl, @NonNull String newUrl); - /** * Generate description. * diff --git a/src/main/java/run/halo/app/service/impl/AttachmentServiceImpl.java b/src/main/java/run/halo/app/service/impl/AttachmentServiceImpl.java index 2bb85bee6..01d9b38d0 100644 --- a/src/main/java/run/halo/app/service/impl/AttachmentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/AttachmentServiceImpl.java @@ -1,6 +1,5 @@ package run.halo.app.service.impl; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; @@ -77,7 +76,7 @@ public class AttachmentServiceImpl extends AbstractCrudService buildSpecByQuery(@NonNull AttachmentQuery attachmentQuery) { Assert.notNull(attachmentQuery, "Attachment query must not be null"); - return (Specification) (root, query, criteriaBuilder) -> { + return (root, query, criteriaBuilder) -> { List predicates = new LinkedList<>(); if (attachmentQuery.getMediaType() != null) { @@ -198,22 +197,6 @@ public class AttachmentServiceImpl extends AbstractCrudService replaceUrl(String oldUrl, String newUrl) { - List attachments = listAll(); - List replaced = new ArrayList<>(); - attachments.forEach(attachment -> { - if (StringUtils.isNotEmpty(attachment.getPath())) { - attachment.setPath(attachment.getPath().replaceAll(oldUrl, newUrl)); - } - if (StringUtils.isNotEmpty(attachment.getThumbPath())) { - attachment.setThumbPath(attachment.getThumbPath().replaceAll(oldUrl, newUrl)); - } - replaced.add(attachment); - }); - return updateInBatch(replaced); - } - @Override public Attachment create(Attachment attachment) { Assert.notNull(attachment, "Attachment must not be null"); diff --git a/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java b/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java index cf47f4be8..f2c535ff3 100644 --- a/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java @@ -13,7 +13,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Queue; import java.util.Set; import java.util.stream.Collectors; import javax.persistence.criteria.Predicate; @@ -86,18 +85,21 @@ public abstract class BaseCommentServiceImpl } @Override - public List listBy(Integer postId) { + @NonNull + public List listBy(@NonNull Integer postId) { Assert.notNull(postId, "Post id must not be null"); return baseCommentRepository.findAllByPostId(postId); } @Override - public Page pageLatest(int top) { + @NonNull + public Page pageLatest(@NonNull int top) { return pageLatest(top, null); } @Override + @NonNull public Page pageLatest(int top, CommentStatus status) { if (status == null) { return listAll(ServiceUtils.buildLatestPageable(top)); @@ -107,7 +109,8 @@ public abstract class BaseCommentServiceImpl } @Override - public Page pageBy(CommentStatus status, Pageable pageable) { + @NonNull + public Page pageBy(@NonNull CommentStatus status, @NonNull Pageable pageable) { Assert.notNull(status, "Comment status must not be null"); Assert.notNull(pageable, "Page info must not be null"); @@ -117,14 +120,16 @@ public abstract class BaseCommentServiceImpl } @Override - public Page pageBy(CommentQuery commentQuery, Pageable pageable) { + @NonNull + public Page pageBy(@NonNull CommentQuery commentQuery, @NonNull Pageable pageable) { Assert.notNull(pageable, "Page info must not be null"); return baseCommentRepository.findAll(buildSpecByQuery(commentQuery), pageable); } @Override - public Page pageVosAllBy(Integer postId, Pageable pageable) { + @NonNull + public Page pageVosAllBy(@NonNull Integer postId, @NonNull Pageable pageable) { Assert.notNull(postId, "Post id must not be null"); Assert.notNull(pageable, "Page info must not be null"); @@ -137,7 +142,9 @@ public abstract class BaseCommentServiceImpl } @Override - public Page pageVosBy(List comments, Pageable pageable) { + @NonNull + public Page pageVosBy(@NonNull List comments, + @NonNull Pageable pageable) { Assert.notNull(comments, "Comments must not be null"); Assert.notNull(pageable, "Page info must not be null"); @@ -170,7 +177,8 @@ public abstract class BaseCommentServiceImpl } @Override - public Page pageVosBy(Integer postId, Pageable pageable) { + @NonNull + public Page pageVosBy(@NonNull Integer postId, @NonNull Pageable pageable) { Assert.notNull(postId, "Post id must not be null"); Assert.notNull(pageable, "Page info must not be null"); @@ -184,7 +192,9 @@ public abstract class BaseCommentServiceImpl } @Override - public Page pageWithParentVoBy(Integer postId, Pageable pageable) { + @NonNull + public Page pageWithParentVoBy(@NonNull Integer postId, + @NonNull Pageable pageable) { Assert.notNull(postId, "Post id must not be null"); Assert.notNull(pageable, "Page info must not be null"); @@ -214,9 +224,11 @@ public abstract class BaseCommentServiceImpl // Convert to comment page return commentPage.map(comment -> { // Convert to with parent vo - BaseCommentWithParentVO commentWithParentVO = + BaseCommentWithParentVO commentWithParentVo = new BaseCommentWithParentVO().convertFrom(comment); + commentWithParentVo.setAvatar(buildAvatarUrl(commentWithParentVo.getGravatarMd5())); + // Get parent comment vo from cache BaseCommentWithParentVO parentCommentVo = parentCommentVoMap.get(comment.getParentId()); @@ -227,19 +239,23 @@ public abstract class BaseCommentServiceImpl if (parentComment != null) { // Convert to parent comment vo parentCommentVo = new BaseCommentWithParentVO().convertFrom(parentComment); + + parentCommentVo.setAvatar(buildAvatarUrl(parentComment.getGravatarMd5())); + // Cache the parent comment vo parentCommentVoMap.put(parentComment.getId(), parentCommentVo); } } // Set parent - commentWithParentVO.setParent(parentCommentVo == null ? null : parentCommentVo.clone()); + commentWithParentVo.setParent(parentCommentVo == null ? null : parentCommentVo.clone()); - return commentWithParentVO; + return commentWithParentVo; }); } @Override + @NonNull public Map countByPostIds(Collection postIds) { if (CollectionUtils.isEmpty(postIds)) { return Collections.emptyMap(); @@ -269,18 +285,19 @@ public abstract class BaseCommentServiceImpl } @Override - public long countByPostId(Integer postId) { + public long countByPostId(@NonNull Integer postId) { Assert.notNull(postId, "Post id must not be null"); return baseCommentRepository.countByPostId(postId); } @Override - public long countByStatus(CommentStatus status) { + public long countByStatus(@NonNull CommentStatus status) { return baseCommentRepository.countByStatus(status); } @Override - public COMMENT create(COMMENT comment) { + @NonNull + public COMMENT create(@NonNull COMMENT comment) { Assert.notNull(comment, "Domain must not be null"); // Check post id @@ -294,7 +311,8 @@ public abstract class BaseCommentServiceImpl } // Check user login status and set this field - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + final Authentication authentication = + SecurityContextHolder.getContext().getAuthentication(); // Set some default values if (comment.getIpAddress() == null) { @@ -342,7 +360,8 @@ public abstract class BaseCommentServiceImpl } @Override - public COMMENT createBy(BaseCommentParam commentParam) { + @NonNull + public COMMENT createBy(@NonNull BaseCommentParam commentParam) { Assert.notNull(commentParam, "Comment param must not be null"); // Check user login status and set this field @@ -374,7 +393,8 @@ public abstract class BaseCommentServiceImpl } @Override - public COMMENT updateStatus(Long commentId, CommentStatus status) { + @NonNull + public COMMENT updateStatus(@NonNull Long commentId, @NonNull CommentStatus status) { Assert.notNull(commentId, "Comment id must not be null"); Assert.notNull(status, "Comment status must not be null"); @@ -389,7 +409,8 @@ public abstract class BaseCommentServiceImpl } @Override - public List updateStatusByIds(List ids, CommentStatus status) { + @NonNull + public List updateStatusByIds(@NonNull List ids, @NonNull CommentStatus status) { if (CollectionUtils.isEmpty(ids)) { return Collections.emptyList(); } @@ -399,13 +420,14 @@ public abstract class BaseCommentServiceImpl } @Override - public List removeByPostId(Integer postId) { + public List removeByPostId(@NonNull Integer postId) { Assert.notNull(postId, "Post id must not be null"); return baseCommentRepository.deleteByPostId(postId); } @Override - public COMMENT removeById(Long id) { + @NonNull + public COMMENT removeById(@NonNull Long id) { Assert.notNull(id, "Comment id must not be null"); COMMENT comment = baseCommentRepository.findById(id) @@ -424,7 +446,8 @@ public abstract class BaseCommentServiceImpl } @Override - public List removeByIds(Collection ids) { + @NonNull + public List removeByIds(@NonNull Collection ids) { if (CollectionUtils.isEmpty(ids)) { return Collections.emptyList(); } @@ -432,7 +455,8 @@ public abstract class BaseCommentServiceImpl } @Override - public List convertTo(List comments) { + @NonNull + public List convertTo(@NonNull List comments) { if (CollectionUtils.isEmpty(comments)) { return Collections.emptyList(); } @@ -442,17 +466,23 @@ public abstract class BaseCommentServiceImpl } @Override - public Page convertTo(Page commentPage) { + @NonNull + public Page convertTo(@NonNull Page commentPage) { Assert.notNull(commentPage, "Comment page must not be null"); return commentPage.map(this::convertTo); } @Override - public BaseCommentDTO convertTo(COMMENT comment) { + @NonNull + public BaseCommentDTO convertTo(@NonNull COMMENT comment) { Assert.notNull(comment, "Comment must not be null"); - return new BaseCommentDTO().convertFrom(comment); + BaseCommentDTO baseCommentDto = new BaseCommentDTO().convertFrom(comment); + + baseCommentDto.setAvatar(buildAvatarUrl(comment.getGravatarMd5())); + + return baseCommentDto; } @NonNull @@ -527,8 +557,10 @@ public abstract class BaseCommentServiceImpl } @Override - public Page pageTopCommentsBy(Integer targetId, CommentStatus status, - Pageable pageable) { + @NonNull + public Page pageTopCommentsBy(@NonNull Integer targetId, + @NonNull CommentStatus status, + @NonNull Pageable pageable) { Assert.notNull(targetId, "Target id must not be null"); Assert.notNull(status, "Comment status must not be null"); Assert.notNull(pageable, "Page info must not be null"); @@ -561,13 +593,15 @@ public abstract class BaseCommentServiceImpl new CommentWithHasChildrenVO().convertFrom(topComment); comment .setHasChildren(commentChildrenCountMap.getOrDefault(topComment.getId(), 0L) > 0); + comment.setAvatar(buildAvatarUrl(topComment.getGravatarMd5())); return comment; }); } @Override - public List listChildrenBy(Integer targetId, Long commentParentId, - CommentStatus status, Sort sort) { + @NonNull + public List listChildrenBy(@NonNull Integer targetId, @NonNull Long commentParentId, + @NonNull CommentStatus status, @NonNull Sort sort) { Assert.notNull(targetId, "Target id must not be null"); Assert.notNull(commentParentId, "Comment parent id must not be null"); Assert.notNull(sort, "Sort info must not be null"); @@ -592,7 +626,9 @@ public abstract class BaseCommentServiceImpl } @Override - public List listChildrenBy(Integer targetId, Long commentParentId, Sort sort) { + @NonNull + public List listChildrenBy(@NonNull Integer targetId, @NonNull Long commentParentId, + @NonNull Sort sort) { Assert.notNull(targetId, "Target id must not be null"); Assert.notNull(commentParentId, "Comment parent id must not be null"); Assert.notNull(sort, "Sort info must not be null"); @@ -616,70 +652,6 @@ public abstract class BaseCommentServiceImpl return childrenList; } - @Override - @Deprecated - public T filterIpAddress(@NonNull T comment) { - Assert.notNull(comment, "Base comment dto must not be null"); - - // Clear ip address - comment.setIpAddress(""); - - // Handle base comment vo - if (comment instanceof BaseCommentVO) { - BaseCommentVO baseCommentVO = (BaseCommentVO) comment; - Queue commentQueue = new LinkedList<>(); - commentQueue.offer(baseCommentVO); - while (!commentQueue.isEmpty()) { - BaseCommentVO current = commentQueue.poll(); - - // Clear ip address - current.setIpAddress(""); - - if (!CollectionUtils.isEmpty(current.getChildren())) { - // Add children - commentQueue.addAll(current.getChildren()); - } - } - } - - return comment; - } - - @Override - @Deprecated - public List filterIpAddress(List comments) { - if (CollectionUtils.isEmpty(comments)) { - return Collections.emptyList(); - } - - comments.forEach(this::filterIpAddress); - - return comments; - } - - @Override - @Deprecated - public Page filterIpAddress(Page commentPage) { - Assert.notNull(commentPage, "Comment page must not be null"); - commentPage.forEach(this::filterIpAddress); - - return commentPage; - } - - @Override - public List replaceUrl(String oldUrl, String newUrl) { - List comments = listAll(); - List replaced = new ArrayList<>(); - comments.forEach(comment -> { - if (StringUtils.isNotEmpty(comment.getAuthorUrl())) { - comment.setAuthorUrl(comment.getAuthorUrl().replaceAll(oldUrl, newUrl)); - } - replaced.add(comment); - }); - List updated = updateInBatch(replaced); - return convertTo(updated); - } - /** * Get children comments recursively. * @@ -761,13 +733,15 @@ public abstract class BaseCommentServiceImpl // Add children children.forEach(comment -> { // Convert to comment vo - BaseCommentVO commentVO = new BaseCommentVO().convertFrom(comment); + BaseCommentVO commentVo = new BaseCommentVO().convertFrom(comment); + + commentVo.setAvatar(buildAvatarUrl(commentVo.getGravatarMd5())); if (parentComment.getChildren() == null) { parentComment.setChildren(new LinkedList<>()); } - parentComment.getChildren().add(commentVO); + parentComment.getChildren().add(commentVo); }); // Remove children @@ -784,4 +758,18 @@ public abstract class BaseCommentServiceImpl } } + /** + * Build avatar url by gravatarMd5 + * + * @param gravatarMd5 gravatarMd5 + * @return avatar url + */ + public String buildAvatarUrl(String gravatarMd5) { + final String gravatarSource = + optionService.getByPropertyOrDefault(CommentProperties.GRAVATAR_SOURCE, String.class); + final String gravatarDefault = + optionService.getByPropertyOrDefault(CommentProperties.GRAVATAR_DEFAULT, String.class); + + return gravatarSource + gravatarMd5 + "?d=" + gravatarDefault; + } } diff --git a/src/main/java/run/halo/app/service/impl/BasePostServiceImpl.java b/src/main/java/run/halo/app/service/impl/BasePostServiceImpl.java index 3cd29980e..1537202af 100644 --- a/src/main/java/run/halo/app/service/impl/BasePostServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/BasePostServiceImpl.java @@ -456,26 +456,6 @@ public abstract class BasePostServiceImpl }).collect(Collectors.toList()); } - @Override - public List replaceUrl(String oldUrl, String newUrl) { - List posts = listAll(); - List replaced = new ArrayList<>(); - posts.forEach(post -> { - if (StringUtils.isNotEmpty(post.getThumbnail())) { - post.setThumbnail(post.getThumbnail().replaceAll(oldUrl, newUrl)); - } - if (StringUtils.isNotEmpty(post.getOriginalContent())) { - post.setOriginalContent(post.getOriginalContent().replaceAll(oldUrl, newUrl)); - } - if (StringUtils.isNotEmpty(post.getFormatContent())) { - post.setFormatContent(post.getFormatContent().replaceAll(oldUrl, newUrl)); - } - replaced.add(post); - }); - List updated = updateInBatch(replaced); - return updated.stream().map(this::convertToDetail).collect(Collectors.toList()); - } - @Override public String generateDescription(String content) { Assert.notNull(content, "html content must not be null"); diff --git a/src/main/java/run/halo/app/service/impl/DataProcessServiceImpl.java b/src/main/java/run/halo/app/service/impl/DataProcessServiceImpl.java deleted file mode 100644 index 677e5ddad..000000000 --- a/src/main/java/run/halo/app/service/impl/DataProcessServiceImpl.java +++ /dev/null @@ -1,74 +0,0 @@ -package run.halo.app.service.impl; - -import org.springframework.stereotype.Service; -import run.halo.app.service.AttachmentService; -import run.halo.app.service.DataProcessService; -import run.halo.app.service.JournalCommentService; -import run.halo.app.service.OptionService; -import run.halo.app.service.PhotoService; -import run.halo.app.service.PostCommentService; -import run.halo.app.service.PostService; -import run.halo.app.service.SheetCommentService; -import run.halo.app.service.SheetService; -import run.halo.app.service.ThemeSettingService; - -/** - * DataProcessService implementation. - * - * @author ryanwang - * @date 2019-12-29 - */ -@Service -public class DataProcessServiceImpl implements DataProcessService { - - private final PostService postService; - - private final SheetService sheetService; - - private final PostCommentService postCommentService; - - private final SheetCommentService sheetCommentService; - - private final JournalCommentService journalCommentService; - - private final AttachmentService attachmentService; - - private final OptionService optionService; - - private final PhotoService photoService; - - private final ThemeSettingService themeSettingService; - - public DataProcessServiceImpl(PostService postService, - SheetService sheetService, - PostCommentService postCommentService, - SheetCommentService sheetCommentService, - JournalCommentService journalCommentService, - AttachmentService attachmentService, - OptionService optionService, - PhotoService photoService, - ThemeSettingService themeSettingService) { - this.postService = postService; - this.sheetService = sheetService; - this.postCommentService = postCommentService; - this.sheetCommentService = sheetCommentService; - this.journalCommentService = journalCommentService; - this.attachmentService = attachmentService; - this.optionService = optionService; - this.photoService = photoService; - this.themeSettingService = themeSettingService; - } - - @Override - public void replaceAllUrl(String oldUrl, String newUrl) { - postService.replaceUrl(oldUrl, newUrl); - sheetService.replaceUrl(oldUrl, newUrl); - postCommentService.replaceUrl(oldUrl, newUrl); - sheetCommentService.replaceUrl(oldUrl, newUrl); - journalCommentService.replaceUrl(oldUrl, newUrl); - attachmentService.replaceUrl(oldUrl, newUrl); - optionService.replaceUrl(oldUrl, newUrl); - photoService.replaceUrl(oldUrl, newUrl); - themeSettingService.replaceUrl(oldUrl, newUrl); - } -} diff --git a/src/main/java/run/halo/app/service/impl/JournalCommentServiceImpl.java b/src/main/java/run/halo/app/service/impl/JournalCommentServiceImpl.java index 676d1b96b..e9bc9b559 100644 --- a/src/main/java/run/halo/app/service/impl/JournalCommentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/JournalCommentServiceImpl.java @@ -9,6 +9,7 @@ import java.util.stream.Collectors; import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; +import org.springframework.lang.NonNull; import org.springframework.stereotype.Service; import org.springframework.util.Assert; import run.halo.app.exception.NotFoundException; @@ -33,8 +34,6 @@ import run.halo.app.utils.ServiceUtils; public class JournalCommentServiceImpl extends BaseCommentServiceImpl implements JournalCommentService { - private final JournalCommentRepository journalCommentRepository; - private final JournalRepository journalRepository; public JournalCommentServiceImpl(JournalCommentRepository journalCommentRepository, @@ -42,18 +41,18 @@ public class JournalCommentServiceImpl extends BaseCommentServiceImpl convertToWithJournalVo( List journalComments) { @@ -76,22 +75,24 @@ public class JournalCommentServiceImpl extends BaseCommentServiceImpl convertToWithJournalVo( - Page journalCommentPage) { + @NonNull Page journalCommentPage) { Assert.notNull(journalCommentPage, "Journal comment page must not be null"); // Convert the list - List journalCmtWithJournalVOS = + List journalCmtWithJournalVos = convertToWithJournalVo(journalCommentPage.getContent()); // Build and return - return new PageImpl<>(journalCmtWithJournalVOS, journalCommentPage.getPageable(), + return new PageImpl<>(journalCmtWithJournalVos, journalCommentPage.getPageable(), journalCommentPage.getTotalElements()); } } diff --git a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java index c11a002a9..40a7c2b01 100644 --- a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java @@ -2,7 +2,6 @@ package run.halo.app.service.impl; import com.qiniu.common.Zone; import com.qiniu.storage.Region; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; @@ -12,7 +11,6 @@ import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; import javax.persistence.criteria.Predicate; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -275,7 +273,7 @@ public class OptionServiceImpl extends AbstractCrudService private Specification