use of run.halo.app.model.entity.SheetMeta in project halo by ruibaby.
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));
}
}
use of run.halo.app.model.entity.SheetMeta in project halo by ruibaby.
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);
// Remove sheet content
Content sheetContent = sheetContentService.removeById(id);
log.debug("Removed sheet content: [{}]", sheetContent);
Sheet sheet = super.removeById(id);
// Log it
eventPublisher.publishEvent(new LogEvent(this, id.toString(), LogType.SHEET_DELETED, sheet.getTitle()));
return sheet;
}
use of run.halo.app.model.entity.SheetMeta in project halo by ruibaby.
the class SheetServiceImpl method createBy.
@Override
public Sheet createBy(Sheet sheet, Set<SheetMeta> metas, boolean autoSave) {
Sheet createdSheet = createOrUpdateBy(sheet);
// Create sheet meta data
List<SheetMeta> sheetMetaList = sheetMetaService.createOrUpdateByPostId(sheet.getId(), metas);
log.debug("Created sheet metas: [{}]", sheetMetaList);
if (!autoSave) {
// Log the creation
LogEvent logEvent = new LogEvent(this, createdSheet.getId().toString(), LogType.SHEET_PUBLISHED, createdSheet.getTitle());
eventPublisher.publishEvent(logEvent);
}
return createdSheet;
}
use of run.halo.app.model.entity.SheetMeta in project halo by ruibaby.
the class SheetServiceImpl method updateBy.
@Override
public Sheet updateBy(Sheet sheet, Set<SheetMeta> metas, boolean autoSave) {
Sheet updatedSheet = createOrUpdateBy(sheet);
// Create sheet meta data
List<SheetMeta> sheetMetaList = sheetMetaService.createOrUpdateByPostId(updatedSheet.getId(), metas);
log.debug("Created sheet metas: [{}]", sheetMetaList);
if (!autoSave) {
// Log the creation
LogEvent logEvent = new LogEvent(this, updatedSheet.getId().toString(), LogType.SHEET_EDITED, updatedSheet.getTitle());
eventPublisher.publishEvent(logEvent);
}
return updatedSheet;
}
use of run.halo.app.model.entity.SheetMeta in project halo by ruibaby.
the class SheetModel method content.
/**
* Sheet content.
*
* @param sheet sheet
* @param token token
* @param model model
* @return template name
*/
public String content(Sheet sheet, String token, Model model) {
SheetDetailVO sheetDetailVo;
if (StringUtils.isEmpty(token)) {
sheet = sheetService.getBy(PostStatus.PUBLISHED, sheet.getSlug());
sheetDetailVo = sheetRenderAssembler.convertToDetailVo(sheet);
} else {
// verify token
String cachedToken = cacheStore.getAny(token, String.class).orElseThrow(() -> new ForbiddenException("您没有该页面的访问权限"));
if (!cachedToken.equals(token)) {
throw new ForbiddenException("您没有该页面的访问权限");
}
sheetDetailVo = sheetRenderAssembler.convertToPreviewDetailVo(sheet);
}
sheetService.publishVisitEvent(sheet.getId());
List<SheetMeta> metas = sheetMetaService.listBy(sheet.getId());
// Generate meta keywords.
if (StringUtils.isNotEmpty(sheet.getMetaKeywords())) {
model.addAttribute("meta_keywords", sheet.getMetaKeywords());
} else {
model.addAttribute("meta_keywords", optionService.getSeoKeywords());
}
// Generate meta description.
if (StringUtils.isNotEmpty(sheet.getMetaDescription())) {
model.addAttribute("meta_description", sheet.getMetaDescription());
} else {
model.addAttribute("meta_description", sheetService.generateDescription(sheet.getContent().getContent()));
}
// sheet and post all can use
model.addAttribute("sheet", sheetDetailVo);
model.addAttribute("post", sheetDetailVo);
model.addAttribute("is_sheet", true);
model.addAttribute("metas", sheetMetaService.convertToMap(metas));
if (themeService.templateExists(ThemeService.CUSTOM_SHEET_PREFIX + sheet.getTemplate() + HaloConst.SUFFIX_FTL)) {
return themeService.render(ThemeService.CUSTOM_SHEET_PREFIX + sheet.getTemplate());
}
return themeService.render("sheet");
}
Aggregations