Remove source column of Option entity

pull/146/head
johnniang 2019-04-08 23:37:00 +08:00
parent 1fe26cb7d8
commit f87dc413e3
10 changed files with 74 additions and 55 deletions

View File

@ -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;
}
}
}

View File

@ -6,6 +6,7 @@ package run.halo.app.model.enums;
* @author johnniang
* @date 4/1/19
*/
@Deprecated
public enum OptionSource implements ValueEnum<Integer> {
SYSTEM(0),
@ -20,4 +21,5 @@ public enum OptionSource implements ValueEnum<Integer> {
@Override
public Integer getValue() {
return null;
}}
}
}

View File

@ -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<ThemeSetting, Integer> {
}

View File

@ -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<Option, Integer> {
/**
* 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<String, String> options, @NonNull OptionSource source);
void save(@Nullable Map<String, String> options);
/**
* SAve multiple options
*
* @param optionParams option params
* @param source source
*/
@Transactional
void save(List<OptionParam> optionParams, @NonNull OptionSource source);
void save(@Nullable List<OptionParam> 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<? extends PropertyEnum, String> properties, @NonNull OptionSource source);
void saveProperties(@NonNull Map<? extends PropertyEnum, String> properties);
/**
* Get all options

View File

@ -0,0 +1,11 @@
package run.halo.app.service;
/**
* Theme setting service interface.
*
* @author johnniang
* @date 4/8/19
*/
public interface ThemeSettingService {
}

View File

@ -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<Option, Integer> 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<Option, Integer> 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<Option, Integer> impl
log.debug("Saved option: [{}]", savedOption);
}
/**
* Saves multiple options
*
* @param options options
* @param source source
*/
@Override
public void save(Map<String, String> options, OptionSource source) {
public void save(Map<String, String> 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<OptionParam> optionParams, OptionSource source) {
public void save(List<OptionParam> 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<? extends PropertyEnum, String> properties, OptionSource source) {
public void saveProperties(Map<? extends PropertyEnum, String> properties) {
if (CollectionUtils.isEmpty(properties)) {
return;
}
properties.forEach((property, value) -> save(property.getValue(), value, source));
properties.forEach((property, value) -> save(property.getValue(), value));
}
/**

View File

@ -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<ThemeSetting, Integer> implements ThemeSettingService {
private final ThemeSettingRepository themeSettingRepository;
public ThemeSettingServiceImpl(ThemeSettingRepository themeSettingRepository) {
super(themeSettingRepository);
this.themeSettingRepository = themeSettingRepository;
}
}

View File

@ -37,7 +37,7 @@ public class OptionController {
@PostMapping("saving")
public void saveOptions(@Valid @RequestBody List<OptionParam> 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<String, String> optionMap) {
optionService.save(optionMap, OptionSource.SYSTEM);
optionService.save(optionMap);
}
}

View File

@ -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());
}

View File

@ -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);
}
}