From 4819a9824f179cbf3c6e2022034b9f8b9891668a Mon Sep 17 00:00:00 2001 From: johnniang Date: Thu, 25 Apr 2019 02:21:46 +0800 Subject: [PATCH] Complete option default value and type feature --- .../event/post/SheetVisitEventListener.java | 1 - .../app/model/params/AttachmentQuery.java | 3 +- .../model/properties/AliYunProperties.java | 26 ++++-- .../properties/AttachmentProperties.java | 18 ++++- .../app/model/properties/BlogProperties.java | 26 +++--- .../model/properties/CommentProperties.java | 28 ++++--- .../app/model/properties/EmailProperties.java | 27 ++++--- .../app/model/properties/OtherProperties.java | 17 ++-- .../app/model/properties/PostProperties.java | 20 +++-- .../model/properties/PrimaryProperties.java | 19 +++-- .../app/model/properties/PropertyEnum.java | 81 +++++++++++++++++-- .../app/model/properties/QnYunProperties.java | 22 +++-- .../app/model/properties/SeoProperties.java | 24 ++++-- .../app/model/properties/UpYunProperties.java | 23 ++++-- .../service/impl/AttachmentServiceImpl.java | 5 +- .../app/service/impl/OptionServiceImpl.java | 41 ++++++++-- .../model/properties/PropertyEnumTest.java | 21 +++++ 17 files changed, 307 insertions(+), 95 deletions(-) create mode 100644 src/test/java/run/halo/app/model/properties/PropertyEnumTest.java diff --git a/src/main/java/run/halo/app/event/post/SheetVisitEventListener.java b/src/main/java/run/halo/app/event/post/SheetVisitEventListener.java index ef30acdd0..384622997 100644 --- a/src/main/java/run/halo/app/event/post/SheetVisitEventListener.java +++ b/src/main/java/run/halo/app/event/post/SheetVisitEventListener.java @@ -18,7 +18,6 @@ public class SheetVisitEventListener extends AbstractVisitEventListener { @Async @EventListener - public void onSheetVisitEvent(SheetVisitEvent event) throws InterruptedException { handleVisitEvent(event); } diff --git a/src/main/java/run/halo/app/model/params/AttachmentQuery.java b/src/main/java/run/halo/app/model/params/AttachmentQuery.java index 576bb50d8..bda57794f 100644 --- a/src/main/java/run/halo/app/model/params/AttachmentQuery.java +++ b/src/main/java/run/halo/app/model/params/AttachmentQuery.java @@ -1,6 +1,7 @@ package run.halo.app.model.params; import lombok.Data; +import run.halo.app.model.enums.AttachmentType; /** * Attachment query params. @@ -18,5 +19,5 @@ public class AttachmentQuery { private String mediaType; - private String attachmentType; + private AttachmentType attachmentType; } diff --git a/src/main/java/run/halo/app/model/properties/AliYunProperties.java b/src/main/java/run/halo/app/model/properties/AliYunProperties.java index 192e55d9d..1f2ff491c 100644 --- a/src/main/java/run/halo/app/model/properties/AliYunProperties.java +++ b/src/main/java/run/halo/app/model/properties/AliYunProperties.java @@ -2,35 +2,40 @@ package run.halo.app.model.properties; /** * AliYun properties. + * * @author MyFaith * @date 2019-04-04 00:00:56 */ -public enum AliYunProperties implements PropertyEnum { +public enum AliYunProperties implements PropertyEnum { /** * Aliyun oss endpoint. */ - OSS_ENDPOINT("oss_aliyun_endpoint", String.class), + OSS_ENDPOINT("oss_aliyun_endpoint", String.class, ""), /** * Aliyun oss bucket name. */ - OSS_BUCKET_NAME("oss_aliyun_bucket_name", String.class), + OSS_BUCKET_NAME("oss_aliyun_bucket_name", String.class, ""), /** * Aliyun oss access key. */ - OSS_ACCESS_KEY("oss_aliyun_access_key", String.class), + OSS_ACCESS_KEY("oss_aliyun_access_key", String.class, ""), /** * Aliyun oss access secret. */ - OSS_ACCESS_SECRET("oss_aliyun_access_secret", String.class); + OSS_ACCESS_SECRET("oss_aliyun_access_secret", String.class, ""); - private String value; - private Class type; + private final String value; - AliYunProperties(String value, Class type) { + private final Class type; + + private final String defaultValue; + + AliYunProperties(String value, Class type, String defaultValue) { + this.defaultValue = defaultValue; if (!PropertyEnum.isSupportedType(type)) { throw new IllegalArgumentException("Unsupported blog property type: " + type); } @@ -44,6 +49,11 @@ public enum AliYunProperties implements PropertyEnum { return type; } + @Override + public String defaultValue() { + return defaultValue; + } + @Override public String getValue() { return value; diff --git a/src/main/java/run/halo/app/model/properties/AttachmentProperties.java b/src/main/java/run/halo/app/model/properties/AttachmentProperties.java index f2284ad4e..8ff4d9aaa 100644 --- a/src/main/java/run/halo/app/model/properties/AttachmentProperties.java +++ b/src/main/java/run/halo/app/model/properties/AttachmentProperties.java @@ -1,6 +1,5 @@ package run.halo.app.model.properties; -import run.halo.app.model.enums.AttachmentType; import run.halo.app.model.enums.AttachmentType; /** @@ -11,15 +10,18 @@ import run.halo.app.model.enums.AttachmentType; */ public enum AttachmentProperties implements PropertyEnum { - ATTACHMENT_TYPE("attachment_type", AttachmentType.class); + ATTACHMENT_TYPE("attachment_type", AttachmentType.class, AttachmentType.LOCAL.name()); private final String value; private final Class type; - AttachmentProperties(String value, Class type) { + private final String defaultValue; + + AttachmentProperties(String value, Class type, String defaultValue) { this.value = value; this.type = type; + this.defaultValue = defaultValue; } @Override @@ -27,7 +29,15 @@ public enum AttachmentProperties implements PropertyEnum { return type; } + @Override + public String defaultValue() { + return defaultValue; + } + @Override public String getValue() { return value; - }} + } + + +} diff --git a/src/main/java/run/halo/app/model/properties/BlogProperties.java b/src/main/java/run/halo/app/model/properties/BlogProperties.java index c9098cef3..c825b07fe 100644 --- a/src/main/java/run/halo/app/model/properties/BlogProperties.java +++ b/src/main/java/run/halo/app/model/properties/BlogProperties.java @@ -9,38 +9,41 @@ public enum BlogProperties implements PropertyEnum { /** * Blog locale. */ - BLOG_LOCALE("blog_locale", String.class), + BLOG_LOCALE("blog_locale", String.class, ""), /** * Blog title. */ - BLOG_TITLE("blog_title", String.class), + BLOG_TITLE("blog_title", String.class, ""), /** * Blog logo. */ - BLOG_LOGO("blog_logo", String.class), + BLOG_LOGO("blog_logo", String.class, ""), /** * Blog url. */ - BLOG_URL("blog_url", String.class), + BLOG_URL("blog_url", String.class, ""), /** * Blog favicon. */ - BLOG_FAVICON("blog_favicon", String.class), + BLOG_FAVICON("blog_favicon", String.class, ""), /** * Blog footer info. */ - BLOG_FOOTER_INFO("blog_footer_info", String.class); + BLOG_FOOTER_INFO("blog_footer_info", String.class, ""); - private String value; + private final String value; - private Class type; + private final Class type; - BlogProperties(String value, Class type) { + private final String defaultValue; + + BlogProperties(String value, Class type, String defaultValue) { + this.defaultValue = defaultValue; if (!PropertyEnum.isSupportedType(type)) { throw new IllegalArgumentException("Unsupported blog property type: " + type); } @@ -64,4 +67,9 @@ public enum BlogProperties implements PropertyEnum { return type; } + @Override + public String defaultValue() { + return defaultValue; + } + } diff --git a/src/main/java/run/halo/app/model/properties/CommentProperties.java b/src/main/java/run/halo/app/model/properties/CommentProperties.java index 92511c3c3..20ec3d678 100644 --- a/src/main/java/run/halo/app/model/properties/CommentProperties.java +++ b/src/main/java/run/halo/app/model/properties/CommentProperties.java @@ -8,31 +8,34 @@ package run.halo.app.model.properties; */ public enum CommentProperties implements PropertyEnum { - GAVATAR_DEFAULT("comment_gavatar_default", String.class), + GAVATAR_DEFAULT("comment_gavatar_default", String.class, ""), - NEW_NEED_CHECK("comment_new_need_check", Boolean.class), + NEW_NEED_CHECK("comment_new_need_check", Boolean.class, ""), - NEW_NOTICE("comment_new_notice", Boolean.class), + NEW_NOTICE("comment_new_notice", Boolean.class, ""), - PASS_NOTICE("comment_pass_notice", Boolean.class), + PASS_NOTICE("comment_pass_notice", Boolean.class, ""), - REPLY_NOTICE("comment_reply_notice", Boolean.class), + REPLY_NOTICE("comment_reply_notice", Boolean.class, ""), - API_ENABLED("comment_api_enabled", Boolean.class), + API_ENABLED("comment_api_enabled", Boolean.class, ""), - PAGE_SIZE("comment_page_size", Integer.class), + PAGE_SIZE("comment_page_size", Integer.class, ""), - CONTENT_PLACEHOLDER("comment_content_placeholder", String.class), + CONTENT_PLACEHOLDER("comment_content_placeholder", String.class, ""), - CUSTOM_STYLE("comment_custom_style", String.class); + CUSTOM_STYLE("comment_custom_style", String.class, ""); private final String value; private final Class type; + + private final String defaultValue; - CommentProperties(String value, Class type) { + CommentProperties(String value, Class type, String defaultValue) { this.value = value; this.type = type; + this.defaultValue = defaultValue; } @Override @@ -40,6 +43,11 @@ public enum CommentProperties implements PropertyEnum { return type; } + @Override + public String defaultValue() { + return defaultValue; + } + @Override public String getValue() { return value; diff --git a/src/main/java/run/halo/app/model/properties/EmailProperties.java b/src/main/java/run/halo/app/model/properties/EmailProperties.java index 72bcbd307..49f25a3bd 100644 --- a/src/main/java/run/halo/app/model/properties/EmailProperties.java +++ b/src/main/java/run/halo/app/model/properties/EmailProperties.java @@ -8,25 +8,28 @@ package run.halo.app.model.properties; */ public enum EmailProperties implements PropertyEnum { - HOST("email_host", String.class), + HOST("email_host", String.class, ""), - PROTOCOL("email_protocol", String.class), + PROTOCOL("email_protocol", String.class, ""), - SSL_PORT("email_ssl_port", Integer.class), + SSL_PORT("email_ssl_port", Integer.class, ""), - USERNAME("email_username", String.class), + USERNAME("email_username", String.class, ""), - PASSWORD("email_password", String.class), + PASSWORD("email_password", String.class, ""), - FROM_NAME("email_from_name", String.class), + FROM_NAME("email_from_name", String.class, ""), - ENABLED("email_enabled", Boolean.class); + ENABLED("email_enabled", Boolean.class, ""); private final String value; private final Class type; - EmailProperties(String value, Class type) { + private final String defaultValue; + + EmailProperties(String value, Class type, String defaultValue) { + this.defaultValue = defaultValue; if (!PropertyEnum.isSupportedType(type)) { throw new IllegalArgumentException("Unsupported blog property type: " + type); } @@ -40,7 +43,13 @@ public enum EmailProperties implements PropertyEnum { return type; } + @Override + public String defaultValue() { + return defaultValue; + } + @Override public String getValue() { return value; - }} + } +} diff --git a/src/main/java/run/halo/app/model/properties/OtherProperties.java b/src/main/java/run/halo/app/model/properties/OtherProperties.java index 2e96e82cd..c00764656 100644 --- a/src/main/java/run/halo/app/model/properties/OtherProperties.java +++ b/src/main/java/run/halo/app/model/properties/OtherProperties.java @@ -8,20 +8,22 @@ package run.halo.app.model.properties; */ public enum OtherProperties implements PropertyEnum { - API_ENABLED("api_enabled", Boolean.class), + API_ENABLED("api_enabled", Boolean.class, ""), - API_TOKEN("api_token", String.class), + API_TOKEN("api_token", String.class, ""), - STATISTICS_CODE("statistics_code", String.class), - ; + STATISTICS_CODE("statistics_code", String.class, ""); private final String value; private final Class type; - OtherProperties(String value, Class type) { + private final String defaultValue; + + OtherProperties(String value, Class type, String defaultValue) { this.value = value; this.type = type; + this.defaultValue = defaultValue; } @Override @@ -29,6 +31,11 @@ public enum OtherProperties implements PropertyEnum { return type; } + @Override + public String defaultValue() { + return defaultValue; + } + @Override public String getValue() { return value; diff --git a/src/main/java/run/halo/app/model/properties/PostProperties.java b/src/main/java/run/halo/app/model/properties/PostProperties.java index e719bc98f..394eaaf97 100644 --- a/src/main/java/run/halo/app/model/properties/PostProperties.java +++ b/src/main/java/run/halo/app/model/properties/PostProperties.java @@ -1,33 +1,41 @@ package run.halo.app.model.properties; /** + * Post properties. + * * @author johnniang * @date 4/1/19 */ public enum PostProperties implements PropertyEnum { - SUMMARY_LENGTH("post_summary_length", Integer.class), + SUMMARY_LENGTH("post_summary_length", Integer.class, ""), - RSS_PAGE_SIZE("rss_page_size", Integer.class), + RSS_PAGE_SIZE("rss_page_size", Integer.class, "20"), - INDEX_PAGE_SIZE("post_index_page_size", Integer.class), - ; + INDEX_PAGE_SIZE("post_index_page_size", Integer.class, "10"); private final String value; private final Class type; - PostProperties(String value, Class type) { + private final String defaultValue; + + PostProperties(String value, Class type, String defaultValue) { this.value = value; this.type = type; + this.defaultValue = defaultValue; } - @Override public Class getType() { return type; } + @Override + public String defaultValue() { + return defaultValue; + } + @Override public String getValue() { return value; diff --git a/src/main/java/run/halo/app/model/properties/PrimaryProperties.java b/src/main/java/run/halo/app/model/properties/PrimaryProperties.java index ef72d3bea..61874f336 100644 --- a/src/main/java/run/halo/app/model/properties/PrimaryProperties.java +++ b/src/main/java/run/halo/app/model/properties/PrimaryProperties.java @@ -8,20 +8,23 @@ package run.halo.app.model.properties; */ public enum PrimaryProperties implements PropertyEnum { - IS_INSTALLED("is_installed", Boolean.class), + IS_INSTALLED("is_installed", Boolean.class, ""), - THEME("theme", String.class), + THEME("theme", String.class, ""), - BIRTHDAY("birthday", Long.class), + BIRTHDAY("birthday", Long.class, ""), ; private final String value; private final Class type; - PrimaryProperties(String value, Class type) { + private final String defaultValue; + + PrimaryProperties(String value, Class type, String defaultValue) { this.value = value; this.type = type; + this.defaultValue = defaultValue; } @Override @@ -29,7 +32,13 @@ public enum PrimaryProperties implements PropertyEnum { return type; } + @Override + public String defaultValue() { + return defaultValue; + } + @Override public String getValue() { return value; - }} + } +} diff --git a/src/main/java/run/halo/app/model/properties/PropertyEnum.java b/src/main/java/run/halo/app/model/properties/PropertyEnum.java index 1eb68d01c..ac8e2895f 100644 --- a/src/main/java/run/halo/app/model/properties/PropertyEnum.java +++ b/src/main/java/run/halo/app/model/properties/PropertyEnum.java @@ -1,10 +1,17 @@ package run.halo.app.model.properties; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import run.halo.app.model.enums.ValueEnum; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + /** * Property enum. * @@ -16,18 +23,15 @@ public interface PropertyEnum extends ValueEnum { /** * Converts to value with corresponding type * - * @param value string value must not be null + * @param value string value must not be blank * @param type property value type must not be null * @param property value type * @return property value */ @SuppressWarnings("unchecked") static T convertTo(@NonNull String value, @NonNull Class type) { - Assert.hasText(value, "Property value must not be blank"); - - if (!isSupportedType(type)) { - throw new IllegalArgumentException("Unsupported blog property type: " + type); - } + Assert.hasText(value, "Value must not be null"); + Assert.notNull(type, "Type must not be null"); if (type.isAssignableFrom(String.class)) { return (T) value; @@ -65,6 +69,36 @@ public interface PropertyEnum extends ValueEnum { throw new UnsupportedOperationException("Unsupported convention for blog property type:" + type.getName() + " provided"); } + /** + * Converts to value with corresponding type + * + * @param value value + * @param propertyEnum property enum must not be null + * @return property value + */ + @SuppressWarnings("unchecked") + static Object convertTo(@Nullable String value, @NonNull PropertyEnum propertyEnum) { + Assert.notNull(propertyEnum, "Property enum must not be null"); + + if (StringUtils.isBlank(value)) { + // Set default value + value = propertyEnum.defaultValue(); + } + + try { + if (propertyEnum.getType().isAssignableFrom(Enum.class)) { + Class type = (Class) propertyEnum.getType(); + Enum result = convertToEnum(value, type); + return result != null ? result : value; + } + + return convertTo(value, propertyEnum.getType()); + } catch (Exception e) { + // Return value + return value; + } + } + /** * Converts to enum. * @@ -107,10 +141,45 @@ public interface PropertyEnum extends ValueEnum { ); } + static Map getValuePropertyEnumMap() { + // Get all properties + List> propertyEnumClasses = new LinkedList<>(); + propertyEnumClasses.add(AliYunProperties.class); + propertyEnumClasses.add(AttachmentProperties.class); + propertyEnumClasses.add(BlogProperties.class); + propertyEnumClasses.add(CommentProperties.class); + propertyEnumClasses.add(EmailProperties.class); + propertyEnumClasses.add(OtherProperties.class); + propertyEnumClasses.add(PostProperties.class); + propertyEnumClasses.add(PrimaryProperties.class); + propertyEnumClasses.add(QnYunProperties.class); + propertyEnumClasses.add(SeoProperties.class); + propertyEnumClasses.add(UpYunProperties.class); + + Map result = new HashMap<>(); + + propertyEnumClasses.forEach(propertyEnumClass -> { + PropertyEnum[] propertyEnums = propertyEnumClass.getEnumConstants(); + + for (PropertyEnum propertyEnum : propertyEnums) { + result.put(propertyEnum.getValue(), propertyEnum); + } + }); + + return result; + } + /** * Get property type. * * @return property type */ Class getType(); + + /** + * Default value. + * + * @return default value + */ + String defaultValue(); } diff --git a/src/main/java/run/halo/app/model/properties/QnYunProperties.java b/src/main/java/run/halo/app/model/properties/QnYunProperties.java index 27604a8c8..9216e5965 100644 --- a/src/main/java/run/halo/app/model/properties/QnYunProperties.java +++ b/src/main/java/run/halo/app/model/properties/QnYunProperties.java @@ -8,23 +8,26 @@ package run.halo.app.model.properties; */ public enum QnYunProperties implements PropertyEnum { - ZONE("oss_qiniu_zone", String.class), + ZONE("oss_qiniu_zone", String.class, ""), - ACCESS_KEY("oss_qiniu_access_key", String.class), + ACCESS_KEY("oss_qiniu_access_key", String.class, ""), - SECRET_KEY("oss_qiniu_secret_key", String.class), + SECRET_KEY("oss_qiniu_secret_key", String.class, ""), - DOMAIN("oss_qiniu_domain", String.class), + DOMAIN("oss_qiniu_domain", String.class, ""), - BUCKET("oss_qiniu_bucket", String.class), + BUCKET("oss_qiniu_bucket", String.class, ""), - SMALL_URL("oss_qiniu_small_url", String.class); + SMALL_URL("oss_qiniu_small_url", String.class, ""); private final String value; private final Class type; + + private final String defaultValue; - QnYunProperties(String value, Class type) { + QnYunProperties(String value, Class type, String defaultValue) { + this.defaultValue = defaultValue; if (!PropertyEnum.isSupportedType(type)) { throw new IllegalArgumentException("Unsupported blog property type: " + type); } @@ -43,4 +46,9 @@ public enum QnYunProperties implements PropertyEnum { return type; } + @Override + public String defaultValue() { + return defaultValue; + } + } diff --git a/src/main/java/run/halo/app/model/properties/SeoProperties.java b/src/main/java/run/halo/app/model/properties/SeoProperties.java index 30b21dff5..86acef1bb 100644 --- a/src/main/java/run/halo/app/model/properties/SeoProperties.java +++ b/src/main/java/run/halo/app/model/properties/SeoProperties.java @@ -8,27 +8,30 @@ package run.halo.app.model.properties; */ public enum SeoProperties implements PropertyEnum { - KEYWORDS("seo_keywords", String.class), + KEYWORDS("seo_keywords", String.class, ""), - DESCRIPTION("seo_description", String.class), + DESCRIPTION("seo_description", String.class, ""), - BAIDU_TOKEN("seo_baidu_token", String.class), + BAIDU_TOKEN("seo_baidu_token", String.class, ""), - VERIFICATION_BAIDU("seo_verification_baidu", String.class), + VERIFICATION_BAIDU("seo_verification_baidu", String.class, ""), - VERIFICATION_GOOGLE("seo_verification_google", String.class), + VERIFICATION_GOOGLE("seo_verification_google", String.class, ""), - VERIFICATION_BING("seo_verification_bing", String.class), + VERIFICATION_BING("seo_verification_bing", String.class, ""), - VERIFICATION_QIHU("seo_verification_qihu", String.class); + VERIFICATION_QIHU("seo_verification_qihu", String.class, ""); private final String value; private final Class type; + + private final String defaultValue; - SeoProperties(String value, Class type) { + SeoProperties(String value, Class type, String defaultValue) { this.value = value; this.type = type; + this.defaultValue = defaultValue; } @Override @@ -36,6 +39,11 @@ public enum SeoProperties implements PropertyEnum { return type; } + @Override + public String defaultValue() { + return defaultValue; + } + @Override public String getValue() { return value; diff --git a/src/main/java/run/halo/app/model/properties/UpYunProperties.java b/src/main/java/run/halo/app/model/properties/UpYunProperties.java index b8043823a..addb22f54 100644 --- a/src/main/java/run/halo/app/model/properties/UpYunProperties.java +++ b/src/main/java/run/halo/app/model/properties/UpYunProperties.java @@ -8,23 +8,26 @@ package run.halo.app.model.properties; */ public enum UpYunProperties implements PropertyEnum { - OSS_SOURCE("oss_upyun_source", String.class), + OSS_SOURCE("oss_upyun_source", String.class, ""), - OSS_PASSWORD("oss_upyun_password", String.class), + OSS_PASSWORD("oss_upyun_password", String.class, ""), - OSS_BUCKET("oss_upyun_bucket", String.class), + OSS_BUCKET("oss_upyun_bucket", String.class, ""), - OSS_DOMAIN("oss_upyun_domain", String.class), + OSS_DOMAIN("oss_upyun_domain", String.class, ""), - OSS_OPERATOR("oss_upyun_operator", String.class), + OSS_OPERATOR("oss_upyun_operator", String.class, ""), - OSS_SMALL_URL("oss_upyun_small_url", String.class); + OSS_SMALL_URL("oss_upyun_small_url", String.class, ""); private String value; private Class type; - UpYunProperties(String value, Class type) { + private final String defaultValue; + + UpYunProperties(String value, Class type, String defaultValue) { + this.defaultValue = defaultValue; if (!PropertyEnum.isSupportedType(type)) { throw new IllegalArgumentException("Unsupported blog property type: " + type); } @@ -33,12 +36,16 @@ public enum UpYunProperties implements PropertyEnum { this.type = type; } - @Override public Class getType() { return type; } + @Override + public String defaultValue() { + return defaultValue; + } + @Override public String getValue() { return value; diff --git a/src/main/java/run/halo/app/service/impl/AttachmentServiceImpl.java b/src/main/java/run/halo/app/service/impl/AttachmentServiceImpl.java index 65e02eaa8..0361ea0c2 100644 --- a/src/main/java/run/halo/app/service/impl/AttachmentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/AttachmentServiceImpl.java @@ -15,7 +15,6 @@ import run.halo.app.model.entity.Attachment; import run.halo.app.model.enums.AttachmentType; import run.halo.app.model.params.AttachmentQuery; import run.halo.app.model.properties.AttachmentProperties; -import run.halo.app.model.properties.PropertyEnum; import run.halo.app.model.support.UploadResult; import run.halo.app.repository.AttachmentRepository; import run.halo.app.service.AttachmentService; @@ -74,8 +73,8 @@ public class AttachmentServiceImpl extends AbstractCrudService impl private final StringCacheStore cacheStore; + private final Map propertyEnumMap; + public OptionServiceImpl(OptionRepository optionRepository, ApplicationContext applicationContext, StringCacheStore cacheStore) { @@ -51,6 +50,8 @@ public class OptionServiceImpl extends AbstractCrudService impl this.optionRepository = optionRepository; this.applicationContext = applicationContext; this.cacheStore = cacheStore; + + propertyEnumMap = Collections.unmodifiableMap(PropertyEnum.getValuePropertyEnumMap()); } @Override @@ -125,7 +126,37 @@ public class OptionServiceImpl extends AbstractCrudService impl @Override public Map listOptions() { - return ServiceUtils.convertToMap(listAll(), Option::getKey, Option::getValue); + List