mirror of https://github.com/halo-dev/halo
Refactor OPTIONS and remove it
parent
2b7753bccf
commit
a7af1e7f77
|
@ -0,0 +1,18 @@
|
|||
package cc.ryanc.halo.exception;
|
||||
|
||||
/**
|
||||
* Missing property value exception.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/22/19
|
||||
*/
|
||||
public class MissingPropertyValueException extends BadRequestException {
|
||||
|
||||
public MissingPropertyValueException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public MissingPropertyValueException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -25,7 +25,6 @@ import java.nio.charset.Charset;
|
|||
import java.util.List;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.DEFAULT_THEME_NAME;
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
|
@ -54,22 +53,12 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
@Override
|
||||
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||
// save halo version to database
|
||||
// TODO Complete cache option value
|
||||
this.cacheOptions();
|
||||
this.cacheThemes();
|
||||
this.cacheOwo();
|
||||
this.getActiveTheme();
|
||||
this.printStartInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache options to map
|
||||
*/
|
||||
private void cacheOptions() {
|
||||
OPTIONS.clear();
|
||||
OPTIONS.putAll(optionService.listOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache themes to map
|
||||
*/
|
||||
|
@ -115,7 +104,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
// Get server port
|
||||
String serverPort = applicationContext.getEnvironment().getProperty("server.port");
|
||||
|
||||
String blogUrl = OPTIONS.get(BlogProperties.BLOG_URL);
|
||||
String blogUrl = optionService.getByPropertyOfNullable(BlogProperties.BLOG_URL);
|
||||
|
||||
if (StrUtil.isNotBlank(blogUrl)) {
|
||||
blogUrl = StrUtil.removeSuffix(blogUrl, "/");
|
||||
|
|
|
@ -4,8 +4,6 @@ import cn.hutool.json.JSONObject;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
|
@ -33,12 +31,6 @@ public class HaloConst {
|
|||
*/
|
||||
public static final String TOKEN_HEADER = "token";
|
||||
|
||||
/**
|
||||
* All of the options
|
||||
*/
|
||||
@Deprecated
|
||||
public final static ConcurrentMap<String, String> OPTIONS = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* All of the Owo
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.exception.MissingPropertyValueException;
|
||||
import cc.ryanc.halo.model.dto.OptionOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Option;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
|
@ -24,6 +25,8 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
|
||||
int DEFAULT_COMMENT_PAGE_SIZE = 10;
|
||||
|
||||
int DEFAULT_RSS_PAGE_SIZE = 20;
|
||||
|
||||
/**
|
||||
* Save one option
|
||||
*
|
||||
|
@ -80,6 +83,15 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
@Nullable
|
||||
String getByKeyOfNullable(@NonNull String key);
|
||||
|
||||
/**
|
||||
* Gets option value of non null.
|
||||
*
|
||||
* @param key option key must not be null
|
||||
* @return option value of non null
|
||||
*/
|
||||
@NonNull
|
||||
String getByKeyOfNonNull(@NonNull String key);
|
||||
|
||||
/**
|
||||
* Get option by key
|
||||
*
|
||||
|
@ -90,7 +102,7 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
Optional<String> getByKey(@NonNull String key);
|
||||
|
||||
/**
|
||||
* Gets option by blog property.
|
||||
* Gets option value by blog property.
|
||||
*
|
||||
* @param property blog property must not be null
|
||||
* @return an option value
|
||||
|
@ -99,7 +111,17 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
String getByPropertyOfNullable(@NonNull BlogProperties property);
|
||||
|
||||
/**
|
||||
* Gets option by blog property.
|
||||
* Gets option value by blog property.
|
||||
*
|
||||
* @param property blog property
|
||||
* @return an optiona value
|
||||
* @throws MissingPropertyValueException throws when property value dismisses
|
||||
*/
|
||||
@NonNull
|
||||
String getByPropertyOfNonNull(@NonNull BlogProperties property);
|
||||
|
||||
/**
|
||||
* Gets option value by blog property.
|
||||
*
|
||||
* @param property blog property must not be null
|
||||
* @return an optional option value
|
||||
|
@ -121,6 +143,13 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
*/
|
||||
int getCommentPageSize();
|
||||
|
||||
/**
|
||||
* Gets rss page size.
|
||||
*
|
||||
* @return page size
|
||||
*/
|
||||
int getRssPageSize();
|
||||
|
||||
/**
|
||||
* Get quniu zone.
|
||||
*
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.service.impl;
|
|||
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.service.MailService;
|
||||
import cc.ryanc.halo.service.OptionService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import freemarker.template.Template;
|
||||
|
@ -13,8 +14,6 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
|||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019-03-17
|
||||
|
@ -24,8 +23,12 @@ public class MailServiceImpl implements MailService {
|
|||
|
||||
private final FreeMarkerConfigurer freeMarker;
|
||||
|
||||
public MailServiceImpl(FreeMarkerConfigurer freeMarker) {
|
||||
private final OptionService optionService;
|
||||
|
||||
public MailServiceImpl(FreeMarkerConfigurer freeMarker,
|
||||
OptionService optionService) {
|
||||
this.freeMarker = freeMarker;
|
||||
this.optionService = optionService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,12 +41,12 @@ public class MailServiceImpl implements MailService {
|
|||
@Override
|
||||
public void sendMail(String to, String subject, String content) {
|
||||
HaloUtils.configMail(
|
||||
OPTIONS.get(BlogProperties.MAIL_SMTP_HOST.getValue()),
|
||||
OPTIONS.get(BlogProperties.MAIL_SMTP_USERNAME.getValue()),
|
||||
OPTIONS.get(BlogProperties.MAIL_SMTP_PASSWORD.getValue()));
|
||||
optionService.getByPropertyOfNonNull(BlogProperties.MAIL_SMTP_HOST),
|
||||
optionService.getByPropertyOfNonNull(BlogProperties.MAIL_SMTP_USERNAME),
|
||||
optionService.getByPropertyOfNonNull(BlogProperties.MAIL_SMTP_PASSWORD));
|
||||
try {
|
||||
OhMyEmail.subject(subject)
|
||||
.from(OPTIONS.get(BlogProperties.MAIL_FROM_NAME.getValue()))
|
||||
.from(optionService.getByPropertyOfNonNull(BlogProperties.MAIL_FROM_NAME))
|
||||
.to(to)
|
||||
.text(content)
|
||||
.send();
|
||||
|
@ -64,15 +67,15 @@ public class MailServiceImpl implements MailService {
|
|||
@Override
|
||||
public void sendTemplateMail(String to, String subject, Map<String, Object> content, String templateName) {
|
||||
HaloUtils.configMail(
|
||||
OPTIONS.get(BlogProperties.MAIL_SMTP_HOST.getValue()),
|
||||
OPTIONS.get(BlogProperties.MAIL_SMTP_USERNAME.getValue()),
|
||||
OPTIONS.get(BlogProperties.MAIL_SMTP_PASSWORD.getValue()));
|
||||
optionService.getByPropertyOfNonNull(BlogProperties.MAIL_SMTP_HOST),
|
||||
optionService.getByPropertyOfNonNull(BlogProperties.MAIL_SMTP_USERNAME),
|
||||
optionService.getByPropertyOfNonNull(BlogProperties.MAIL_SMTP_PASSWORD));
|
||||
StrBuilder text = new StrBuilder();
|
||||
try {
|
||||
final Template template = freeMarker.getConfiguration().getTemplate(templateName);
|
||||
text.append(FreeMarkerTemplateUtils.processTemplateIntoString(template, content));
|
||||
OhMyEmail.subject(subject)
|
||||
.from(OPTIONS.get(BlogProperties.MAIL_FROM_NAME.getValue()))
|
||||
.from(optionService.getByPropertyOfNonNull(BlogProperties.MAIL_FROM_NAME))
|
||||
.to(to)
|
||||
.html(text.toString())
|
||||
.send();
|
||||
|
@ -94,16 +97,16 @@ public class MailServiceImpl implements MailService {
|
|||
@Override
|
||||
public void sendAttachMail(String to, String subject, Map<String, Object> content, String templateName, String attachSrc) {
|
||||
HaloUtils.configMail(
|
||||
OPTIONS.get(BlogProperties.MAIL_SMTP_HOST.getValue()),
|
||||
OPTIONS.get(BlogProperties.MAIL_SMTP_USERNAME.getValue()),
|
||||
OPTIONS.get(BlogProperties.MAIL_SMTP_PASSWORD.getValue()));
|
||||
optionService.getByPropertyOfNonNull(BlogProperties.MAIL_SMTP_HOST),
|
||||
optionService.getByPropertyOfNonNull(BlogProperties.MAIL_SMTP_USERNAME),
|
||||
optionService.getByPropertyOfNonNull(BlogProperties.MAIL_SMTP_PASSWORD));
|
||||
File file = new File(attachSrc);
|
||||
StrBuilder text = new StrBuilder();
|
||||
try {
|
||||
final Template template = freeMarker.getConfiguration().getTemplate(templateName);
|
||||
text.append(FreeMarkerTemplateUtils.processTemplateIntoString(template, content));
|
||||
OhMyEmail.subject(subject)
|
||||
.from(OPTIONS.get(BlogProperties.MAIL_FROM_NAME.getValue()))
|
||||
.from(optionService.getByPropertyOfNonNull(BlogProperties.MAIL_FROM_NAME))
|
||||
.to(to)
|
||||
.html(text.toString())
|
||||
.attach(file, file.getName())
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.exception.MissingPropertyValueException;
|
||||
import cc.ryanc.halo.model.dto.OptionOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Option;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
|
@ -133,6 +134,11 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
return getByKey(key).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getByKeyOfNonNull(String key) {
|
||||
return getByKey(key).orElseThrow(() -> new MissingPropertyValueException("You have to config " + key + " setting"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getByKey(String key) {
|
||||
Assert.hasText(key, "Option key must not be blank");
|
||||
|
@ -145,6 +151,13 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
return getByProperty(property).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getByPropertyOfNonNull(BlogProperties property) {
|
||||
Assert.notNull(property, "Blog property must not be null");
|
||||
|
||||
return getByKeyOfNonNull(property.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getByProperty(BlogProperties property) {
|
||||
Assert.notNull(property, "Blog property must not be null");
|
||||
|
@ -157,7 +170,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
try {
|
||||
return getByProperty(BlogProperties.INDEX_POSTS).map(Integer::valueOf).orElse(DEFAULT_POST_PAGE_SIZE);
|
||||
} catch (NumberFormatException e) {
|
||||
log.error(BlogProperties.INDEX_POSTS + " option was not a number format", e);
|
||||
log.error(BlogProperties.INDEX_POSTS + " option is not a number format", e);
|
||||
return DEFAULT_POST_PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
@ -167,11 +180,21 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
try {
|
||||
return getByProperty(BlogProperties.INDEX_COMMENTS).map(Integer::valueOf).orElse(DEFAULT_COMMENT_PAGE_SIZE);
|
||||
} catch (NumberFormatException e) {
|
||||
log.error(BlogProperties.INDEX_COMMENTS + " option was not a number format", e);
|
||||
log.error(BlogProperties.INDEX_COMMENTS + " option is not a number format", e);
|
||||
return DEFAULT_COMMENT_PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRssPageSize() {
|
||||
try {
|
||||
return getByProperty(BlogProperties.RSS_POSTS).map(Integer::valueOf).orElse(DEFAULT_RSS_PAGE_SIZE);
|
||||
} catch (NumberFormatException e) {
|
||||
log.error(BlogProperties.RSS_POSTS + " setting is not a number format", e);
|
||||
return DEFAULT_RSS_PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Zone getQiniuZone() {
|
||||
return getByProperty(BlogProperties.QINIU_ZONE).map(qiniuZone -> {
|
||||
|
|
|
@ -36,8 +36,6 @@ import java.util.Properties;
|
|||
@Slf4j
|
||||
public class HaloUtils {
|
||||
|
||||
public final static int DEFAULT_PAGE_SIZE = 10;
|
||||
|
||||
/**
|
||||
* Initialize url if blank.
|
||||
*
|
||||
|
|
|
@ -17,8 +17,6 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019/3/20
|
||||
|
@ -59,11 +57,9 @@ public class ThemeController {
|
|||
public void active(@RequestParam(name = "themeName", defaultValue = "anatole") String themeName) throws TemplateModelException {
|
||||
Map<BlogProperties, String> properties = new HashMap<>(1);
|
||||
properties.put(BlogProperties.THEME, themeName);
|
||||
optionService.saveProperties(properties,"system");
|
||||
optionService.saveProperties(properties, "system");
|
||||
BaseContentController.THEME = themeName;
|
||||
OPTIONS.clear();
|
||||
OPTIONS.putAll(optionService.listOptions());
|
||||
configuration.setSharedVariable("themeName", themeName);
|
||||
configuration.setSharedVariable("options", OPTIONS);
|
||||
configuration.setSharedVariable("options", optionService.listOptions());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import freemarker.template.Configuration;
|
|||
import freemarker.template.TemplateModelException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
import static cc.ryanc.halo.model.support.HaloConst.THEMES;
|
||||
|
||||
/**
|
||||
|
@ -28,11 +27,9 @@ public abstract class BaseController {
|
|||
*/
|
||||
public void refreshCache() {
|
||||
try {
|
||||
OPTIONS.clear();
|
||||
THEMES.clear();
|
||||
OPTIONS.putAll(optionService.listOptions());
|
||||
THEMES = ThemeUtils.getThemes();
|
||||
configuration.setSharedVariable("options", OPTIONS);
|
||||
configuration.setSharedVariable("options", optionService.listOptions());
|
||||
} catch (TemplateModelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cc.ryanc.halo.web.controller.content;
|
||||
|
||||
import cc.ryanc.halo.model.entity.Post;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.PostStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.service.OptionService;
|
||||
|
@ -23,8 +22,6 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019-03-21
|
||||
|
@ -57,12 +54,9 @@ public class ContentFeedController {
|
|||
@GetMapping(value = {"feed", "feed.xml", "rss", "rss.xml"}, produces = "application/xml;charset=UTF-8")
|
||||
@ResponseBody
|
||||
public String feed(Model model) throws IOException, TemplateException {
|
||||
String rssPosts = OPTIONS.get(BlogProperties.RSS_POSTS.getValue());
|
||||
if (StrUtil.isBlank(rssPosts)) {
|
||||
rssPosts = "20";
|
||||
}
|
||||
int rssPageSize = optionService.getRssPageSize();
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
final Pageable pageable = PageRequest.of(0, Integer.parseInt(rssPosts), sort);
|
||||
final Pageable pageable = PageRequest.of(0, rssPageSize, sort);
|
||||
model.addAttribute("posts", buildPosts(pageable));
|
||||
final Template template = freeMarker.getConfiguration().getTemplate("common/web/rss.ftl");
|
||||
return FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
|
||||
|
|
|
@ -4,33 +4,26 @@ import cc.ryanc.halo.exception.BadRequestException;
|
|||
import cc.ryanc.halo.model.entity.*;
|
||||
import cc.ryanc.halo.model.enums.AttachOrigin;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.CommentStatus;
|
||||
import cc.ryanc.halo.model.enums.PostStatus;
|
||||
import cc.ryanc.halo.model.params.InstallParam;
|
||||
import cc.ryanc.halo.model.support.BaseResponse;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.service.*;
|
||||
import cc.ryanc.halo.utils.MarkdownUtils;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import freemarker.template.Configuration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.DEFAULT_THEME_NAME;
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
|
||||
/**
|
||||
* Installation controller.
|
||||
|
@ -82,7 +75,7 @@ public class InstallController {
|
|||
@GetMapping
|
||||
public String install(Model model) {
|
||||
try {
|
||||
if (StrUtil.equals("true", OPTIONS.get("is_install"))) {
|
||||
if (StrUtil.equals(Boolean.TRUE.toString(), optionService.getByProperty(BlogProperties.IS_INSTALL).orElse(Boolean.FALSE.toString()))) {
|
||||
model.addAttribute("isInstall", true);
|
||||
} else {
|
||||
model.addAttribute("isInstall", false);
|
||||
|
@ -98,7 +91,7 @@ public class InstallController {
|
|||
public BaseResponse<?> installBlog(@Valid InstallParam installParam) {
|
||||
// TODO Install blog.
|
||||
// Check is installed
|
||||
boolean isInstalled = Boolean.parseBoolean(OPTIONS.getOrDefault(BlogProperties.IS_INSTALL, "false"));
|
||||
boolean isInstalled = Boolean.parseBoolean(optionService.getByProperty(BlogProperties.IS_INSTALL).orElse(Boolean.FALSE.toString()));
|
||||
|
||||
if (isInstalled) {
|
||||
throw new BadRequestException("该博客已初始化,不能再次安装!");
|
||||
|
@ -191,117 +184,117 @@ public class InstallController {
|
|||
properties.put(BlogProperties.ATTACH_LOC, AttachOrigin.SERVER.getValue().toString());
|
||||
|
||||
// Create properties
|
||||
optionService.saveProperties(properties,"system");
|
||||
optionService.saveProperties(properties, "system");
|
||||
}
|
||||
|
||||
/**
|
||||
* Do install
|
||||
*
|
||||
* @param blogLocale language
|
||||
* @param blogTitle blog title
|
||||
* @param blogUrl blog url
|
||||
* @param userName user name
|
||||
* @param nickName nick name
|
||||
* @param userEmail user email
|
||||
* @param userPwd user password
|
||||
* @param request request
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/do")
|
||||
@ResponseBody
|
||||
@Deprecated
|
||||
public JsonResult doInstall(@RequestParam("blogLocale") String blogLocale,
|
||||
@RequestParam("blogTitle") String blogTitle,
|
||||
@RequestParam("blogUrl") String blogUrl,
|
||||
@RequestParam("userName") String userName,
|
||||
@RequestParam("userDisplayName") String nickName,
|
||||
@RequestParam("userEmail") String userEmail,
|
||||
@RequestParam("userPwd") String userPwd,
|
||||
HttpServletRequest request) {
|
||||
try {
|
||||
if (StrUtil.equals("true", OPTIONS.get("is_install"))) {
|
||||
return new JsonResult(0, "该博客已初始化,不能再次安装!");
|
||||
}
|
||||
// Create new user
|
||||
final User user = new User();
|
||||
user.setUsername(userName);
|
||||
user.setNickname(StrUtil.isBlank(nickName) ? userName : nickName);
|
||||
user.setEmail(userEmail);
|
||||
user.setPassword(SecureUtil.md5(userPwd));
|
||||
userService.create(user);
|
||||
|
||||
//默认分类
|
||||
Category category = new Category();
|
||||
category.setName("未分类");
|
||||
category.setSlugName("default");
|
||||
category.setDescription("未分类");
|
||||
category = categoryService.create(category);
|
||||
|
||||
//第一篇文章
|
||||
final Post post = new Post();
|
||||
final List<Category> categories = new ArrayList<>(1);
|
||||
categories.add(category);
|
||||
post.setTitle("Hello Halo!");
|
||||
post.setOriginalContent("# Hello Halo!\n" +
|
||||
"欢迎使用Halo进行创作,删除这篇文章后赶紧开始吧。");
|
||||
post.setFormatContent(MarkdownUtils.renderMarkdown(post.getOriginalContent()));
|
||||
post.setSummary("欢迎使用Halo进行创作,删除这篇文章后赶紧开始吧。");
|
||||
post.setStatus(PostStatus.PUBLISHED);
|
||||
post.setUrl("hello-halo");
|
||||
post.setDisallowComment(true);
|
||||
post.setThumbnail("/static/halo-frontend/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 11) + ".jpg");
|
||||
postService.create(post);
|
||||
|
||||
//第一个评论
|
||||
final Comment comment = new Comment();
|
||||
comment.setAuthor("ruibaby");
|
||||
comment.setEmail("i@ryanc.cc");
|
||||
comment.setAuthorUrl("https://ryanc.cc");
|
||||
comment.setIpAddress("127.0.0.1");
|
||||
comment.setGavatarMd5(SecureUtil.md5("i@ryanc.cc"));
|
||||
comment.setContent("欢迎,欢迎!");
|
||||
comment.setStatus(CommentStatus.PUBLISHED);
|
||||
comment.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36");
|
||||
comment.setIsAdmin(false);
|
||||
commentService.create(comment);
|
||||
|
||||
final Map<BlogProperties, Object> options = new HashMap<>();
|
||||
// options.put(BlogProperties.IS_INSTALL, TrueFalseEnum.TRUE.getDesc());
|
||||
// options.put(BlogProperties.BLOG_LOCALE, blogLocale);
|
||||
// options.put(BlogProperties.BLOG_TITLE, blogTitle);
|
||||
// options.put(BlogProperties.BLOG_URL, blogUrl);
|
||||
// options.put(BlogProperties.THEME, "anatole");
|
||||
// options.put(BlogProperties.BLOG_START, DateUtil.format(DateUtil.date(), "yyyy-MM-dd"));
|
||||
// options.put(BlogProperties.SMTP_EMAIL_ENABLE, TrueFalseEnum.FALSE.getDesc());
|
||||
// options.put(BlogProperties.NEW_COMMENT_NOTICE, TrueFalseEnum.FALSE.getDesc());
|
||||
// options.put(BlogProperties.COMMENT_PASS_NOTICE, TrueFalseEnum.FALSE.getDesc());
|
||||
// options.put(BlogProperties.COMMENT_REPLY_NOTICE, TrueFalseEnum.FALSE.getDesc());
|
||||
// options.put(BlogProperties.ATTACH_LOC, AttachLocationEnum.SERVER.getDesc());
|
||||
// optionService.saveOptions(options);
|
||||
|
||||
//更新日志
|
||||
// logsService.save(LogsRecord.INSTALL, "安装成功,欢迎使用Halo。", request);
|
||||
|
||||
final Menu menuIndex = new Menu();
|
||||
menuIndex.setName("首页");
|
||||
menuIndex.setUrl("/");
|
||||
menuIndex.setSort(1);
|
||||
menuService.create(menuIndex);
|
||||
|
||||
final Menu menuArchive = new Menu();
|
||||
menuArchive.setName("归档");
|
||||
menuArchive.setUrl("/archives");
|
||||
menuArchive.setSort(2);
|
||||
menuService.create(menuArchive);
|
||||
|
||||
OPTIONS.clear();
|
||||
OPTIONS.putAll(optionService.listOptions());
|
||||
configuration.setSharedVariable("options", OPTIONS);
|
||||
// configuration.setSharedVariable("user", userService.findUser());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return new JsonResult(0, e.getMessage());
|
||||
}
|
||||
return new JsonResult(1, "安装成功!");
|
||||
}
|
||||
// /**
|
||||
// * Do install
|
||||
// *
|
||||
// * @param blogLocale language
|
||||
// * @param blogTitle blog title
|
||||
// * @param blogUrl blog url
|
||||
// * @param userName user name
|
||||
// * @param nickName nick name
|
||||
// * @param userEmail user email
|
||||
// * @param userPwd user password
|
||||
// * @param request request
|
||||
// * @return JsonResult
|
||||
// */
|
||||
// @PostMapping(value = "/do")
|
||||
// @ResponseBody
|
||||
// @Deprecated
|
||||
// public JsonResult doInstall(@RequestParam("blogLocale") String blogLocale,
|
||||
// @RequestParam("blogTitle") String blogTitle,
|
||||
// @RequestParam("blogUrl") String blogUrl,
|
||||
// @RequestParam("userName") String userName,
|
||||
// @RequestParam("userDisplayName") String nickName,
|
||||
// @RequestParam("userEmail") String userEmail,
|
||||
// @RequestParam("userPwd") String userPwd,
|
||||
// HttpServletRequest request) {
|
||||
// try {
|
||||
// if (StrUtil.equals("true", OPTIONS.get("is_install"))) {
|
||||
// return new JsonResult(0, "该博客已初始化,不能再次安装!");
|
||||
// }
|
||||
// // Create new user
|
||||
// final User user = new User();
|
||||
// user.setUsername(userName);
|
||||
// user.setNickname(StrUtil.isBlank(nickName) ? userName : nickName);
|
||||
// user.setEmail(userEmail);
|
||||
// user.setPassword(SecureUtil.md5(userPwd));
|
||||
// userService.create(user);
|
||||
//
|
||||
// //默认分类
|
||||
// Category category = new Category();
|
||||
// category.setName("未分类");
|
||||
// category.setSlugName("default");
|
||||
// category.setDescription("未分类");
|
||||
// category = categoryService.create(category);
|
||||
//
|
||||
// //第一篇文章
|
||||
// final Post post = new Post();
|
||||
// final List<Category> categories = new ArrayList<>(1);
|
||||
// categories.add(category);
|
||||
// post.setTitle("Hello Halo!");
|
||||
// post.setOriginalContent("# Hello Halo!\n" +
|
||||
// "欢迎使用Halo进行创作,删除这篇文章后赶紧开始吧。");
|
||||
// post.setFormatContent(MarkdownUtils.renderMarkdown(post.getOriginalContent()));
|
||||
// post.setSummary("欢迎使用Halo进行创作,删除这篇文章后赶紧开始吧。");
|
||||
// post.setStatus(PostStatus.PUBLISHED);
|
||||
// post.setUrl("hello-halo");
|
||||
// post.setDisallowComment(true);
|
||||
// post.setThumbnail("/static/halo-frontend/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 11) + ".jpg");
|
||||
// postService.create(post);
|
||||
//
|
||||
// //第一个评论
|
||||
// final Comment comment = new Comment();
|
||||
// comment.setAuthor("ruibaby");
|
||||
// comment.setEmail("i@ryanc.cc");
|
||||
// comment.setAuthorUrl("https://ryanc.cc");
|
||||
// comment.setIpAddress("127.0.0.1");
|
||||
// comment.setGavatarMd5(SecureUtil.md5("i@ryanc.cc"));
|
||||
// comment.setContent("欢迎,欢迎!");
|
||||
// comment.setStatus(CommentStatus.PUBLISHED);
|
||||
// comment.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36");
|
||||
// comment.setIsAdmin(false);
|
||||
// commentService.create(comment);
|
||||
//
|
||||
// final Map<BlogProperties, Object> options = new HashMap<>();
|
||||
//// options.put(BlogProperties.IS_INSTALL, TrueFalseEnum.TRUE.getDesc());
|
||||
//// options.put(BlogProperties.BLOG_LOCALE, blogLocale);
|
||||
//// options.put(BlogProperties.BLOG_TITLE, blogTitle);
|
||||
//// options.put(BlogProperties.BLOG_URL, blogUrl);
|
||||
//// options.put(BlogProperties.THEME, "anatole");
|
||||
//// options.put(BlogProperties.BLOG_START, DateUtil.format(DateUtil.date(), "yyyy-MM-dd"));
|
||||
//// options.put(BlogProperties.SMTP_EMAIL_ENABLE, TrueFalseEnum.FALSE.getDesc());
|
||||
//// options.put(BlogProperties.NEW_COMMENT_NOTICE, TrueFalseEnum.FALSE.getDesc());
|
||||
//// options.put(BlogProperties.COMMENT_PASS_NOTICE, TrueFalseEnum.FALSE.getDesc());
|
||||
//// options.put(BlogProperties.COMMENT_REPLY_NOTICE, TrueFalseEnum.FALSE.getDesc());
|
||||
//// options.put(BlogProperties.ATTACH_LOC, AttachLocationEnum.SERVER.getDesc());
|
||||
//// optionService.saveOptions(options);
|
||||
//
|
||||
// //更新日志
|
||||
//// logsService.save(LogsRecord.INSTALL, "安装成功,欢迎使用Halo。", request);
|
||||
//
|
||||
// final Menu menuIndex = new Menu();
|
||||
// menuIndex.setName("首页");
|
||||
// menuIndex.setUrl("/");
|
||||
// menuIndex.setSort(1);
|
||||
// menuService.create(menuIndex);
|
||||
//
|
||||
// final Menu menuArchive = new Menu();
|
||||
// menuArchive.setName("归档");
|
||||
// menuArchive.setUrl("/archives");
|
||||
// menuArchive.setSort(2);
|
||||
// menuService.create(menuArchive);
|
||||
//
|
||||
// OPTIONS.clear();
|
||||
// OPTIONS.putAll(optionService.listOptions());
|
||||
// configuration.setSharedVariable("options", OPTIONS);
|
||||
//// configuration.setSharedVariable("user", userService.findUser());
|
||||
// } catch (Exception e) {
|
||||
// log.error(e.getMessage());
|
||||
// return new JsonResult(0, e.getMessage());
|
||||
// }
|
||||
// return new JsonResult(1, "安装成功!");
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package cc.ryanc.halo.utils;
|
||||
|
||||
/**
|
||||
* Reflection utils test.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
public class ReflectionUtilsTest {
|
||||
|
||||
}
|
Loading…
Reference in New Issue