mirror of https://github.com/halo-dev/halo
Refactor option service
parent
aabc665ba0
commit
26c0192517
|
@ -79,7 +79,7 @@ public class InstallController {
|
||||||
public BaseResponse<String> installBlog(@RequestBody @Valid InstallParam installParam) {
|
public BaseResponse<String> installBlog(@RequestBody @Valid InstallParam installParam) {
|
||||||
// TODO Install blog.
|
// TODO Install blog.
|
||||||
// Check is installed
|
// Check is installed
|
||||||
boolean isInstalled = Boolean.parseBoolean(optionService.getByProperty(PrimaryProperties.IS_INSTALLED).orElse(Boolean.FALSE.toString()));
|
boolean isInstalled = optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false);
|
||||||
|
|
||||||
if (isInstalled) {
|
if (isInstalled) {
|
||||||
// TODO i18n
|
// TODO i18n
|
||||||
|
@ -172,7 +172,7 @@ public class InstallController {
|
||||||
properties.put(CommentProperties.NEW_NOTICE, Boolean.FALSE.toString());
|
properties.put(CommentProperties.NEW_NOTICE, Boolean.FALSE.toString());
|
||||||
properties.put(CommentProperties.PASS_NOTICE, Boolean.FALSE.toString());
|
properties.put(CommentProperties.PASS_NOTICE, Boolean.FALSE.toString());
|
||||||
properties.put(CommentProperties.REPLY_NOTICE, Boolean.FALSE.toString());
|
properties.put(CommentProperties.REPLY_NOTICE, Boolean.FALSE.toString());
|
||||||
properties.put(AttachmentProperties.ATTACHMENT_TYPE, AttachmentType.LOCAL.getValue().toString());
|
properties.put(AttachmentProperties.ATTACHMENT_TYPE, AttachmentType.LOCAL.name());
|
||||||
|
|
||||||
// Create properties
|
// Create properties
|
||||||
optionService.saveProperties(properties);
|
optionService.saveProperties(properties);
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
package run.halo.app.controller.content.api;
|
package run.halo.app.controller.content.api;
|
||||||
|
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
import run.halo.app.model.dto.OptionDTO;
|
import run.halo.app.model.dto.OptionDTO;
|
||||||
import run.halo.app.model.support.BaseResponse;
|
import run.halo.app.model.support.BaseResponse;
|
||||||
import run.halo.app.service.OptionService;
|
import run.halo.app.service.OptionService;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -36,14 +34,18 @@ public class OptionController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("map_view")
|
@GetMapping("map_view")
|
||||||
@ApiOperation("Lists all options with map view")
|
@ApiOperation("Lists options with map view")
|
||||||
public Map<String, Object> listAllWithMapView() {
|
public Map<String, Object> listAllWithMapView(@RequestParam(value = "key", required = false) List<String> keys) {
|
||||||
return optionService.listOptions();
|
if (CollectionUtils.isEmpty(keys)) {
|
||||||
|
return optionService.listOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
return optionService.listOptions(keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("keys/{key}")
|
@GetMapping("keys/{key}")
|
||||||
@ApiOperation("Gets option value by option key")
|
@ApiOperation("Gets option value by option key")
|
||||||
public BaseResponse<String> getBy(@PathVariable("key") String key) {
|
public BaseResponse<Object> getBy(@PathVariable("key") String key) {
|
||||||
return BaseResponse.ok(HttpStatus.OK.getReasonPhrase(), optionService.getByKey(key).orElse(""));
|
return BaseResponse.ok(HttpStatus.OK.getReasonPhrase(), optionService.getByKey(key).orElse(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class CommentEventListener {
|
||||||
|
|
||||||
Map<String, Object> data = new HashMap<>();
|
Map<String, Object> data = new HashMap<>();
|
||||||
|
|
||||||
StrBuilder url = new StrBuilder(optionService.getByPropertyOfNullable(BlogProperties.BLOG_URL))
|
StrBuilder url = new StrBuilder(optionService.getByPropertyOfNullable(BlogProperties.BLOG_URL).toString())
|
||||||
.append("/archives/")
|
.append("/archives/")
|
||||||
.append(post.getUrl());
|
.append(post.getUrl());
|
||||||
data.put("url", url.toString());
|
data.put("url", url.toString());
|
||||||
|
|
|
@ -41,10 +41,10 @@ public class AliYunFileHandler implements FileHandler {
|
||||||
Assert.notNull(file, "Multipart file must not be null");
|
Assert.notNull(file, "Multipart file must not be null");
|
||||||
|
|
||||||
// Get config
|
// Get config
|
||||||
String ossEndPoint = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ENDPOINT);
|
String ossEndPoint = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ENDPOINT).toString();
|
||||||
String ossAccessKey = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_KEY);
|
String ossAccessKey = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_KEY).toString();
|
||||||
String ossAccessSecret = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_SECRET);
|
String ossAccessSecret = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_SECRET).toString();
|
||||||
String ossBucketName = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_BUCKET_NAME);
|
String ossBucketName = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_BUCKET_NAME).toString();
|
||||||
String ossSource = StringUtils.join("https://", ossBucketName, "." + ossEndPoint);
|
String ossSource = StringUtils.join("https://", ossBucketName, "." + ossEndPoint);
|
||||||
|
|
||||||
// Init OSS client
|
// Init OSS client
|
||||||
|
@ -100,10 +100,10 @@ public class AliYunFileHandler implements FileHandler {
|
||||||
Assert.notNull(key, "File key must not be blank");
|
Assert.notNull(key, "File key must not be blank");
|
||||||
|
|
||||||
// Get config
|
// Get config
|
||||||
String ossEndPoint = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ENDPOINT);
|
String ossEndPoint = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ENDPOINT).toString();
|
||||||
String ossAccessKey = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_KEY);
|
String ossAccessKey = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_KEY).toString();
|
||||||
String ossAccessSecret = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_SECRET);
|
String ossAccessSecret = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_SECRET).toString();
|
||||||
String ossBucketName = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_BUCKET_NAME);
|
String ossBucketName = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_BUCKET_NAME).toString();
|
||||||
String ossSource = StringUtils.join("https://", ossBucketName, "." + ossEndPoint);
|
String ossSource = StringUtils.join("https://", ossBucketName, "." + ossEndPoint);
|
||||||
|
|
||||||
// Init OSS client
|
// Init OSS client
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
package run.halo.app.handler.file;
|
package run.halo.app.handler.file;
|
||||||
|
|
||||||
import run.halo.app.exception.FileOperationException;
|
|
||||||
import run.halo.app.model.enums.AttachmentType;
|
|
||||||
import run.halo.app.model.properties.QnYunProperties;
|
|
||||||
import run.halo.app.model.support.QiNiuPutSet;
|
|
||||||
import run.halo.app.model.support.UploadResult;
|
|
||||||
import run.halo.app.service.OptionService;
|
|
||||||
import run.halo.app.utils.FilenameUtils;
|
|
||||||
import run.halo.app.utils.JsonUtils;
|
|
||||||
import com.qiniu.common.QiniuException;
|
import com.qiniu.common.QiniuException;
|
||||||
import com.qiniu.common.Zone;
|
import com.qiniu.common.Zone;
|
||||||
import com.qiniu.http.Response;
|
import com.qiniu.http.Response;
|
||||||
|
@ -23,6 +15,14 @@ import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import run.halo.app.exception.FileOperationException;
|
||||||
|
import run.halo.app.model.enums.AttachmentType;
|
||||||
|
import run.halo.app.model.properties.QnYunProperties;
|
||||||
|
import run.halo.app.model.support.QiNiuPutSet;
|
||||||
|
import run.halo.app.model.support.UploadResult;
|
||||||
|
import run.halo.app.service.OptionService;
|
||||||
|
import run.halo.app.utils.FilenameUtils;
|
||||||
|
import run.halo.app.utils.JsonUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -53,11 +53,11 @@ public class QnYunFileHandler implements FileHandler {
|
||||||
|
|
||||||
// Get all config
|
// Get all config
|
||||||
Zone zone = optionService.getQnYunZone();
|
Zone zone = optionService.getQnYunZone();
|
||||||
String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.ACCESS_KEY);
|
String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.ACCESS_KEY).toString();
|
||||||
String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY);
|
String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY).toString();
|
||||||
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET);
|
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET).toString();
|
||||||
String domain = optionService.getByPropertyOfNonNull(QnYunProperties.DOMAIN);
|
String domain = optionService.getByPropertyOfNonNull(QnYunProperties.DOMAIN).toString();
|
||||||
String smallUrl = optionService.getByPropertyOfNullable(QnYunProperties.SMALL_URL);
|
String smallUrl = optionService.getByPropertyOrDefault(QnYunProperties.SMALL_URL, String.class, "");
|
||||||
|
|
||||||
// TODO Consider to cache the configuration
|
// TODO Consider to cache the configuration
|
||||||
// Create configuration
|
// Create configuration
|
||||||
|
@ -132,9 +132,9 @@ public class QnYunFileHandler implements FileHandler {
|
||||||
|
|
||||||
// Get all config
|
// Get all config
|
||||||
Zone zone = optionService.getQnYunZone();
|
Zone zone = optionService.getQnYunZone();
|
||||||
String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.ACCESS_KEY);
|
String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.ACCESS_KEY).toString();
|
||||||
String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY);
|
String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY).toString();
|
||||||
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET);
|
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET).toString();
|
||||||
|
|
||||||
// TODO Consider to cache the configuration
|
// TODO Consider to cache the configuration
|
||||||
// Create configuration
|
// Create configuration
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
package run.halo.app.handler.file;
|
package run.halo.app.handler.file;
|
||||||
|
|
||||||
import run.halo.app.exception.FileOperationException;
|
|
||||||
import run.halo.app.model.enums.AttachmentType;
|
|
||||||
import run.halo.app.model.properties.UpYunProperties;
|
|
||||||
import run.halo.app.model.support.UploadResult;
|
|
||||||
import run.halo.app.service.OptionService;
|
|
||||||
import run.halo.app.utils.FilenameUtils;
|
|
||||||
import com.UpYun;
|
import com.UpYun;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -14,6 +8,12 @@ import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.DigestUtils;
|
import org.springframework.util.DigestUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import run.halo.app.exception.FileOperationException;
|
||||||
|
import run.halo.app.model.enums.AttachmentType;
|
||||||
|
import run.halo.app.model.properties.UpYunProperties;
|
||||||
|
import run.halo.app.model.support.UploadResult;
|
||||||
|
import run.halo.app.service.OptionService;
|
||||||
|
import run.halo.app.utils.FilenameUtils;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
@ -39,13 +39,13 @@ public class UpYunFileHandler implements FileHandler {
|
||||||
public UploadResult upload(MultipartFile file) {
|
public UploadResult upload(MultipartFile file) {
|
||||||
Assert.notNull(file, "Multipart file must not be null");
|
Assert.notNull(file, "Multipart file must not be null");
|
||||||
|
|
||||||
String ossSource = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_SOURCE);
|
String ossSource = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_SOURCE).toString();
|
||||||
String ossPassword = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_PASSWORD);
|
String ossPassword = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_PASSWORD).toString();
|
||||||
String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET);
|
String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET).toString();
|
||||||
String ossDomain = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_DOMAIN);
|
String ossDomain = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_DOMAIN).toString();
|
||||||
String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR);
|
String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR).toString();
|
||||||
// small url can be null
|
// small url can be null
|
||||||
String ossSmallUrl = optionService.getByPropertyOfNullable(UpYunProperties.OSS_SMALL_URL);
|
String ossSmallUrl = optionService.getByPropertyOrDefault(UpYunProperties.OSS_SMALL_URL, String.class, "");
|
||||||
|
|
||||||
// Create up yun
|
// Create up yun
|
||||||
UpYun upYun = new UpYun(ossBucket, ossOperator, ossPassword);
|
UpYun upYun = new UpYun(ossBucket, ossOperator, ossPassword);
|
||||||
|
@ -101,10 +101,10 @@ public class UpYunFileHandler implements FileHandler {
|
||||||
Assert.notNull(key, "File key must not be blank");
|
Assert.notNull(key, "File key must not be blank");
|
||||||
|
|
||||||
// Get config
|
// Get config
|
||||||
String ossSource = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_SOURCE);
|
String ossSource = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_SOURCE).toString();
|
||||||
String ossPassword = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_PASSWORD);
|
String ossPassword = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_PASSWORD).toString();
|
||||||
String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET);
|
String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET).toString();
|
||||||
String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR);
|
String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR).toString();
|
||||||
|
|
||||||
// Create up yun
|
// Create up yun
|
||||||
UpYun upYun = new UpYun(ossBucket, ossOperator, ossPassword);
|
UpYun upYun = new UpYun(ossBucket, ossOperator, ossPassword);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package run.halo.app.model.dto;
|
package run.halo.app.model.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import run.halo.app.model.dto.base.OutputConverter;
|
import run.halo.app.model.dto.base.OutputConverter;
|
||||||
import run.halo.app.model.entity.Option;
|
import run.halo.app.model.entity.Option;
|
||||||
|
|
||||||
|
@ -11,10 +13,12 @@ import run.halo.app.model.entity.Option;
|
||||||
* @date 3/20/19
|
* @date 3/20/19
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class OptionDTO implements OutputConverter<OptionDTO, Option> {
|
public class OptionDTO implements OutputConverter<OptionDTO, Option> {
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
|
|
||||||
private String value;
|
private Object value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ public interface OptionService extends CrudService<Option, Integer> {
|
||||||
* @return option value or null
|
* @return option value or null
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
String getByKeyOfNullable(@NonNull String key);
|
Object getByKeyOfNullable(@NonNull String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets option value of non null.
|
* Gets option value of non null.
|
||||||
|
@ -110,7 +110,7 @@ public interface OptionService extends CrudService<Option, Integer> {
|
||||||
* @return option value of non null
|
* @return option value of non null
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
String getByKeyOfNonNull(@NonNull String key);
|
Object getByKeyOfNonNull(@NonNull String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get option by key
|
* Get option by key
|
||||||
|
@ -119,7 +119,7 @@ public interface OptionService extends CrudService<Option, Integer> {
|
||||||
* @return an optional option value
|
* @return an optional option value
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Optional<String> getByKey(@NonNull String key);
|
Optional<Object> getByKey(@NonNull String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets option value by blog property.
|
* Gets option value by blog property.
|
||||||
|
@ -128,7 +128,7 @@ public interface OptionService extends CrudService<Option, Integer> {
|
||||||
* @return an option value
|
* @return an option value
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
String getByPropertyOfNullable(@NonNull PropertyEnum property);
|
Object getByPropertyOfNullable(@NonNull PropertyEnum property);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets option value by blog property.
|
* Gets option value by blog property.
|
||||||
|
@ -138,7 +138,7 @@ public interface OptionService extends CrudService<Option, Integer> {
|
||||||
* @throws MissingPropertyException throws when property value dismisses
|
* @throws MissingPropertyException throws when property value dismisses
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
String getByPropertyOfNonNull(@NonNull PropertyEnum property);
|
Object getByPropertyOfNonNull(@NonNull PropertyEnum property);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets option value by blog property.
|
* Gets option value by blog property.
|
||||||
|
@ -147,7 +147,7 @@ public interface OptionService extends CrudService<Option, Integer> {
|
||||||
* @return an optional option value
|
* @return an optional option value
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Optional<String> getByProperty(@NonNull PropertyEnum property);
|
Optional<Object> getByProperty(@NonNull PropertyEnum property);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets property value by blog property.
|
* Gets property value by blog property.
|
||||||
|
|
|
@ -256,7 +256,7 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
|
||||||
User user = authentication.getDetail().getUser();
|
User user = authentication.getDetail().getUser();
|
||||||
commentParam.setAuthor(StringUtils.isBlank(user.getNickname()) ? user.getUsername() : user.getNickname());
|
commentParam.setAuthor(StringUtils.isBlank(user.getNickname()) ? user.getUsername() : user.getNickname());
|
||||||
commentParam.setEmail(user.getEmail());
|
commentParam.setEmail(user.getEmail());
|
||||||
commentParam.setAuthorUrl(optionService.getByPropertyOfNullable(BlogProperties.BLOG_URL));
|
commentParam.setAuthorUrl(optionService.getByPropertyOrDefault(BlogProperties.BLOG_URL, String.class, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the comment param manually
|
// Validate the comment param manually
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class MailServiceImpl implements MailService {
|
||||||
public void sendMail(String to, String subject, String content) {
|
public void sendMail(String to, String subject, String content) {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
String fromUsername = optionService.getByPropertyOfNonNull(EmailProperties.FROM_NAME);
|
String fromUsername = optionService.getByPropertyOfNonNull(EmailProperties.FROM_NAME).toString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OhMyEmail.subject(subject)
|
OhMyEmail.subject(subject)
|
||||||
|
@ -89,7 +89,7 @@ public class MailServiceImpl implements MailService {
|
||||||
public void sendTemplateMail(String to, String subject, Map<String, Object> content, String templateName) {
|
public void sendTemplateMail(String to, String subject, Map<String, Object> content, String templateName) {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
String fromUsername = optionService.getByPropertyOfNonNull(EmailProperties.FROM_NAME);
|
String fromUsername = optionService.getByPropertyOfNonNull(EmailProperties.FROM_NAME).toString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
StrBuilder text = new StrBuilder();
|
StrBuilder text = new StrBuilder();
|
||||||
|
@ -120,7 +120,7 @@ public class MailServiceImpl implements MailService {
|
||||||
public void sendAttachMail(String to, String subject, Map<String, Object> content, String templateName, String attachFilename) {
|
public void sendAttachMail(String to, String subject, Map<String, Object> content, String templateName, String attachFilename) {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
String fromUsername = optionService.getByPropertyOfNonNull(EmailProperties.FROM_NAME);
|
String fromUsername = optionService.getByPropertyOfNonNull(EmailProperties.FROM_NAME).toString();
|
||||||
|
|
||||||
File file = new File(attachFilename);
|
File file = new File(attachFilename);
|
||||||
try {
|
try {
|
||||||
|
@ -149,11 +149,11 @@ public class MailServiceImpl implements MailService {
|
||||||
// Get default properties
|
// Get default properties
|
||||||
Properties defaultProperties = OhMyEmail.defaultConfig(log.isDebugEnabled());
|
Properties defaultProperties = OhMyEmail.defaultConfig(log.isDebugEnabled());
|
||||||
// Set smtp host
|
// Set smtp host
|
||||||
defaultProperties.setProperty("mail.smtp.host", optionService.getByPropertyOfNonNull(EmailProperties.HOST));
|
defaultProperties.setProperty("mail.smtp.host", optionService.getByPropertyOfNonNull(EmailProperties.HOST).toString());
|
||||||
// Config email
|
// Config email
|
||||||
OhMyEmail.config(defaultProperties,
|
OhMyEmail.config(defaultProperties,
|
||||||
optionService.getByPropertyOfNonNull(EmailProperties.USERNAME),
|
optionService.getByPropertyOfNonNull(EmailProperties.USERNAME).toString(),
|
||||||
optionService.getByPropertyOfNonNull(EmailProperties.PASSWORD));
|
optionService.getByPropertyOfNonNull(EmailProperties.PASSWORD).toString());
|
||||||
|
|
||||||
// Set config loaded with true
|
// Set config loaded with true
|
||||||
loaded = true;
|
loaded = true;
|
||||||
|
|
|
@ -24,7 +24,6 @@ import run.halo.app.utils.HaloUtils;
|
||||||
import run.halo.app.utils.ServiceUtils;
|
import run.halo.app.utils.ServiceUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OptionService implementation class
|
* OptionService implementation class
|
||||||
|
@ -209,40 +208,44 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<OptionDTO> listDtos() {
|
public List<OptionDTO> listDtos() {
|
||||||
return listAll().stream().map(option -> new OptionDTO().<OptionDTO>convertFrom(option)).collect(Collectors.toList());
|
List<OptionDTO> result = new LinkedList<>();
|
||||||
|
|
||||||
|
listOptions().forEach((key, value) -> result.add(new OptionDTO(key, value)));
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getByKeyOfNullable(String key) {
|
public Object getByKeyOfNullable(String key) {
|
||||||
return getByKey(key).orElse(null);
|
return getByKey(key).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getByKeyOfNonNull(String key) {
|
public Object getByKeyOfNonNull(String key) {
|
||||||
return getByKey(key).orElseThrow(() -> new MissingPropertyException("You have to config " + key + " setting"));
|
return getByKey(key).orElseThrow(() -> new MissingPropertyException("You have to config " + key + " setting"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getByKey(String key) {
|
public Optional<Object> getByKey(String key) {
|
||||||
Assert.hasText(key, "Option key must not be blank");
|
Assert.hasText(key, "Option key must not be blank");
|
||||||
|
|
||||||
return optionRepository.findByKey(key).map(Option::getValue);
|
return Optional.ofNullable(listOptions().get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getByPropertyOfNullable(PropertyEnum property) {
|
public Object getByPropertyOfNullable(PropertyEnum property) {
|
||||||
return getByProperty(property).orElse(null);
|
return getByProperty(property).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getByPropertyOfNonNull(PropertyEnum property) {
|
public Object getByPropertyOfNonNull(PropertyEnum property) {
|
||||||
Assert.notNull(property, "Blog property must not be null");
|
Assert.notNull(property, "Blog property must not be null");
|
||||||
|
|
||||||
return getByKeyOfNonNull(property.getValue());
|
return getByKeyOfNonNull(property.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getByProperty(PropertyEnum property) {
|
public Optional<Object> getByProperty(PropertyEnum property) {
|
||||||
Assert.notNull(property, "Blog property must not be null");
|
Assert.notNull(property, "Blog property must not be null");
|
||||||
|
|
||||||
return getByKey(property.getValue());
|
return getByKey(property.getValue());
|
||||||
|
@ -257,7 +260,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<T> getByProperty(PropertyEnum property, Class<T> propertyType) {
|
public <T> Optional<T> getByProperty(PropertyEnum property, Class<T> propertyType) {
|
||||||
return getByProperty(property).map(propertyValue -> PropertyEnum.convertTo(propertyValue, propertyType));
|
return getByProperty(property).map(propertyValue -> PropertyEnum.convertTo(propertyValue.toString(), propertyType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -267,12 +270,12 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<T> getByKey(String key, Class<T> valueType) {
|
public <T> Optional<T> getByKey(String key, Class<T> valueType) {
|
||||||
return getByKey(key).map(value -> PropertyEnum.convertTo(value, valueType));
|
return getByKey(key).map(value -> PropertyEnum.convertTo(value.toString(), valueType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends Enum<T>> Optional<T> getEnumByProperty(PropertyEnum property, Class<T> valueType) {
|
public <T extends Enum<T>> Optional<T> getEnumByProperty(PropertyEnum property, Class<T> valueType) {
|
||||||
return getByProperty(property).map(value -> PropertyEnum.convertToEnum(value, valueType));
|
return getByProperty(property).map(value -> PropertyEnum.convertToEnum(value.toString(), valueType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -282,7 +285,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <V, E extends ValueEnum<V>> Optional<E> getValueEnumByProperty(PropertyEnum property, Class<V> valueType, Class<E> enumType) {
|
public <V, E extends ValueEnum<V>> Optional<E> getValueEnumByProperty(PropertyEnum property, Class<V> valueType, Class<E> enumType) {
|
||||||
return getByProperty(property).map(value -> ValueEnum.valueToEnum(enumType, PropertyEnum.convertTo(value, valueType)));
|
return getByProperty(property).map(value -> ValueEnum.valueToEnum(enumType, PropertyEnum.convertTo(value.toString(), valueType)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -325,7 +328,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
return getByProperty(QnYunProperties.ZONE).map(qiniuZone -> {
|
return getByProperty(QnYunProperties.ZONE).map(qiniuZone -> {
|
||||||
|
|
||||||
Zone zone;
|
Zone zone;
|
||||||
switch (qiniuZone) {
|
switch (qiniuZone.toString()) {
|
||||||
case "z0":
|
case "z0":
|
||||||
zone = Zone.zone0();
|
zone = Zone.zone0();
|
||||||
break;
|
break;
|
||||||
|
@ -354,7 +357,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
public Locale getLocale() {
|
public Locale getLocale() {
|
||||||
return getByProperty(BlogProperties.BLOG_LOCALE).map(localeStr -> {
|
return getByProperty(BlogProperties.BLOG_LOCALE).map(localeStr -> {
|
||||||
try {
|
try {
|
||||||
return Locale.forLanguageTag(localeStr);
|
return Locale.forLanguageTag(localeStr.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Locale.getDefault();
|
return Locale.getDefault();
|
||||||
}
|
}
|
||||||
|
@ -366,7 +369,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
// Get server port
|
// Get server port
|
||||||
String serverPort = applicationContext.getEnvironment().getProperty("server.port", "8080");
|
String serverPort = applicationContext.getEnvironment().getProperty("server.port", "8080");
|
||||||
|
|
||||||
String blogUrl = getByPropertyOfNullable(BlogProperties.BLOG_URL);
|
String blogUrl = getByProperty(BlogProperties.BLOG_URL).orElse("").toString();
|
||||||
|
|
||||||
if (StrUtil.isNotBlank(blogUrl)) {
|
if (StrUtil.isNotBlank(blogUrl)) {
|
||||||
blogUrl = StrUtil.removeSuffix(blogUrl, "/");
|
blogUrl = StrUtil.removeSuffix(blogUrl, "/");
|
||||||
|
|
|
@ -296,7 +296,7 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
if (activatedThemeId == null) {
|
if (activatedThemeId == null) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (activatedThemeId == null) {
|
if (activatedThemeId == null) {
|
||||||
activatedThemeId = optionService.getByProperty(PrimaryProperties.THEME).orElse(DEFAULT_THEME_ID);
|
activatedThemeId = optionService.getByPropertyOrDefault(PrimaryProperties.THEME, String.class, DEFAULT_THEME_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue