Change cn.hutool.core.lang.Assert to org.springframework.util.Assert.

pull/165/head
ruibaby 2019-05-18 09:36:10 +08:00
parent 8a19e1c907
commit e68ce3afee
8 changed files with 68 additions and 24 deletions

View File

@ -140,4 +140,9 @@ public class ThemeController {
public void reload() { public void reload() {
themeService.reload(); themeService.reload();
} }
@GetMapping(value = "activation/template/exists")
public BaseResponse exists(@RequestParam(value = "template") String template) {
return BaseResponse.ok(themeService.templateExists(template));
}
} }

View File

@ -1,8 +1,8 @@
package run.halo.app.event.post; package run.halo.app.event.post;
import cn.hutool.core.lang.Assert;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import run.halo.app.service.base.BasePostService; import run.halo.app.service.base.BasePostService;
import java.util.Map; import java.util.Map;

View File

@ -1,13 +1,14 @@
package run.halo.app.handler.file; package run.halo.app.handler.file;
import cn.hutool.core.lang.Assert;
import com.aliyun.oss.OSS; import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder; import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.*; import com.aliyun.oss.model.DeleteObjectsRequest;
import com.aliyun.oss.model.PutObjectResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import run.halo.app.exception.FileOperationException; import run.halo.app.exception.FileOperationException;
import run.halo.app.model.enums.AttachmentType; import run.halo.app.model.enums.AttachmentType;
@ -18,11 +19,11 @@ import run.halo.app.utils.FilenameUtils;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.Date;
import java.util.Objects; import java.util.Objects;
/** /**
* AliYun file handler. * AliYun file handler.
*
* @author MyFaith * @author MyFaith
* @date 2019-04-04 00:06:13 * @date 2019-04-04 00:06:13
*/ */
@ -81,7 +82,7 @@ public class AliYunFileHandler implements FileHandler {
} }
return uploadResult; return uploadResult;
} catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
ossClient.shutdown(); ossClient.shutdown();

View File

@ -1,15 +1,14 @@
package run.halo.app.security.handler; package run.halo.app.security.handler;
import run.halo.app.exception.HaloException;
import run.halo.app.model.support.BaseResponse;
import run.halo.app.utils.ExceptionUtils;
import run.halo.app.utils.JsonUtils;
import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.extra.servlet.ServletUtil;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import run.halo.app.exception.HaloException; import run.halo.app.exception.HaloException;
import run.halo.app.model.support.BaseResponse;
import run.halo.app.utils.ExceptionUtils;
import run.halo.app.utils.JsonUtils;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;

View File

@ -1,11 +1,11 @@
package run.halo.app.service.impl; package run.halo.app.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import run.halo.app.exception.NotFoundException; import run.halo.app.exception.NotFoundException;
import run.halo.app.model.dto.JournalDTO; import run.halo.app.model.dto.JournalDTO;
import run.halo.app.model.entity.Journal; import run.halo.app.model.entity.Journal;

View File

@ -1,12 +1,12 @@
package run.halo.app.service.impl; package run.halo.app.service.impl;
import cn.hutool.core.lang.Assert;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;

View File

@ -1,6 +1,5 @@
package run.halo.app.service.impl; package run.halo.app.service.impl;
import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
@ -28,7 +27,6 @@ import run.halo.app.model.support.HaloConst;
import run.halo.app.model.support.ThemeFile; import run.halo.app.model.support.ThemeFile;
import run.halo.app.service.OptionService; import run.halo.app.service.OptionService;
import run.halo.app.service.ThemeService; import run.halo.app.service.ThemeService;
import run.halo.app.service.support.HaloMediaType;
import run.halo.app.utils.FileUtils; import run.halo.app.utils.FileUtils;
import run.halo.app.utils.FilenameUtils; import run.halo.app.utils.FilenameUtils;
import run.halo.app.utils.HaloUtils; import run.halo.app.utils.HaloUtils;
@ -248,7 +246,7 @@ public class ThemeServiceImpl implements ThemeService {
try { try {
// Delete the folder // Delete the folder
FileUtil.del(Paths.get(themeProperty.getThemePath())); FileUtils.del(Paths.get(themeProperty.getThemePath()));
// Delete theme cache // Delete theme cache
eventPublisher.publishEvent(new ThemeUpdatedEvent(this)); eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
@ -329,6 +327,16 @@ public class ThemeServiceImpl implements ThemeService {
return activatedTheme; return activatedTheme;
} }
/**
* Sets activated theme.
*
* @param activatedTheme activated theme
*/
private void setActivatedTheme(@Nullable ThemeProperty activatedTheme) {
this.activatedTheme = activatedTheme;
this.activatedThemeId = Optional.ofNullable(activatedTheme).map(ThemeProperty::getId).orElse(null);
}
@Override @Override
public ThemeProperty activateTheme(String themeId) { public ThemeProperty activateTheme(String themeId) {
// Check existence of the theme // Check existence of the theme
@ -513,16 +521,6 @@ public class ThemeServiceImpl implements ThemeService {
return Files.createTempDirectory("halo"); return Files.createTempDirectory("halo");
} }
/**
* Sets activated theme.
*
* @param activatedTheme activated theme
*/
private void setActivatedTheme(@Nullable ThemeProperty activatedTheme) {
this.activatedTheme = activatedTheme;
this.activatedThemeId = Optional.ofNullable(activatedTheme).map(ThemeProperty::getId).orElse(null);
}
/** /**
* Lists theme files as tree view. * Lists theme files as tree view.
* *

View File

@ -1,5 +1,6 @@
package run.halo.app.utils; package run.halo.app.utils;
import cn.hutool.core.io.IORuntimeException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -259,4 +260,44 @@ public class FileUtils {
log.warn("Failed to delete " + deletingPath); log.warn("Failed to delete " + deletingPath);
} }
} }
/**
*
*
* @param path path
* @return boolean
* @throws IORuntimeException IORuntimeException
*/
public static boolean del(Path path) throws IORuntimeException {
if (Files.notExists(path)) {
return true;
}
try {
if (Files.isDirectory(path)) {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
if (e == null) {
Files.delete(dir);
return FileVisitResult.CONTINUE;
} else {
throw e;
}
}
});
} else {
Files.delete(path);
}
} catch (IOException e) {
throw new IORuntimeException(e);
}
return true;
}
} }