From f87dc413e391d3e8bcbe77f66133eff06f4fab29 Mon Sep 17 00:00:00 2001 From: johnniang Date: Mon, 8 Apr 2019 23:37:00 +0800 Subject: [PATCH] Remove source column of Option entity --- .../run/halo/app/model/entity/Option.java | 11 ------ .../halo/app/model/enums/OptionSource.java | 4 ++- .../repository/ThemeSettingRepository.java | 14 ++++++++ .../run/halo/app/service/OptionService.java | 20 ++++------- .../halo/app/service/ThemeSettingService.java | 11 ++++++ .../app/service/impl/OptionServiceImpl.java | 34 +++++-------------- .../service/impl/ThemeSettingServiceImpl.java | 26 ++++++++++++++ .../admin/api/OptionController.java | 4 +-- .../controller/admin/api/ThemeController.java | 3 +- .../controller/core/InstallController.java | 2 +- 10 files changed, 74 insertions(+), 55 deletions(-) create mode 100644 src/main/java/run/halo/app/repository/ThemeSettingRepository.java create mode 100644 src/main/java/run/halo/app/service/ThemeSettingService.java create mode 100644 src/main/java/run/halo/app/service/impl/ThemeSettingServiceImpl.java diff --git a/src/main/java/run/halo/app/model/entity/Option.java b/src/main/java/run/halo/app/model/entity/Option.java index 539a20ec7..792e84e4a 100644 --- a/src/main/java/run/halo/app/model/entity/Option.java +++ b/src/main/java/run/halo/app/model/entity/Option.java @@ -1,6 +1,5 @@ package run.halo.app.model.entity; -import run.halo.app.model.enums.OptionSource; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -41,12 +40,6 @@ public class Option extends BaseEntity { @Column(name = "option_value", columnDefinition = "varchar(1023) not null") private String value; - /** - * source,default is system - */ - @Column(name = "option_source", columnDefinition = "int default 0") - private OptionSource source; - public Option(String key, String value) { this.key = key; this.value = value; @@ -56,9 +49,5 @@ public class Option extends BaseEntity { public void prePersist() { super.prePersist(); id = null; - - if (source == null) { - source = OptionSource.SYSTEM; - } } } diff --git a/src/main/java/run/halo/app/model/enums/OptionSource.java b/src/main/java/run/halo/app/model/enums/OptionSource.java index 404ca8280..b0b404ea3 100644 --- a/src/main/java/run/halo/app/model/enums/OptionSource.java +++ b/src/main/java/run/halo/app/model/enums/OptionSource.java @@ -6,6 +6,7 @@ package run.halo.app.model.enums; * @author johnniang * @date 4/1/19 */ +@Deprecated public enum OptionSource implements ValueEnum { SYSTEM(0), @@ -20,4 +21,5 @@ public enum OptionSource implements ValueEnum { @Override public Integer getValue() { return null; - }} + } +} diff --git a/src/main/java/run/halo/app/repository/ThemeSettingRepository.java b/src/main/java/run/halo/app/repository/ThemeSettingRepository.java new file mode 100644 index 000000000..4a48b02e5 --- /dev/null +++ b/src/main/java/run/halo/app/repository/ThemeSettingRepository.java @@ -0,0 +1,14 @@ +package run.halo.app.repository; + +import run.halo.app.model.entity.ThemeSetting; +import run.halo.app.repository.base.BaseRepository; + +/** + * Theme setting repository interface. + * + * @author johnniang + * @date 4/8/19 + */ +public interface ThemeSettingRepository extends BaseRepository { + +} diff --git a/src/main/java/run/halo/app/service/OptionService.java b/src/main/java/run/halo/app/service/OptionService.java index c77cd0597..540b95fe3 100755 --- a/src/main/java/run/halo/app/service/OptionService.java +++ b/src/main/java/run/halo/app/service/OptionService.java @@ -7,7 +7,6 @@ import org.springframework.transaction.annotation.Transactional; import run.halo.app.exception.MissingPropertyException; import run.halo.app.model.dto.OptionOutputDTO; import run.halo.app.model.entity.Option; -import run.halo.app.model.enums.OptionSource; import run.halo.app.model.enums.ValueEnum; import run.halo.app.model.params.OptionParam; import run.halo.app.model.properties.PropertyEnum; @@ -34,49 +33,44 @@ public interface OptionService extends CrudService { /** * Save one option * - * @param key key must not be blank - * @param value value - * @param source source + * @param key key must not be blank + * @param value value */ @Transactional - void save(@NonNull String key, String value, @NonNull OptionSource source); + void save(@NonNull String key, String value); /** * Save multiple options * * @param options options - * @param source source */ @Transactional - void save(@NonNull Map options, @NonNull OptionSource source); + void save(@Nullable Map options); /** * SAve multiple options * * @param optionParams option params - * @param source source */ @Transactional - void save(List optionParams, @NonNull OptionSource source); + void save(@Nullable List optionParams); /** * Saves a property. * * @param property must not be null * @param value could be null - * @param source must not be null */ @Transactional - void saveProperty(@NonNull PropertyEnum property, String value, @NonNull OptionSource source); + void saveProperty(@NonNull PropertyEnum property, @Nullable String value); /** * Saves blog properties. * * @param properties blog properties - * @param source source */ @Transactional - void saveProperties(@NonNull Map properties, @NonNull OptionSource source); + void saveProperties(@NonNull Map properties); /** * Get all options diff --git a/src/main/java/run/halo/app/service/ThemeSettingService.java b/src/main/java/run/halo/app/service/ThemeSettingService.java new file mode 100644 index 000000000..9dc5662e0 --- /dev/null +++ b/src/main/java/run/halo/app/service/ThemeSettingService.java @@ -0,0 +1,11 @@ +package run.halo.app.service; + +/** + * Theme setting service interface. + * + * @author johnniang + * @date 4/8/19 + */ +public interface ThemeSettingService { + +} 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 cf01a5f58..7c1a4b2cf 100644 --- a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java @@ -9,7 +9,6 @@ import org.springframework.util.CollectionUtils; import run.halo.app.exception.MissingPropertyException; import run.halo.app.model.dto.OptionOutputDTO; import run.halo.app.model.entity.Option; -import run.halo.app.model.enums.OptionSource; import run.halo.app.model.enums.ValueEnum; import run.halo.app.model.params.OptionParam; import run.halo.app.model.properties.*; @@ -41,15 +40,8 @@ public class OptionServiceImpl extends AbstractCrudService impl this.optionRepository = optionRepository; } - /** - * Saves one option - * - * @param key key - * @param value value - * @param source source - */ @Override - public void save(String key, String value, OptionSource source) { + public void save(String key, String value) { Assert.hasText(key, "Option key must not be blank"); if (StringUtils.isBlank(value)) { @@ -71,7 +63,6 @@ public class OptionServiceImpl extends AbstractCrudService impl Option anOption = new Option(); anOption.setKey(key); anOption.setValue(value); - anOption.setSource(source); return anOption; }); @@ -81,47 +72,40 @@ public class OptionServiceImpl extends AbstractCrudService impl log.debug("Saved option: [{}]", savedOption); } - /** - * Saves multiple options - * - * @param options options - * @param source source - */ @Override - public void save(Map options, OptionSource source) { + public void save(Map options) { if (CollectionUtils.isEmpty(options)) { return; } // TODO Optimize the queries - options.forEach((key, value) -> save(key, value, source)); + options.forEach(this::save); } @Override - public void save(List optionParams, OptionSource source) { + public void save(List optionParams) { if (CollectionUtils.isEmpty(optionParams)) { return; } // TODO Optimize the query - optionParams.forEach(optionParam -> save(optionParam.getOptionKey(), optionParam.getOptionValue(), source)); + optionParams.forEach(optionParam -> save(optionParam.getOptionKey(), optionParam.getOptionValue())); } @Override - public void saveProperty(PropertyEnum property, String value, OptionSource source) { + public void saveProperty(PropertyEnum property, String value) { Assert.notNull(property, "Property must not be null"); - Assert.notNull(source, "Option source must not be null"); - save(property.getValue(), value, source); + save(property.getValue(), value); } @Override - public void saveProperties(Map properties, OptionSource source) { + public void saveProperties(Map properties) { if (CollectionUtils.isEmpty(properties)) { return; } - properties.forEach((property, value) -> save(property.getValue(), value, source)); + properties.forEach((property, value) -> save(property.getValue(), value)); } /** diff --git a/src/main/java/run/halo/app/service/impl/ThemeSettingServiceImpl.java b/src/main/java/run/halo/app/service/impl/ThemeSettingServiceImpl.java new file mode 100644 index 000000000..a500292b0 --- /dev/null +++ b/src/main/java/run/halo/app/service/impl/ThemeSettingServiceImpl.java @@ -0,0 +1,26 @@ +package run.halo.app.service.impl; + +import org.springframework.stereotype.Service; +import run.halo.app.model.entity.ThemeSetting; +import run.halo.app.repository.ThemeSettingRepository; +import run.halo.app.service.ThemeSettingService; +import run.halo.app.service.base.AbstractCrudService; + +/** + * Theme setting service implementation. + * + * @author johnniang + * @date 4/8/19 + */ +@Service +public class ThemeSettingServiceImpl extends AbstractCrudService implements ThemeSettingService { + + private final ThemeSettingRepository themeSettingRepository; + + public ThemeSettingServiceImpl(ThemeSettingRepository themeSettingRepository) { + super(themeSettingRepository); + this.themeSettingRepository = themeSettingRepository; + } + + +} diff --git a/src/main/java/run/halo/app/web/controller/admin/api/OptionController.java b/src/main/java/run/halo/app/web/controller/admin/api/OptionController.java index be7c27133..e279d1664 100644 --- a/src/main/java/run/halo/app/web/controller/admin/api/OptionController.java +++ b/src/main/java/run/halo/app/web/controller/admin/api/OptionController.java @@ -37,7 +37,7 @@ public class OptionController { @PostMapping("saving") public void saveOptions(@Valid @RequestBody List optionParams) { - optionService.save(optionParams, OptionSource.SYSTEM); + optionService.save(optionParams); } @GetMapping("map_view") @@ -49,6 +49,6 @@ public class OptionController { @PostMapping("map_view/saving") @ApiOperation("Saves options by option map") public void saveOptionsWithMapView(@RequestBody Map optionMap) { - optionService.save(optionMap, OptionSource.SYSTEM); + optionService.save(optionMap); } } diff --git a/src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java b/src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java index 32f7d629f..42722a478 100644 --- a/src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java +++ b/src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java @@ -4,7 +4,6 @@ import freemarker.template.Configuration; import freemarker.template.TemplateModelException; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; -import run.halo.app.model.enums.OptionSource; import run.halo.app.model.properties.PrimaryProperties; import run.halo.app.model.support.BaseResponse; import run.halo.app.model.support.Theme; @@ -79,7 +78,7 @@ public class ThemeController { @ApiOperation("Active a theme") public void active(String theme) throws TemplateModelException { // TODO Check existence of the theme - optionService.saveProperty(PrimaryProperties.THEME, theme, OptionSource.SYSTEM); + optionService.saveProperty(PrimaryProperties.THEME, theme); configuration.setSharedVariable("themeName", theme); configuration.setSharedVariable("options", optionService.listOptions()); } diff --git a/src/main/java/run/halo/app/web/controller/core/InstallController.java b/src/main/java/run/halo/app/web/controller/core/InstallController.java index 2122f8f06..4c8216f51 100644 --- a/src/main/java/run/halo/app/web/controller/core/InstallController.java +++ b/src/main/java/run/halo/app/web/controller/core/InstallController.java @@ -176,7 +176,7 @@ public class InstallController { properties.put(AttachmentProperties.ATTACHMENT_TYPE, AttachmentType.LOCAL.getValue().toString()); // Create properties - optionService.saveProperties(properties, OptionSource.SYSTEM); + optionService.saveProperties(properties); } }