Search in sources :

Example 11 with SheetComment

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));
    }
}
Also used : SheetMeta(run.halo.app.model.entity.SheetMeta) HashMap(java.util.HashMap) JournalComment(run.halo.app.model.entity.JournalComment) Attachment(run.halo.app.model.entity.Attachment) Journal(run.halo.app.model.entity.Journal) Photo(run.halo.app.model.entity.Photo) ContentPatchLog(run.halo.app.model.entity.ContentPatchLog) PostComment(run.halo.app.model.entity.PostComment) PostMeta(run.halo.app.model.entity.PostMeta) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ContentPatchLog(run.halo.app.model.entity.ContentPatchLog) Log(run.halo.app.model.entity.Log) Content(run.halo.app.model.entity.Content) ThemeUpdatedEvent(run.halo.app.event.theme.ThemeUpdatedEvent) Option(run.halo.app.model.entity.Option) CommentBlackList(run.halo.app.model.entity.CommentBlackList) Link(run.halo.app.model.entity.Link) SheetComment(run.halo.app.model.entity.SheetComment) Category(run.halo.app.model.entity.Category) PostCategory(run.halo.app.model.entity.PostCategory) User(run.halo.app.model.entity.User) OptionUpdatedEvent(run.halo.app.event.options.OptionUpdatedEvent) PostCategory(run.halo.app.model.entity.PostCategory) ThemeSetting(run.halo.app.model.entity.ThemeSetting) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Menu(run.halo.app.model.entity.Menu) PostTag(run.halo.app.model.entity.PostTag) Post(run.halo.app.model.entity.Post) BadRequestException(run.halo.app.exception.BadRequestException) PostTag(run.halo.app.model.entity.PostTag) Tag(run.halo.app.model.entity.Tag) Sheet(run.halo.app.model.entity.Sheet)

Example 12 with SheetComment

use of run.halo.app.model.entity.SheetComment in project halo-plugin-experimental by guqing.

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);
    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<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));
    }
}
Also used : SheetMeta(run.halo.app.model.entity.SheetMeta) HashMap(java.util.HashMap) JournalComment(run.halo.app.model.entity.JournalComment) Attachment(run.halo.app.model.entity.Attachment) Journal(run.halo.app.model.entity.Journal) Photo(run.halo.app.model.entity.Photo) PostComment(run.halo.app.model.entity.PostComment) PostMeta(run.halo.app.model.entity.PostMeta) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Log(run.halo.app.model.entity.Log) ThemeUpdatedEvent(run.halo.app.event.theme.ThemeUpdatedEvent) Option(run.halo.app.model.entity.Option) CommentBlackList(run.halo.app.model.entity.CommentBlackList) Link(run.halo.app.model.entity.Link) SheetComment(run.halo.app.model.entity.SheetComment) PostCategory(run.halo.app.model.entity.PostCategory) Category(run.halo.app.model.entity.Category) User(run.halo.app.model.entity.User) OptionUpdatedEvent(run.halo.app.event.options.OptionUpdatedEvent) PostCategory(run.halo.app.model.entity.PostCategory) ThemeSetting(run.halo.app.model.entity.ThemeSetting) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Menu(run.halo.app.model.entity.Menu) PostTag(run.halo.app.model.entity.PostTag) Post(run.halo.app.model.entity.Post) PostTag(run.halo.app.model.entity.PostTag) Tag(run.halo.app.model.entity.Tag) Sheet(run.halo.app.model.entity.Sheet)

Example 13 with SheetComment

use of run.halo.app.model.entity.SheetComment in project halo-plugin-experimental by guqing.

the class SheetServiceImpl method removeById.

@Override
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);
    Sheet sheet = super.removeById(id);
    // Log it
    eventPublisher.publishEvent(new LogEvent(this, id.toString(), LogType.SHEET_DELETED, sheet.getTitle()));
    return sheet;
}
Also used : SheetComment(run.halo.app.model.entity.SheetComment) SheetMeta(run.halo.app.model.entity.SheetMeta) LogEvent(run.halo.app.event.logger.LogEvent) Sheet(run.halo.app.model.entity.Sheet)

Example 14 with SheetComment

use of run.halo.app.model.entity.SheetComment in project halo-plugin-experimental by guqing.

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 sheetCommentService.convertTo(sheetCommentService.update(commentToUpdate));
}
Also used : SheetComment(run.halo.app.model.entity.SheetComment) PutMapping(org.springframework.web.bind.annotation.PutMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 15 with SheetComment

use of run.halo.app.model.entity.SheetComment in project halo-plugin-experimental by guqing.

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 = postService.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 = sheetService.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);
}
Also used : SheetComment(run.halo.app.model.entity.SheetComment) User(run.halo.app.model.entity.User) PostCommentService(run.halo.app.service.PostCommentService) HashMap(java.util.HashMap) JournalComment(run.halo.app.model.entity.JournalComment) Journal(run.halo.app.model.entity.Journal) PostComment(run.halo.app.model.entity.PostComment) BasePostMinimalDTO(run.halo.app.model.dto.post.BasePostMinimalDTO) ServiceException(run.halo.app.exception.ServiceException) SheetCommentService(run.halo.app.service.SheetCommentService) JournalCommentService(run.halo.app.service.JournalCommentService) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Aggregations

SheetComment (run.halo.app.model.entity.SheetComment)15 HashMap (java.util.HashMap)9 Journal (run.halo.app.model.entity.Journal)9 JournalComment (run.halo.app.model.entity.JournalComment)9 PostComment (run.halo.app.model.entity.PostComment)9 Async (org.springframework.scheduling.annotation.Async)6 BasePostMinimalDTO (run.halo.app.model.dto.post.BasePostMinimalDTO)6 Sheet (run.halo.app.model.entity.Sheet)6 SheetMeta (run.halo.app.model.entity.SheetMeta)6 JournalCommentService (run.halo.app.service.JournalCommentService)6 PostCommentService (run.halo.app.service.PostCommentService)6 SheetCommentService (run.halo.app.service.SheetCommentService)6 User (run.halo.app.model.entity.User)5 EventListener (org.springframework.context.event.EventListener)4 Content (run.halo.app.model.entity.Content)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ApiOperation (io.swagger.annotations.ApiOperation)3 PutMapping (org.springframework.web.bind.annotation.PutMapping)3 LogEvent (run.halo.app.event.logger.LogEvent)3