Skip to content
Permalink
Browse files

Refactor runtime mode conversion

  • Loading branch information...
JohnNiang committed Jun 10, 2019
1 parent 186611d commit 5b2591b5c33d1c2d93bc5c2116ac08470d38d0e7
@@ -1,6 +1,7 @@
package run.halo.app.model.dto;

import lombok.Data;
import run.halo.app.model.enums.Mode;

/**
* Theme controller.
@@ -17,5 +18,5 @@

private String version;

private String mode;
private Mode mode;
}
@@ -0,0 +1,47 @@
package run.halo.app.model.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.Nullable;

/**
* Halo runtime mode.
*
* @author johnniang
* @date 19-6-10
*/
public enum Mode {
PRODUCTION,
DEVELOPMENT,
TEST;

@JsonValue
String getValue() {
return this.name().toLowerCase();
}

/**
* Get mode from value.
*
* @param value mode value
* @return runtime mode or null if the value is mismatch
*/
@Nullable
@JsonCreator
public static Mode valueFrom(@Nullable String value) {
if (StringUtils.isBlank(value) || value.equalsIgnoreCase("prod")) {
return Mode.PRODUCTION;
}

if (value.equalsIgnoreCase("dev")) {
return Mode.DEVELOPMENT;
}

if (value.equalsIgnoreCase("test")) {
return Mode.TEST;
}

return null;
}
}
@@ -23,7 +23,7 @@
public final static String DEFAULT_THEME_ID = "caicai_anatole";

/**
* version constant
* Version constant. (Available in production environment)
*/
public static final String HALO_VERSION;

@@ -42,6 +42,7 @@
* @param name name
* @return Category
*/
@Nullable
Category getByName(@NonNull String name);

/**
@@ -15,6 +15,7 @@
import run.halo.app.model.dto.StatisticDTO;
import run.halo.app.model.entity.User;
import run.halo.app.model.enums.CommentStatus;
import run.halo.app.model.enums.Mode;
import run.halo.app.model.enums.PostStatus;
import run.halo.app.model.params.LoginParam;
import run.halo.app.model.support.HaloConst;
@@ -78,7 +79,7 @@ public AdminServiceImpl(PostService postService,
StringCacheStore cacheStore,
ApplicationEventPublisher eventPublisher,
@Value("${spring.datasource.driver-class-name}") String driverClassName,
@Value("${spring.profiles.active}") String mode) {
@Value("${spring.profiles.active:prod}") String mode) {
this.postService = postService;
this.sheetService = sheetService;
this.attachmentService = attachmentService;
@@ -194,11 +195,7 @@ public EnvironmentDTO getEnvironments() {

environmentDTO.setVersion(HaloConst.HALO_VERSION);

if (StringUtils.isNotEmpty(mode)) {
environmentDTO.setMode(StringUtils.equals("dev", mode) ? "development" : "production");
} else {
environmentDTO.setMode("test");
}
environmentDTO.setMode(Mode.valueFrom(this.mode));

return environmentDTO;
}
@@ -214,9 +211,8 @@ public AuthToken refreshToken(String refreshToken) {
User user = userService.getById(userId);

// Remove all token
cacheStore.getAny(SecurityUtils.buildAccessTokenKey(user), String.class).ifPresent(accessToken -> {
cacheStore.delete(SecurityUtils.buildTokenAccessKey(accessToken));
});
cacheStore.getAny(SecurityUtils.buildAccessTokenKey(user), String.class)
.ifPresent(accessToken -> cacheStore.delete(SecurityUtils.buildTokenAccessKey(accessToken)));
cacheStore.delete(SecurityUtils.buildTokenRefreshKey(refreshToken));
cacheStore.delete(SecurityUtils.buildAccessTokenKey(user));
cacheStore.delete(SecurityUtils.buildRefreshTokenKey(user));
@@ -8,6 +8,7 @@
import run.halo.app.service.PostService;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* Backup service implementation.
@@ -28,7 +29,7 @@ public BackupServiceImpl(PostService postService) {
public BasePostDetailDTO importMarkdowns(MultipartFile file) throws IOException {

// Read markdown content.
String markdown = IoUtil.read(file.getInputStream(), "UTF-8");
String markdown = IoUtil.read(file.getInputStream(), StandardCharsets.UTF_8);

// TODO sheet import

@@ -340,6 +340,7 @@ public PostDetailVO importMarkdown(String markdown, String filename) {
category = categoryService.create(category);
}
categoryIds.add(category.getId());
break;
default:
break;
}

0 comments on commit 5b2591b

Please sign in to comment.
You can’t perform that action at this time.