use of run.halo.app.model.entity.SheetComment in project halo by halo-dev.
the class SheetCommentController method updateBy.
@PutMapping("{commentId:\\d+}")
@ApiOperation("Updates a sheet comment")
public BaseCommentDTO updateBy(@Valid @RequestBody SheetCommentParam commentParam, @PathVariable("commentId") Long commentId) {
SheetComment commentToUpdate = sheetCommentService.getById(commentId);
commentParam.update(commentToUpdate);
return sheetCommentAssembler.convertTo(sheetCommentService.update(commentToUpdate));
}
use of run.halo.app.model.entity.SheetComment in project halo by halo-dev.
the class CommentEventListener method handleCommentNewEvent.
/**
* Received a new new comment event.
*
* @param newEvent new comment event.
*/
@Async
@EventListener
public void handleCommentNewEvent(CommentNewEvent newEvent) {
Boolean newCommentNotice = optionService.getByPropertyOrDefault(CommentProperties.NEW_NOTICE, Boolean.class, false);
if (!newCommentNotice) {
// Skip mailing
return;
}
User user = userService.getCurrentUser().orElseThrow(() -> new ServiceException("未查询到博主信息"));
Map<String, Object> data = new HashMap<>();
StringBuilder subject = new StringBuilder();
Boolean enabledAbsolutePath = optionService.isEnabledAbsolutePath();
if (newEvent.getSource() instanceof PostCommentService) {
// Get postComment id
PostComment postComment = postCommentService.getById(newEvent.getCommentId());
log.debug("Got post comment: [{}]", postComment);
BasePostMinimalDTO post = postAssembler.convertToMinimal(postService.getById(postComment.getPostId()));
data.put("pageFullPath", enabledAbsolutePath ? post.getFullPath() : optionService.getBlogBaseUrl() + post.getFullPath());
data.put("pageTitle", post.getTitle());
data.put("author", postComment.getAuthor());
data.put("content", postComment.getContent());
subject.append("您的博客文章《").append(post.getTitle()).append("》有了新的评论。");
} else if (newEvent.getSource() instanceof SheetCommentService) {
SheetComment sheetComment = sheetCommentService.getById(newEvent.getCommentId());
log.debug("Got sheet comment: [{}]", sheetComment);
BasePostMinimalDTO sheet = sheetAssembler.convertToMinimal(sheetService.getById(sheetComment.getPostId()));
data.put("pageFullPath", enabledAbsolutePath ? sheet.getFullPath() : optionService.getBlogBaseUrl() + sheet.getFullPath());
data.put("pageTitle", sheet.getTitle());
data.put("author", sheetComment.getAuthor());
data.put("content", sheetComment.getContent());
subject.append("您的博客页面《").append(sheet.getTitle()).append("》有了新的评论。");
} else if (newEvent.getSource() instanceof JournalCommentService) {
JournalComment journalComment = journalCommentService.getById(newEvent.getCommentId());
log.debug("Got journal comment: [{}]", journalComment);
Journal journal = journalService.getById(journalComment.getPostId());
StringBuilder url = new StringBuilder(optionService.getBlogBaseUrl()).append("/").append(optionService.getJournalsPrefix());
data.put("pageFullPath", url);
data.put("pageTitle", journal.getCreateTime());
data.put("author", journalComment.getAuthor());
data.put("content", journalComment.getContent());
subject.append("您的博客日志有了新的评论");
}
String template = "common/mail_template/mail_notice.ftl";
if (themeService.templateExists("mail_template/mail_notice.ftl")) {
template = themeService.renderWithSuffix("mail_template/mail_notice");
}
mailService.sendTemplateMail(user.getEmail(), subject.toString(), data, template);
}
use of run.halo.app.model.entity.SheetComment in project halo by halo-dev.
the class CommentEventListener method handleCommentReplyEvent.
/**
* Received a new reply comment event.
*
* @param replyEvent reply comment event.
*/
@Async
@EventListener
public void handleCommentReplyEvent(CommentReplyEvent replyEvent) {
Boolean replyCommentNotice = optionService.getByPropertyOrDefault(CommentProperties.REPLY_NOTICE, Boolean.class, false);
if (!replyCommentNotice) {
// Skip mailing
return;
}
String baseAuthorEmail = "";
String blogTitle = optionService.getBlogTitle();
Map<String, Object> data = new HashMap<>();
StringBuilder subject = new StringBuilder();
Boolean enabledAbsolutePath = optionService.isEnabledAbsolutePath();
log.debug("replyEvent.getSource():" + replyEvent.getSource().toString());
if (replyEvent.getSource() instanceof PostCommentService) {
PostComment postComment = postCommentService.getById(replyEvent.getCommentId());
PostComment baseComment = postCommentService.getById(postComment.getParentId());
if (StringUtils.isEmpty(baseComment.getEmail()) && !ValidationUtils.isEmail(baseComment.getEmail())) {
return;
}
if (!baseComment.getAllowNotification()) {
return;
}
baseAuthorEmail = baseComment.getEmail();
BasePostMinimalDTO post = postAssembler.convertToMinimal(postService.getById(postComment.getPostId()));
data.put("pageFullPath", enabledAbsolutePath ? post.getFullPath() : optionService.getBlogBaseUrl() + post.getFullPath());
data.put("pageTitle", post.getTitle());
data.put("baseAuthor", baseComment.getAuthor());
data.put("baseContent", baseComment.getContent());
data.put("replyAuthor", postComment.getAuthor());
data.put("replyContent", postComment.getContent());
subject.append("您在【").append(blogTitle).append("】评论的文章《").append(post.getTitle()).append("》有了新的评论。");
} else if (replyEvent.getSource() instanceof SheetCommentService) {
SheetComment sheetComment = sheetCommentService.getById(replyEvent.getCommentId());
SheetComment baseComment = sheetCommentService.getById(sheetComment.getParentId());
if (StringUtils.isEmpty(baseComment.getEmail()) && !ValidationUtils.isEmail(baseComment.getEmail())) {
return;
}
if (!baseComment.getAllowNotification()) {
return;
}
baseAuthorEmail = baseComment.getEmail();
BasePostMinimalDTO sheet = sheetAssembler.convertToMinimal(sheetService.getById(sheetComment.getPostId()));
data.put("pageFullPath", enabledAbsolutePath ? sheet.getFullPath() : optionService.getBlogBaseUrl() + sheet.getFullPath());
data.put("pageTitle", sheet.getTitle());
data.put("baseAuthor", baseComment.getAuthor());
data.put("baseContent", baseComment.getContent());
data.put("replyAuthor", sheetComment.getAuthor());
data.put("replyContent", sheetComment.getContent());
subject.append("您在【").append(blogTitle).append("】评论的页面《").append(sheet.getTitle()).append("》有了新的评论。");
} else if (replyEvent.getSource() instanceof JournalCommentService) {
JournalComment journalComment = journalCommentService.getById(replyEvent.getCommentId());
JournalComment baseComment = journalCommentService.getById(journalComment.getParentId());
if (StringUtils.isEmpty(baseComment.getEmail()) && !ValidationUtils.isEmail(baseComment.getEmail())) {
return;
}
if (!baseComment.getAllowNotification()) {
return;
}
baseAuthorEmail = baseComment.getEmail();
Journal journal = journalService.getById(journalComment.getPostId());
StringBuilder url = new StringBuilder(optionService.getBlogBaseUrl()).append("/").append(optionService.getJournalsPrefix());
data.put("pageFullPath", url);
data.put("pageTitle", journal.getContent());
data.put("baseAuthor", baseComment.getAuthor());
data.put("baseContent", baseComment.getContent());
data.put("replyAuthor", journalComment.getAuthor());
data.put("replyContent", journalComment.getContent());
subject.append("您在【").append(blogTitle).append("】评论的日志").append("有了新的评论。");
}
String template = "common/mail_template/mail_reply.ftl";
if (themeService.templateExists("mail_template/mail_reply.ftl")) {
template = themeService.renderWithSuffix("mail_template/mail_reply");
}
mailService.sendTemplateMail(baseAuthorEmail, subject.toString(), data, template);
}
use of run.halo.app.model.entity.SheetComment in project halo by halo-dev.
the class SheetServiceImpl method removeById.
@Override
@Transactional(rollbackFor = Exception.class)
public Sheet removeById(Integer id) {
// Remove sheet metas
List<SheetMeta> metas = sheetMetaService.removeByPostId(id);
log.debug("Removed sheet metas: [{}]", metas);
// Remove sheet comments
List<SheetComment> sheetComments = sheetCommentService.removeByPostId(id);
log.debug("Removed sheet comments: [{}]", sheetComments);
// Remove sheet content
Content sheetContent = sheetContentService.removeById(id);
log.debug("Removed sheet content: [{}]", sheetContent);
Sheet sheet = super.removeById(id);
sheet.setContent(PatchedContent.of(sheetContent));
// Log it
eventPublisher.publishEvent(new LogEvent(this, id.toString(), LogType.SHEET_DELETED, sheet.getTitle()));
return sheet;
}
use of run.halo.app.model.entity.SheetComment in project halo by halo-dev.
the class BackupServiceImpl method importData.
@Override
public void importData(MultipartFile file) throws IOException {
String jsonContent = FileUtils.readString(file.getInputStream());
ObjectMapper mapper = JsonUtils.createDefaultJsonMapper();
TypeReference<HashMap<String, Object>> typeRef = new TypeReference<>() {
};
HashMap<String, Object> data = mapper.readValue(jsonContent, typeRef);
String version = (String) Objects.requireNonNullElse(data.get("version"), "");
if (!VersionUtil.hasSameMajorAndMinorVersion(HaloConst.HALO_VERSION, version)) {
throw new BadRequestException("导入数据的主次版本号与当前系统版本号不匹配,不支持导入!");
}
List<Attachment> attachments = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("attachments")), Attachment[].class));
attachmentService.createInBatch(attachments);
List<Category> categories = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("categories")), Category[].class));
categoryService.createInBatch(categories);
List<Tag> tags = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("tags")), Tag[].class));
tagService.createInBatch(tags);
List<CommentBlackList> commentBlackList = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("comment_black_list")), CommentBlackList[].class));
commentBlackListService.createInBatch(commentBlackList);
List<Journal> journals = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("journals")), Journal[].class));
journalService.createInBatch(journals);
List<JournalComment> journalComments = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("journal_comments")), JournalComment[].class));
journalCommentService.createInBatch(journalComments);
List<Link> links = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("links")), Link[].class));
linkService.createInBatch(links);
List<Log> logs = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("logs")), Log[].class));
logService.createInBatch(logs);
List<Menu> menus = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("menus")), Menu[].class));
menuService.createInBatch(menus);
List<Option> options = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("options")), Option[].class));
optionService.createInBatch(options);
eventPublisher.publishEvent(new OptionUpdatedEvent(this));
List<Photo> photos = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("photos")), Photo[].class));
photoService.createInBatch(photos);
List<Post> posts = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("posts")), Post[].class));
postService.createInBatch(posts);
List<Content> contents = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("contents")), Content[].class));
contentService.createInBatch(contents);
List<ContentPatchLog> contentPatchLogs = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("content_patch_logs")), ContentPatchLog[].class));
contentPatchLogService.createInBatch(contentPatchLogs);
List<PostCategory> postCategories = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("post_categories")), PostCategory[].class));
postCategoryService.createInBatch(postCategories);
List<PostComment> postComments = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("post_comments")), PostComment[].class));
postCommentService.createInBatch(postComments);
List<PostMeta> postMetas = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("post_metas")), PostMeta[].class));
postMetaService.createInBatch(postMetas);
List<PostTag> postTags = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("post_tags")), PostTag[].class));
postTagService.createInBatch(postTags);
List<Sheet> sheets = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("sheets")), Sheet[].class));
sheetService.createInBatch(sheets);
List<SheetComment> sheetComments = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("sheet_comments")), SheetComment[].class));
sheetCommentService.createInBatch(sheetComments);
List<SheetMeta> sheetMetas = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("sheet_metas")), SheetMeta[].class));
sheetMetaService.createInBatch(sheetMetas);
List<ThemeSetting> themeSettings = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("theme_settings")), ThemeSetting[].class));
themeSettingService.createInBatch(themeSettings);
eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
List<User> users = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("user")), User[].class));
if (users.size() > 0) {
userService.create(users.get(0));
}
}
Aggregations