mirror of https://github.com/halo-dev/halo
Refactor option source
parent
c3739ff8b8
commit
1a3ea785b8
|
@ -1,13 +1,14 @@
|
|||
package cc.ryanc.halo.model.entity;
|
||||
|
||||
import cc.ryanc.halo.model.enums.OptionSource;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
||||
import javax.persistence.*;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Setting entity.
|
||||
|
@ -43,8 +44,8 @@ public class Option extends BaseEntity {
|
|||
/**
|
||||
* source,default is system
|
||||
*/
|
||||
@Column(name = "option_source", columnDefinition = "varchar(127) default 'system'")
|
||||
private String optionSource;
|
||||
@Column(name = "option_source", columnDefinition = "int default 0")
|
||||
private OptionSource source;
|
||||
|
||||
public Option(String optionKey, String optionValue) {
|
||||
this.optionKey = optionKey;
|
||||
|
@ -55,6 +56,9 @@ public class Option extends BaseEntity {
|
|||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
optionSource = "system";
|
||||
|
||||
if (source == null) {
|
||||
source = OptionSource.SYSTEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* Option source.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 4/1/19
|
||||
*/
|
||||
public enum OptionSource implements ValueEnum<Integer> {
|
||||
|
||||
SYSTEM(0),
|
||||
THEME(1);
|
||||
|
||||
private final int value;
|
||||
|
||||
OptionSource(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return null;
|
||||
}}
|
|
@ -0,0 +1,19 @@
|
|||
package cc.ryanc.halo.model.enums.converter;
|
||||
|
||||
import cc.ryanc.halo.model.enums.OptionSource;
|
||||
|
||||
import javax.persistence.Converter;
|
||||
|
||||
/**
|
||||
* OptionSource converter.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 4/1/19
|
||||
*/
|
||||
@Converter(autoApply = true)
|
||||
public class OptionSourceConverter extends AbstractConverter<OptionSource, Integer> {
|
||||
|
||||
public OptionSourceConverter() {
|
||||
super(OptionSource.class);
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package cc.ryanc.halo.service;
|
|||
import cc.ryanc.halo.exception.MissingPropertyException;
|
||||
import cc.ryanc.halo.model.dto.OptionOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Option;
|
||||
import cc.ryanc.halo.model.enums.OptionSource;
|
||||
import cc.ryanc.halo.model.enums.PropertyEnum;
|
||||
import cc.ryanc.halo.model.enums.ValueEnum;
|
||||
import cc.ryanc.halo.model.params.OptionParam;
|
||||
|
@ -36,7 +37,7 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
* @param value value
|
||||
* @param source source
|
||||
*/
|
||||
void save(@NonNull String key, String value, String source);
|
||||
void save(@NonNull String key, String value, @NonNull OptionSource source);
|
||||
|
||||
/**
|
||||
* Save multiple options
|
||||
|
@ -44,7 +45,7 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
* @param options options
|
||||
* @param source source
|
||||
*/
|
||||
void save(@NonNull Map<String, String> options, String source);
|
||||
void save(@NonNull Map<String, String> options, @NonNull OptionSource source);
|
||||
|
||||
/**
|
||||
* SAve multiple options
|
||||
|
@ -52,7 +53,7 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
* @param optionParams option params
|
||||
* @param source source
|
||||
*/
|
||||
void save(List<OptionParam> optionParams, String source);
|
||||
void save(List<OptionParam> optionParams, @NonNull OptionSource source);
|
||||
|
||||
/**
|
||||
* Saves blog properties.
|
||||
|
@ -60,7 +61,7 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
* @param properties blog properties
|
||||
* @param source source
|
||||
*/
|
||||
void saveProperties(@NonNull Map<? extends PropertyEnum, String> properties, String source);
|
||||
void saveProperties(@NonNull Map<? extends PropertyEnum, String> properties, @NonNull OptionSource source);
|
||||
|
||||
/**
|
||||
* Get all options
|
||||
|
|
|
@ -3,10 +3,7 @@ package cc.ryanc.halo.service.impl;
|
|||
import cc.ryanc.halo.exception.MissingPropertyException;
|
||||
import cc.ryanc.halo.model.dto.OptionOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Option;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.PropertyEnum;
|
||||
import cc.ryanc.halo.model.enums.QnYunProperties;
|
||||
import cc.ryanc.halo.model.enums.ValueEnum;
|
||||
import cc.ryanc.halo.model.enums.*;
|
||||
import cc.ryanc.halo.model.params.OptionParam;
|
||||
import cc.ryanc.halo.repository.OptionRepository;
|
||||
import cc.ryanc.halo.service.OptionService;
|
||||
|
@ -50,7 +47,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
* @param source source
|
||||
*/
|
||||
@Override
|
||||
public void save(String key, String value, String source) {
|
||||
public void save(String key, String value, OptionSource source) {
|
||||
Assert.hasText(key, "Option key must not be blank");
|
||||
|
||||
if (StringUtils.isBlank(value)) {
|
||||
|
@ -68,7 +65,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
Option anOption = new Option();
|
||||
anOption.setOptionKey(key);
|
||||
anOption.setOptionValue(value);
|
||||
anOption.setOptionSource(source);
|
||||
anOption.setSource(source);
|
||||
return anOption;
|
||||
});
|
||||
|
||||
|
@ -83,7 +80,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
* @param source source
|
||||
*/
|
||||
@Override
|
||||
public void save(Map<String, String> options, String source) {
|
||||
public void save(Map<String, String> options, OptionSource source) {
|
||||
if (CollectionUtils.isEmpty(options)) {
|
||||
return;
|
||||
}
|
||||
|
@ -92,7 +89,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
}
|
||||
|
||||
@Override
|
||||
public void save(List<OptionParam> optionParams, String source) {
|
||||
public void save(List<OptionParam> optionParams, OptionSource source) {
|
||||
if (CollectionUtils.isEmpty(optionParams)) {
|
||||
return;
|
||||
}
|
||||
|
@ -102,7 +99,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
}
|
||||
|
||||
@Override
|
||||
public void saveProperties(Map<? extends PropertyEnum, String> properties, String source) {
|
||||
public void saveProperties(Map<? extends PropertyEnum, String> properties, OptionSource source) {
|
||||
if (CollectionUtils.isEmpty(properties)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cc.ryanc.halo.web.controller.admin.api;
|
||||
|
||||
import cc.ryanc.halo.model.dto.OptionOutputDTO;
|
||||
import cc.ryanc.halo.model.enums.OptionSource;
|
||||
import cc.ryanc.halo.model.params.OptionParam;
|
||||
import cc.ryanc.halo.service.OptionService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
@ -33,7 +34,7 @@ public class OptionController {
|
|||
|
||||
@PostMapping("saving")
|
||||
public void saveOptions(@Valid @RequestBody List<OptionParam> optionParams) {
|
||||
optionService.save(optionParams, "system");
|
||||
optionService.save(optionParams, OptionSource.SYSTEM);
|
||||
}
|
||||
|
||||
@GetMapping("map_view")
|
||||
|
@ -45,6 +46,6 @@ public class OptionController {
|
|||
@PostMapping("map_view/saving")
|
||||
@ApiOperation("Saves options by option map")
|
||||
public void saveOptionsWithMapView(@RequestBody Map<String, String> optionMap) {
|
||||
optionService.save(optionMap, "system");
|
||||
optionService.save(optionMap, OptionSource.SYSTEM);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cc.ryanc.halo.web.controller.admin.api;
|
||||
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.OptionSource;
|
||||
import cc.ryanc.halo.model.support.Theme;
|
||||
import cc.ryanc.halo.service.OptionService;
|
||||
import cc.ryanc.halo.service.ThemeService;
|
||||
|
@ -61,7 +62,7 @@ public class ThemeController {
|
|||
public void active(@RequestParam(name = "themeName", defaultValue = "anatole") String themeName) throws TemplateModelException {
|
||||
Map<BlogProperties, String> properties = new HashMap<>(1);
|
||||
properties.put(BlogProperties.THEME, themeName);
|
||||
optionService.saveProperties(properties, "system");
|
||||
optionService.saveProperties(properties, OptionSource.SYSTEM);
|
||||
BaseContentController.THEME = themeName;
|
||||
configuration.setSharedVariable("themeName", themeName);
|
||||
configuration.setSharedVariable("options", optionService.listOptions());
|
||||
|
|
|
@ -4,6 +4,7 @@ import cc.ryanc.halo.exception.BadRequestException;
|
|||
import cc.ryanc.halo.model.entity.*;
|
||||
import cc.ryanc.halo.model.enums.AttachmentType;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.OptionSource;
|
||||
import cc.ryanc.halo.model.params.InstallParam;
|
||||
import cc.ryanc.halo.model.support.BaseResponse;
|
||||
import cc.ryanc.halo.service.*;
|
||||
|
@ -175,7 +176,7 @@ public class InstallController {
|
|||
properties.put(BlogProperties.ATTACHMENT_TYPE, AttachmentType.LOCAL.getValue().toString());
|
||||
|
||||
// Create properties
|
||||
optionService.saveProperties(properties, "system");
|
||||
optionService.saveProperties(properties, OptionSource.SYSTEM);
|
||||
}
|
||||
|
||||
// /**
|
||||
|
|
Loading…
Reference in New Issue