From d16a1f8de6b36ba88cebec95c4b00c8aa9b4757a Mon Sep 17 00:00:00 2001 From: johnniang Date: Mon, 6 May 2019 22:47:42 +0800 Subject: [PATCH] Remove resolved TODO tasks --- .../admin/api/InstallController.java | 1 - .../app/handler/file/QnYunFileHandler.java | 3 - .../app/handler/file/SmmsFileHandler.java | 19 +++-- .../app/handler/file/UpYunFileHandler.java | 1 - .../theme/config/ThemeConfigResolvers.java | 72 ------------------- .../impl/YamlThemeConfigResolverImpl.java | 2 - .../halo/app/listener/StartedListener.java | 1 - .../method/RecentCommentsMethod.java | 1 + .../freemarker/method/RecentPostsMethod.java | 1 + .../app/service/impl/OptionServiceImpl.java | 30 ++++---- .../app/service/impl/RecoveryServiceImpl.java | 7 +- .../app/service/impl/ThemeServiceImpl.java | 4 +- .../java/run/halo/app/utils/BeanUtils.java | 1 - .../java/run/halo/app/utils/HaloUtils.java | 1 - .../run/halo/app/utils/HttpClientUtils.java | 1 - .../theme}/YamlThemePropertyResolverTest.java | 2 +- 16 files changed, 30 insertions(+), 117 deletions(-) delete mode 100644 src/main/java/run/halo/app/handler/theme/config/ThemeConfigResolvers.java rename src/{main/java/run/halo/app/handler/theme/config/impl => test/java/run/halo/app/handler/theme}/YamlThemePropertyResolverTest.java (95%) 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 3af534a6..cf7d22ed 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 @@ -78,7 +78,6 @@ public class InstallController { @ResponseBody @CacheLock public BaseResponse installBlog(@RequestBody @Valid InstallParam installParam) { - // TODO Install blog. // Check is installed boolean isInstalled = optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false); 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 8cb5d05a..63650cda 100644 --- a/src/main/java/run/halo/app/handler/file/QnYunFileHandler.java +++ b/src/main/java/run/halo/app/handler/file/QnYunFileHandler.java @@ -59,7 +59,6 @@ public class QnYunFileHandler implements FileHandler { String domain = optionService.getByPropertyOfNonNull(QnYunProperties.DOMAIN).toString(); String smallUrl = optionService.getByPropertyOrDefault(QnYunProperties.SMALL_URL, String.class, ""); - // TODO Consider to cache the configuration // Create configuration Configuration configuration = new Configuration(zone); @@ -88,7 +87,6 @@ public class QnYunFileHandler implements FileHandler { // Get upload manager UploadManager uploadManager = new UploadManager(configuration, fileRecorder); // Put the file - // TODO May need to set key manually Response response = uploadManager.put(file.getInputStream(), null, uploadToken, null, null); log.debug("QnYun response: [{}]", response.toString()); @@ -136,7 +134,6 @@ public class QnYunFileHandler implements FileHandler { String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY).toString(); String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET).toString(); - // TODO Consider to cache the configuration // Create configuration Configuration configuration = new Configuration(zone); diff --git a/src/main/java/run/halo/app/handler/file/SmmsFileHandler.java b/src/main/java/run/halo/app/handler/file/SmmsFileHandler.java index 937e3073..ec0fd7ab 100644 --- a/src/main/java/run/halo/app/handler/file/SmmsFileHandler.java +++ b/src/main/java/run/halo/app/handler/file/SmmsFileHandler.java @@ -1,22 +1,21 @@ package run.halo.app.handler.file; -import run.halo.app.exception.FileOperationException; -import run.halo.app.model.enums.AttachmentType; -import run.halo.app.model.support.UploadResult; -import run.halo.app.utils.FilenameUtils; -import run.halo.app.utils.HttpClientUtils; import lombok.Data; import lombok.NoArgsConstructor; import lombok.ToString; import lombok.extern.slf4j.Slf4j; import org.springframework.http.*; -import org.springframework.lang.NonNull; +import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; +import run.halo.app.exception.FileOperationException; import run.halo.app.model.enums.AttachmentType; +import run.halo.app.model.support.UploadResult; +import run.halo.app.utils.FilenameUtils; +import run.halo.app.utils.HttpClientUtils; import java.io.IOException; import java.util.Objects; @@ -89,7 +88,7 @@ public class SmmsFileHandler implements FileHandler { // Check error if (!isResponseSuccessfully(smmsResponse)) { log.error("Smms response detail: [{}]", smmsResponse); - throw new FileOperationException(smmsResponse.getMsg()).setErrorData(smmsResponse); + throw new FileOperationException(smmsResponse == null ? "Smms response is null" : smmsResponse.getMsg()).setErrorData(smmsResponse); } // Get response data @@ -149,10 +148,8 @@ public class SmmsFileHandler implements FileHandler { * @param smmsResponse smms response must not be null * @return true if response successfully; false otherwise */ - private boolean isResponseSuccessfully(@NonNull SmmsResponse smmsResponse) { - Assert.notNull(smmsResponse, "Smms response must not be null"); - - return smmsResponse.getCode().equals(SUCCESS_CODE); + private boolean isResponseSuccessfully(@Nullable SmmsResponse smmsResponse) { + return smmsResponse != null && smmsResponse.getCode().equals(SUCCESS_CODE); } @Data 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 4ea85e95..eea0bd2d 100644 --- a/src/main/java/run/halo/app/handler/file/UpYunFileHandler.java +++ b/src/main/java/run/halo/app/handler/file/UpYunFileHandler.java @@ -51,7 +51,6 @@ public class UpYunFileHandler implements FileHandler { UpYun upYun = new UpYun(ossBucket, ossOperator, ossPassword); upYun.setDebug(log.isDebugEnabled()); upYun.setTimeout(60); - // TODO Provide a property for choosing upYun.setApiDomain(UpYun.ED_AUTO); try { diff --git a/src/main/java/run/halo/app/handler/theme/config/ThemeConfigResolvers.java b/src/main/java/run/halo/app/handler/theme/config/ThemeConfigResolvers.java deleted file mode 100644 index 4d4ab094..00000000 --- a/src/main/java/run/halo/app/handler/theme/config/ThemeConfigResolvers.java +++ /dev/null @@ -1,72 +0,0 @@ -package run.halo.app.handler.theme.config; - -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; -import org.springframework.stereotype.Component; -import run.halo.app.handler.theme.config.impl.YamlThemeConfigResolverImpl; -import run.halo.app.handler.theme.config.support.Group; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Theme configuration resolver manager. - * - * @author johnniang - * @date 4/10/19 - */ -@Component -public class ThemeConfigResolvers { - - private final Map resolverMap = new ConcurrentHashMap<>(2); - - public ThemeConfigResolvers() { - resolverMap.put(ConfigType.YAML, new YamlThemeConfigResolverImpl()); - // TODO Add another theme config resolver - } - - /** - * Config type enum. - */ - public enum ConfigType { - - YAML, - - PROPERTY - } - - /** - * Resolves the content. - * - * @param content content must not be blank - * @param type config type - * @return a list of group - * @throws IOException throws when content conversion fails - */ - public List resolve(@NonNull String content, @Nullable ConfigType type) throws IOException { - ThemeConfigResolver resolver = getResolver(type); - - if (resolver == null) { - throw new UnsupportedOperationException("Unsupported theme config type: " + type); - } - - return resolver.resolve(content); - } - - /** - * Resolves the content. - * - * @param content content must not be blank - * @return a list of group - * @throws IOException throws when content conversion fails - */ - public List resolve(String content) throws IOException { - return resolve(content, ConfigType.YAML); - } - - private ThemeConfigResolver getResolver(@Nullable ConfigType type) { - return type == null ? null : resolverMap.get(type); - } -} diff --git a/src/main/java/run/halo/app/handler/theme/config/impl/YamlThemeConfigResolverImpl.java b/src/main/java/run/halo/app/handler/theme/config/impl/YamlThemeConfigResolverImpl.java index 187d2ab0..079b9cd3 100644 --- a/src/main/java/run/halo/app/handler/theme/config/impl/YamlThemeConfigResolverImpl.java +++ b/src/main/java/run/halo/app/handler/theme/config/impl/YamlThemeConfigResolverImpl.java @@ -172,7 +172,6 @@ public class YamlThemeConfigResolverImpl implements ThemeConfigResolver { // Build option Option option = new Option(); - // TODO Convert the value type option.setValue(optionMap.get("value")); option.setLabel(optionMap.get("label").toString()); @@ -192,7 +191,6 @@ public class YamlThemeConfigResolverImpl implements ThemeConfigResolver { Option option = new Option(); - // TODO Convert the value type option.setValue(key); option.setLabel(optionMap.get("label").toString()); diff --git a/src/main/java/run/halo/app/listener/StartedListener.java b/src/main/java/run/halo/app/listener/StartedListener.java index 2025ed41..aee1b127 100644 --- a/src/main/java/run/halo/app/listener/StartedListener.java +++ b/src/main/java/run/halo/app/listener/StartedListener.java @@ -58,7 +58,6 @@ public class StartedListener implements ApplicationListener impl return; } - // TODO Consider cache options with map - Option option = optionRepository.findByKey(key).map(anOption -> { - log.debug("Updating option key: [{}], value: from [{}] to [{}]", key, anOption.getValue(), value); - // Exist - anOption.setValue(value); - return anOption; - }).orElseGet(() -> { - log.debug("Creating option key: [{}], value: [{}]", key, value); - // Not exist - Option anOption = new Option(); - anOption.setKey(key); - anOption.setValue(value); - return anOption; - }); + Option option = optionRepository.findByKey(key) + .map(anOption -> { + log.debug("Updating option key: [{}], value: from [{}] to [{}]", key, anOption.getValue(), value); + // Exist + anOption.setValue(value); + return anOption; + }).orElseGet(() -> { + log.debug("Creating option key: [{}], value: [{}]", key, value); + // Not exist + Option anOption = new Option(); + anOption.setKey(key); + anOption.setValue(value); + return anOption; + }); // Save or update the options Option savedOption = optionRepository.save(option); @@ -96,7 +96,6 @@ public class OptionServiceImpl extends AbstractCrudService impl return; } - // TODO Optimize the queries options.forEach(this::save); publishOptionUpdatedEvent(); @@ -108,7 +107,6 @@ public class OptionServiceImpl extends AbstractCrudService impl return; } - // TODO Optimize the query optionParams.forEach(optionParam -> save(optionParam.getKey(), optionParam.getValue())); publishOptionUpdatedEvent(); diff --git a/src/main/java/run/halo/app/service/impl/RecoveryServiceImpl.java b/src/main/java/run/halo/app/service/impl/RecoveryServiceImpl.java index bf75af7c..08eff81d 100644 --- a/src/main/java/run/halo/app/service/impl/RecoveryServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/RecoveryServiceImpl.java @@ -92,7 +92,6 @@ public class RecoveryServiceImpl implements RecoveryService { @Override @Async public void migrateFromV0_4_3(MultipartFile file) { - // TODO Async execution // Get migration content try { String migrationContent = FileCopyUtils.copyToString(new InputStreamReader(file.getInputStream())); @@ -192,10 +191,10 @@ public class RecoveryServiceImpl implements RecoveryService { try { if (postType.equalsIgnoreCase("post")) { - // TODO Handle post + // Handle post result.add(handlePost(post, postMap)); } else { - // TODO Handle page + // Handle page result.add(handleSheet(post, postMap)); } } catch (Exception e) { @@ -244,7 +243,7 @@ public class RecoveryServiceImpl implements RecoveryService { Sheet createdSheet = sheetService.createOrUpdateBy(sheet); Object commentsObject = postMap.get("comments"); - // TODO Handle comments + // Handle comments List baseComments = handleComment(commentsObject, createdSheet.getId()); List sheetComments = baseComments.stream() 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 f16dad8c..6a608215 100644 --- a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java @@ -47,6 +47,8 @@ import java.util.zip.ZipInputStream; import static run.halo.app.model.support.HaloConst.DEFAULT_THEME_ID; /** + * Theme service implementation. + * * @author ryanwang * @date : 2019/3/26 */ @@ -250,8 +252,6 @@ public class ThemeServiceImpl implements ThemeService { public List fetchConfig(String themeId) { Assert.hasText(themeId, "Theme id must not be blank"); - // TODO Cache the config - // Get theme property ThemeProperty themeProperty = getThemeOfNonNullBy(themeId); diff --git a/src/main/java/run/halo/app/utils/BeanUtils.java b/src/main/java/run/halo/app/utils/BeanUtils.java index 7ee7e8ce..d20447d4 100644 --- a/src/main/java/run/halo/app/utils/BeanUtils.java +++ b/src/main/java/run/halo/app/utils/BeanUtils.java @@ -43,7 +43,6 @@ public class BeanUtils { // Init the instance try { // New instance for the target class - // TODO Class.newInstance() is deprecated in Java 9 T targetInstance = targetClass.newInstance(); // Copy properties org.springframework.beans.BeanUtils.copyProperties(source, targetInstance, getNullPropertyNames(source)); diff --git a/src/main/java/run/halo/app/utils/HaloUtils.java b/src/main/java/run/halo/app/utils/HaloUtils.java index 6e54f272..857f05b3 100755 --- a/src/main/java/run/halo/app/utils/HaloUtils.java +++ b/src/main/java/run/halo/app/utils/HaloUtils.java @@ -118,7 +118,6 @@ public class HaloUtils { if (!StringUtils.isBlank(url)) { return url; } - // TODO Consider to UUID return String.valueOf(System.currentTimeMillis()); } diff --git a/src/main/java/run/halo/app/utils/HttpClientUtils.java b/src/main/java/run/halo/app/utils/HttpClientUtils.java index 3ba0ad69..79a9cdb9 100644 --- a/src/main/java/run/halo/app/utils/HttpClientUtils.java +++ b/src/main/java/run/halo/app/utils/HttpClientUtils.java @@ -40,7 +40,6 @@ public class HttpClientUtils { */ @NonNull public static CloseableHttpClient createHttpsClient(int timeout) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { - // TODO Set key store in production environment SSLContext sslContext = new SSLContextBuilder() .loadTrustMaterial(null, (certificate, authType) -> true) .build(); diff --git a/src/main/java/run/halo/app/handler/theme/config/impl/YamlThemePropertyResolverTest.java b/src/test/java/run/halo/app/handler/theme/YamlThemePropertyResolverTest.java similarity index 95% rename from src/main/java/run/halo/app/handler/theme/config/impl/YamlThemePropertyResolverTest.java rename to src/test/java/run/halo/app/handler/theme/YamlThemePropertyResolverTest.java index 521b4751..e5a9d95c 100644 --- a/src/main/java/run/halo/app/handler/theme/config/impl/YamlThemePropertyResolverTest.java +++ b/src/test/java/run/halo/app/handler/theme/YamlThemePropertyResolverTest.java @@ -1,4 +1,4 @@ -package run.halo.app.handler.theme.config.impl; +package run.halo.app.handler.theme; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -- GitLab