diff --git a/src/main/java/run/halo/app/controller/admin/api/InstallController.java b/src/main/java/run/halo/app/controller/admin/api/InstallController.java index 446a501ad..cd2ee6238 100644 --- a/src/main/java/run/halo/app/controller/admin/api/InstallController.java +++ b/src/main/java/run/halo/app/controller/admin/api/InstallController.java @@ -79,7 +79,7 @@ public class InstallController { public BaseResponse installBlog(@RequestBody @Valid InstallParam installParam) { // TODO Install blog. // 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) { // TODO i18n @@ -172,7 +172,7 @@ public class InstallController { properties.put(CommentProperties.NEW_NOTICE, Boolean.FALSE.toString()); properties.put(CommentProperties.PASS_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 optionService.saveProperties(properties); diff --git a/src/main/java/run/halo/app/controller/content/api/OptionController.java b/src/main/java/run/halo/app/controller/content/api/OptionController.java index a4867808c..eeb428961 100644 --- a/src/main/java/run/halo/app/controller/content/api/OptionController.java +++ b/src/main/java/run/halo/app/controller/content/api/OptionController.java @@ -1,14 +1,12 @@ 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.support.BaseResponse; import run.halo.app.service.OptionService; import io.swagger.annotations.ApiOperation; 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.Map; @@ -36,14 +34,18 @@ public class OptionController { } @GetMapping("map_view") - @ApiOperation("Lists all options with map view") - public Map listAllWithMapView() { - return optionService.listOptions(); + @ApiOperation("Lists options with map view") + public Map listAllWithMapView(@RequestParam(value = "key", required = false) List keys) { + if (CollectionUtils.isEmpty(keys)) { + return optionService.listOptions(); + } + + return optionService.listOptions(keys); } @GetMapping("keys/{key}") @ApiOperation("Gets option value by option key") - public BaseResponse getBy(@PathVariable("key") String key) { - return BaseResponse.ok(HttpStatus.OK.getReasonPhrase(), optionService.getByKey(key).orElse("")); + public BaseResponse getBy(@PathVariable("key") String key) { + return BaseResponse.ok(HttpStatus.OK.getReasonPhrase(), optionService.getByKey(key).orElse(null)); } } diff --git a/src/main/java/run/halo/app/event/comment/CommentEventListener.java b/src/main/java/run/halo/app/event/comment/CommentEventListener.java index 017c4912f..a1e9c75cf 100644 --- a/src/main/java/run/halo/app/event/comment/CommentEventListener.java +++ b/src/main/java/run/halo/app/event/comment/CommentEventListener.java @@ -67,7 +67,7 @@ public class CommentEventListener { Map 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(post.getUrl()); data.put("url", url.toString()); diff --git a/src/main/java/run/halo/app/handler/file/AliYunFileHandler.java b/src/main/java/run/halo/app/handler/file/AliYunFileHandler.java index 29f7565d5..9dc1c6182 100644 --- a/src/main/java/run/halo/app/handler/file/AliYunFileHandler.java +++ b/src/main/java/run/halo/app/handler/file/AliYunFileHandler.java @@ -41,10 +41,10 @@ public class AliYunFileHandler implements FileHandler { Assert.notNull(file, "Multipart file must not be null"); // Get config - String ossEndPoint = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ENDPOINT); - String ossAccessKey = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_KEY); - String ossAccessSecret = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_SECRET); - String ossBucketName = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_BUCKET_NAME); + String ossEndPoint = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ENDPOINT).toString(); + String ossAccessKey = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_KEY).toString(); + String ossAccessSecret = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_SECRET).toString(); + String ossBucketName = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_BUCKET_NAME).toString(); String ossSource = StringUtils.join("https://", ossBucketName, "." + ossEndPoint); // Init OSS client @@ -100,10 +100,10 @@ public class AliYunFileHandler implements FileHandler { Assert.notNull(key, "File key must not be blank"); // Get config - String ossEndPoint = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ENDPOINT); - String ossAccessKey = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_KEY); - String ossAccessSecret = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_SECRET); - String ossBucketName = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_BUCKET_NAME); + String ossEndPoint = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ENDPOINT).toString(); + String ossAccessKey = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_KEY).toString(); + String ossAccessSecret = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_SECRET).toString(); + String ossBucketName = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_BUCKET_NAME).toString(); String ossSource = StringUtils.join("https://", ossBucketName, "." + ossEndPoint); // Init OSS client diff --git a/src/main/java/run/halo/app/handler/file/QnYunFileHandler.java b/src/main/java/run/halo/app/handler/file/QnYunFileHandler.java index 5ef221dd1..8cb5d05a9 100644 --- a/src/main/java/run/halo/app/handler/file/QnYunFileHandler.java +++ b/src/main/java/run/halo/app/handler/file/QnYunFileHandler.java @@ -1,13 +1,5 @@ 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.Zone; import com.qiniu.http.Response; @@ -23,6 +15,14 @@ import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.util.Assert; 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.nio.file.Path; @@ -53,11 +53,11 @@ public class QnYunFileHandler implements FileHandler { // Get all config Zone zone = optionService.getQnYunZone(); - String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.ACCESS_KEY); - String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY); - String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET); - String domain = optionService.getByPropertyOfNonNull(QnYunProperties.DOMAIN); - String smallUrl = optionService.getByPropertyOfNullable(QnYunProperties.SMALL_URL); + String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.ACCESS_KEY).toString(); + String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY).toString(); + String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET).toString(); + String domain = optionService.getByPropertyOfNonNull(QnYunProperties.DOMAIN).toString(); + String smallUrl = optionService.getByPropertyOrDefault(QnYunProperties.SMALL_URL, String.class, ""); // TODO Consider to cache the configuration // Create configuration @@ -132,9 +132,9 @@ public class QnYunFileHandler implements FileHandler { // Get all config Zone zone = optionService.getQnYunZone(); - String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.ACCESS_KEY); - String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY); - String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET); + String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.ACCESS_KEY).toString(); + String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY).toString(); + String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET).toString(); // TODO Consider to cache the configuration // Create configuration diff --git a/src/main/java/run/halo/app/handler/file/UpYunFileHandler.java b/src/main/java/run/halo/app/handler/file/UpYunFileHandler.java index ffa50fb52..4ea85e955 100644 --- a/src/main/java/run/halo/app/handler/file/UpYunFileHandler.java +++ b/src/main/java/run/halo/app/handler/file/UpYunFileHandler.java @@ -1,11 +1,5 @@ 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 lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -14,6 +8,12 @@ import org.springframework.stereotype.Component; import org.springframework.util.Assert; import org.springframework.util.DigestUtils; 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 java.awt.image.BufferedImage; @@ -39,13 +39,13 @@ public class UpYunFileHandler implements FileHandler { public UploadResult upload(MultipartFile file) { Assert.notNull(file, "Multipart file must not be null"); - String ossSource = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_SOURCE); - String ossPassword = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_PASSWORD); - String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET); - String ossDomain = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_DOMAIN); - String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR); + String ossSource = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_SOURCE).toString(); + String ossPassword = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_PASSWORD).toString(); + String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET).toString(); + String ossDomain = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_DOMAIN).toString(); + String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR).toString(); // 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 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"); // Get config - String ossSource = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_SOURCE); - String ossPassword = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_PASSWORD); - String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET); - String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR); + String ossSource = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_SOURCE).toString(); + String ossPassword = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_PASSWORD).toString(); + String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET).toString(); + String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR).toString(); // Create up yun UpYun upYun = new UpYun(ossBucket, ossOperator, ossPassword); diff --git a/src/main/java/run/halo/app/model/dto/OptionDTO.java b/src/main/java/run/halo/app/model/dto/OptionDTO.java index 93b905f42..ba54efba7 100644 --- a/src/main/java/run/halo/app/model/dto/OptionDTO.java +++ b/src/main/java/run/halo/app/model/dto/OptionDTO.java @@ -1,6 +1,8 @@ package run.halo.app.model.dto; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import run.halo.app.model.dto.base.OutputConverter; import run.halo.app.model.entity.Option; @@ -11,10 +13,12 @@ import run.halo.app.model.entity.Option; * @date 3/20/19 */ @Data +@NoArgsConstructor +@AllArgsConstructor public class OptionDTO implements OutputConverter { private String key; - private String value; + private Object value; } diff --git a/src/main/java/run/halo/app/service/OptionService.java b/src/main/java/run/halo/app/service/OptionService.java index 8da5d3f4b..636bb6636 100755 --- a/src/main/java/run/halo/app/service/OptionService.java +++ b/src/main/java/run/halo/app/service/OptionService.java @@ -101,7 +101,7 @@ public interface OptionService extends CrudService { * @return option value or null */ @Nullable - String getByKeyOfNullable(@NonNull String key); + Object getByKeyOfNullable(@NonNull String key); /** * Gets option value of non null. @@ -110,7 +110,7 @@ public interface OptionService extends CrudService { * @return option value of non null */ @NonNull - String getByKeyOfNonNull(@NonNull String key); + Object getByKeyOfNonNull(@NonNull String key); /** * Get option by key @@ -119,7 +119,7 @@ public interface OptionService extends CrudService { * @return an optional option value */ @NonNull - Optional getByKey(@NonNull String key); + Optional getByKey(@NonNull String key); /** * Gets option value by blog property. @@ -128,7 +128,7 @@ public interface OptionService extends CrudService { * @return an option value */ @Nullable - String getByPropertyOfNullable(@NonNull PropertyEnum property); + Object getByPropertyOfNullable(@NonNull PropertyEnum property); /** * Gets option value by blog property. @@ -138,7 +138,7 @@ public interface OptionService extends CrudService { * @throws MissingPropertyException throws when property value dismisses */ @NonNull - String getByPropertyOfNonNull(@NonNull PropertyEnum property); + Object getByPropertyOfNonNull(@NonNull PropertyEnum property); /** * Gets option value by blog property. @@ -147,7 +147,7 @@ public interface OptionService extends CrudService { * @return an optional option value */ @NonNull - Optional getByProperty(@NonNull PropertyEnum property); + Optional getByProperty(@NonNull PropertyEnum property); /** * Gets property value by blog property. diff --git a/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java b/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java index 4c079cbbc..7473feb8e 100644 --- a/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java @@ -256,7 +256,7 @@ public abstract class BaseCommentServiceImpl extend User user = authentication.getDetail().getUser(); commentParam.setAuthor(StringUtils.isBlank(user.getNickname()) ? user.getUsername() : user.getNickname()); 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 diff --git a/src/main/java/run/halo/app/service/impl/MailServiceImpl.java b/src/main/java/run/halo/app/service/impl/MailServiceImpl.java index 8895624e9..d012f1b31 100644 --- a/src/main/java/run/halo/app/service/impl/MailServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/MailServiceImpl.java @@ -62,7 +62,7 @@ public class MailServiceImpl implements MailService { public void sendMail(String to, String subject, String content) { loadConfig(); - String fromUsername = optionService.getByPropertyOfNonNull(EmailProperties.FROM_NAME); + String fromUsername = optionService.getByPropertyOfNonNull(EmailProperties.FROM_NAME).toString(); try { OhMyEmail.subject(subject) @@ -89,7 +89,7 @@ public class MailServiceImpl implements MailService { public void sendTemplateMail(String to, String subject, Map content, String templateName) { loadConfig(); - String fromUsername = optionService.getByPropertyOfNonNull(EmailProperties.FROM_NAME); + String fromUsername = optionService.getByPropertyOfNonNull(EmailProperties.FROM_NAME).toString(); try { StrBuilder text = new StrBuilder(); @@ -120,7 +120,7 @@ public class MailServiceImpl implements MailService { public void sendAttachMail(String to, String subject, Map content, String templateName, String attachFilename) { loadConfig(); - String fromUsername = optionService.getByPropertyOfNonNull(EmailProperties.FROM_NAME); + String fromUsername = optionService.getByPropertyOfNonNull(EmailProperties.FROM_NAME).toString(); File file = new File(attachFilename); try { @@ -149,11 +149,11 @@ public class MailServiceImpl implements MailService { // Get default properties Properties defaultProperties = OhMyEmail.defaultConfig(log.isDebugEnabled()); // Set smtp host - defaultProperties.setProperty("mail.smtp.host", optionService.getByPropertyOfNonNull(EmailProperties.HOST)); + defaultProperties.setProperty("mail.smtp.host", optionService.getByPropertyOfNonNull(EmailProperties.HOST).toString()); // Config email OhMyEmail.config(defaultProperties, - optionService.getByPropertyOfNonNull(EmailProperties.USERNAME), - optionService.getByPropertyOfNonNull(EmailProperties.PASSWORD)); + optionService.getByPropertyOfNonNull(EmailProperties.USERNAME).toString(), + optionService.getByPropertyOfNonNull(EmailProperties.PASSWORD).toString()); // Set config loaded with true loaded = true; diff --git a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java index d50f1be7b..4b4146559 100644 --- a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java @@ -24,7 +24,6 @@ import run.halo.app.utils.HaloUtils; import run.halo.app.utils.ServiceUtils; import java.util.*; -import java.util.stream.Collectors; /** * OptionService implementation class @@ -209,40 +208,44 @@ public class OptionServiceImpl extends AbstractCrudService impl @Override public List listDtos() { - return listAll().stream().map(option -> new OptionDTO().convertFrom(option)).collect(Collectors.toList()); + List result = new LinkedList<>(); + + listOptions().forEach((key, value) -> result.add(new OptionDTO(key, value))); + + return result; } @Override - public String getByKeyOfNullable(String key) { + public Object getByKeyOfNullable(String key) { return getByKey(key).orElse(null); } @Override - public String getByKeyOfNonNull(String key) { + public Object getByKeyOfNonNull(String key) { return getByKey(key).orElseThrow(() -> new MissingPropertyException("You have to config " + key + " setting")); } @Override - public Optional getByKey(String key) { + public Optional getByKey(String key) { Assert.hasText(key, "Option key must not be blank"); - return optionRepository.findByKey(key).map(Option::getValue); + return Optional.ofNullable(listOptions().get(key)); } @Override - public String getByPropertyOfNullable(PropertyEnum property) { + public Object getByPropertyOfNullable(PropertyEnum property) { return getByProperty(property).orElse(null); } @Override - public String getByPropertyOfNonNull(PropertyEnum property) { + public Object getByPropertyOfNonNull(PropertyEnum property) { Assert.notNull(property, "Blog property must not be null"); return getByKeyOfNonNull(property.getValue()); } @Override - public Optional getByProperty(PropertyEnum property) { + public Optional getByProperty(PropertyEnum property) { Assert.notNull(property, "Blog property must not be null"); return getByKey(property.getValue()); @@ -257,7 +260,7 @@ public class OptionServiceImpl extends AbstractCrudService impl @Override public Optional getByProperty(PropertyEnum property, Class propertyType) { - return getByProperty(property).map(propertyValue -> PropertyEnum.convertTo(propertyValue, propertyType)); + return getByProperty(property).map(propertyValue -> PropertyEnum.convertTo(propertyValue.toString(), propertyType)); } @Override @@ -267,12 +270,12 @@ public class OptionServiceImpl extends AbstractCrudService impl @Override public Optional getByKey(String key, Class valueType) { - return getByKey(key).map(value -> PropertyEnum.convertTo(value, valueType)); + return getByKey(key).map(value -> PropertyEnum.convertTo(value.toString(), valueType)); } @Override public > Optional getEnumByProperty(PropertyEnum property, Class valueType) { - return getByProperty(property).map(value -> PropertyEnum.convertToEnum(value, valueType)); + return getByProperty(property).map(value -> PropertyEnum.convertToEnum(value.toString(), valueType)); } @Override @@ -282,7 +285,7 @@ public class OptionServiceImpl extends AbstractCrudService impl @Override public > Optional getValueEnumByProperty(PropertyEnum property, Class valueType, Class 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 @@ -325,7 +328,7 @@ public class OptionServiceImpl extends AbstractCrudService impl return getByProperty(QnYunProperties.ZONE).map(qiniuZone -> { Zone zone; - switch (qiniuZone) { + switch (qiniuZone.toString()) { case "z0": zone = Zone.zone0(); break; @@ -354,7 +357,7 @@ public class OptionServiceImpl extends AbstractCrudService impl public Locale getLocale() { return getByProperty(BlogProperties.BLOG_LOCALE).map(localeStr -> { try { - return Locale.forLanguageTag(localeStr); + return Locale.forLanguageTag(localeStr.toString()); } catch (Exception e) { return Locale.getDefault(); } @@ -366,7 +369,7 @@ public class OptionServiceImpl extends AbstractCrudService impl // Get server port 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)) { blogUrl = StrUtil.removeSuffix(blogUrl, "/"); diff --git a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java index 9514fc19a..d75e22b9c 100644 --- a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java @@ -296,7 +296,7 @@ public class ThemeServiceImpl implements ThemeService { if (activatedThemeId == null) { synchronized (this) { if (activatedThemeId == null) { - activatedThemeId = optionService.getByProperty(PrimaryProperties.THEME).orElse(DEFAULT_THEME_ID); + activatedThemeId = optionService.getByPropertyOrDefault(PrimaryProperties.THEME, String.class, DEFAULT_THEME_ID); } } }