mirror of https://github.com/halo-dev/halo
Perfect codes.
parent
9c0c610338
commit
11d798ffa3
|
@ -27,7 +27,7 @@ public class InMemoryCacheStore extends StringCacheStore {
|
||||||
/**
|
/**
|
||||||
* Cache container.
|
* Cache container.
|
||||||
*/
|
*/
|
||||||
private final static ConcurrentHashMap<String, CacheWrapper<String>> cacheContainer = new ConcurrentHashMap<>();
|
private final static ConcurrentHashMap<String, CacheWrapper<String>> CACHE_CONTAINER = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final Timer timer;
|
private final Timer timer;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public class InMemoryCacheStore extends StringCacheStore {
|
||||||
Optional<CacheWrapper<String>> getInternal(String key) {
|
Optional<CacheWrapper<String>> getInternal(String key) {
|
||||||
Assert.hasText(key, "Cache key must not be blank");
|
Assert.hasText(key, "Cache key must not be blank");
|
||||||
|
|
||||||
return Optional.ofNullable(cacheContainer.get(key));
|
return Optional.ofNullable(CACHE_CONTAINER.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,7 +55,7 @@ public class InMemoryCacheStore extends StringCacheStore {
|
||||||
Assert.notNull(cacheWrapper, "Cache wrapper must not be null");
|
Assert.notNull(cacheWrapper, "Cache wrapper must not be null");
|
||||||
|
|
||||||
// Put the cache wrapper
|
// Put the cache wrapper
|
||||||
CacheWrapper<String> putCacheWrapper = cacheContainer.put(key, cacheWrapper);
|
CacheWrapper<String> putCacheWrapper = CACHE_CONTAINER.put(key, cacheWrapper);
|
||||||
|
|
||||||
log.debug("Put [{}] cache result: [{}], original cache wrapper: [{}]", key, putCacheWrapper, cacheWrapper);
|
log.debug("Put [{}] cache result: [{}], original cache wrapper: [{}]", key, putCacheWrapper, cacheWrapper);
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ public class InMemoryCacheStore extends StringCacheStore {
|
||||||
public void delete(String key) {
|
public void delete(String key) {
|
||||||
Assert.hasText(key, "Cache key must not be blank");
|
Assert.hasText(key, "Cache key must not be blank");
|
||||||
|
|
||||||
cacheContainer.remove(key);
|
CACHE_CONTAINER.remove(key);
|
||||||
log.debug("Removed key: [{}]", key);
|
log.debug("Removed key: [{}]", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ public class InMemoryCacheStore extends StringCacheStore {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
cacheContainer.keySet().forEach(key -> {
|
CACHE_CONTAINER.keySet().forEach(key -> {
|
||||||
if (!InMemoryCacheStore.this.get(key).isPresent()) {
|
if (!InMemoryCacheStore.this.get(key).isPresent()) {
|
||||||
log.debug("Deleted the cache: [{}] for expiration", key);
|
log.debug("Deleted the cache: [{}] for expiration", key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,12 @@ public class Item {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Item item = (Item) o;
|
Item item = (Item) o;
|
||||||
return name.equals(item.name);
|
return name.equals(item.name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,8 +85,12 @@ public class ThemeProperty {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
ThemeProperty that = (ThemeProperty) o;
|
ThemeProperty that = (ThemeProperty) o;
|
||||||
return id.equals(that.id);
|
return id.equals(that.id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
||||||
|
|
||||||
Path source;
|
Path source;
|
||||||
|
|
||||||
if (themeUri.getScheme().equalsIgnoreCase("jar")) {
|
if ("jar".equalsIgnoreCase(themeUri.getScheme())) {
|
||||||
// Create new file system for jar
|
// Create new file system for jar
|
||||||
FileSystem fileSystem = FileSystems.newFileSystem(themeUri, Collections.emptyMap());
|
FileSystem fileSystem = FileSystems.newFileSystem(themeUri, Collections.emptyMap());
|
||||||
source = fileSystem.getPath("/BOOT-INF/classes/" + ThemeService.THEME_FOLDER);
|
source = fileSystem.getPath("/BOOT-INF/classes/" + ThemeService.THEME_FOLDER);
|
||||||
|
|
|
@ -43,8 +43,12 @@ public class PostCategory extends BaseEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
PostCategory that = (PostCategory) o;
|
PostCategory that = (PostCategory) o;
|
||||||
return categoryId.equals(that.categoryId) &&
|
return categoryId.equals(that.categoryId) &&
|
||||||
postId.equals(that.postId);
|
postId.equals(that.postId);
|
||||||
|
|
|
@ -44,8 +44,12 @@ public class PostTag extends BaseEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
PostTag postTag = (PostTag) o;
|
PostTag postTag = (PostTag) o;
|
||||||
return Objects.equals(postId, postTag.postId) &&
|
return Objects.equals(postId, postTag.postId) &&
|
||||||
Objects.equals(tagId, postTag.tagId);
|
Objects.equals(tagId, postTag.tagId);
|
||||||
|
|
|
@ -30,15 +30,15 @@ public enum Mode {
|
||||||
@Nullable
|
@Nullable
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public static Mode valueFrom(@Nullable String value) {
|
public static Mode valueFrom(@Nullable String value) {
|
||||||
if (StringUtils.isBlank(value) || value.equalsIgnoreCase("prod")) {
|
if (StringUtils.isBlank(value) || "prod".equalsIgnoreCase(value)) {
|
||||||
return Mode.PRODUCTION;
|
return Mode.PRODUCTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.equalsIgnoreCase("dev")) {
|
if ("dev".equalsIgnoreCase(value)) {
|
||||||
return Mode.DEVELOPMENT;
|
return Mode.DEVELOPMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.equalsIgnoreCase("test")) {
|
if ("test".equalsIgnoreCase(value)) {
|
||||||
return Mode.TEST;
|
return Mode.TEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,14 @@ package run.halo.app.model.properties;
|
||||||
*/
|
*/
|
||||||
public enum ApiProperties implements PropertyEnum {
|
public enum ApiProperties implements PropertyEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api_enabled
|
||||||
|
*/
|
||||||
API_ENABLED("api_enabled", Boolean.class, "false"),
|
API_ENABLED("api_enabled", Boolean.class, "false"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api_access_key
|
||||||
|
*/
|
||||||
API_ACCESS_KEY("api_access_key", String.class, "");
|
API_ACCESS_KEY("api_access_key", String.class, "");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
|
@ -10,6 +10,9 @@ import run.halo.app.model.enums.AttachmentType;
|
||||||
*/
|
*/
|
||||||
public enum AttachmentProperties implements PropertyEnum {
|
public enum AttachmentProperties implements PropertyEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* attachment_type
|
||||||
|
*/
|
||||||
ATTACHMENT_TYPE("attachment_type", AttachmentType.class, AttachmentType.LOCAL.name());
|
ATTACHMENT_TYPE("attachment_type", AttachmentType.class, AttachmentType.LOCAL.name());
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class BaseCommentWithParentVO extends BaseCommentDTO implements Cloneable
|
||||||
*/
|
*/
|
||||||
private BaseCommentWithParentVO parent;
|
private BaseCommentWithParentVO parent;
|
||||||
|
|
||||||
|
@Override
|
||||||
public BaseCommentWithParentVO clone() {
|
public BaseCommentWithParentVO clone() {
|
||||||
try {
|
try {
|
||||||
return (BaseCommentWithParentVO) super.clone();
|
return (BaseCommentWithParentVO) super.clone();
|
||||||
|
|
|
@ -29,5 +29,6 @@ public interface PostCommentRepository extends BaseCommentRepository<PostComment
|
||||||
"where comment.parentId in ?1 " +
|
"where comment.parentId in ?1 " +
|
||||||
"group by comment.parentId")
|
"group by comment.parentId")
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@Override
|
||||||
List<CommentChildrenCountProjection> findDirectChildrenCount(@NonNull Iterable<Long> commentIds);
|
List<CommentChildrenCountProjection> findDirectChildrenCount(@NonNull Iterable<Long> commentIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,5 +29,6 @@ public interface SheetCommentRepository extends BaseCommentRepository<SheetComme
|
||||||
"where comment.parentId in ?1 " +
|
"where comment.parentId in ?1 " +
|
||||||
"group by comment.parentId")
|
"group by comment.parentId")
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@Override
|
||||||
List<CommentChildrenCountProjection> findDirectChildrenCount(@NonNull Iterable<Long> commentIds);
|
List<CommentChildrenCountProjection> findDirectChildrenCount(@NonNull Iterable<Long> commentIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,5 +25,6 @@ public interface SheetRepository extends BasePostRepository<Sheet> {
|
||||||
Long countLike();
|
Long countLike();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@Override
|
||||||
Optional<Sheet> getByUrlAndStatus(@NonNull String url, @NonNull PostStatus status);
|
Optional<Sheet> getByUrlAndStatus(@NonNull String url, @NonNull PostStatus status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,7 +323,7 @@ public class AdminServiceImpl implements AdminService {
|
||||||
String contentType = aAssetMap.getOrDefault("content_type", "").toString();
|
String contentType = aAssetMap.getOrDefault("content_type", "").toString();
|
||||||
|
|
||||||
Object name = aAssetMap.getOrDefault("name", "");
|
Object name = aAssetMap.getOrDefault("name", "");
|
||||||
return name.toString().matches(HALO_ADMIN_VERSION_REGEX) && contentType.equalsIgnoreCase("application/zip");
|
return name.toString().matches(HALO_ADMIN_VERSION_REGEX) && "application/zip".equalsIgnoreCase(contentType);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -390,7 +390,7 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
|
||||||
Assert.notNull(toCompareComment, "Comment to compare must not be null");
|
Assert.notNull(toCompareComment, "Comment to compare must not be null");
|
||||||
|
|
||||||
// Get sort order
|
// Get sort order
|
||||||
Sort.Order order = sort.filter(anOrder -> anOrder.getProperty().equals("id"))
|
Sort.Order order = sort.filter(anOrder -> "id".equals(anOrder.getProperty()))
|
||||||
.get()
|
.get()
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseGet(() -> Sort.Order.desc("id"));
|
.orElseGet(() -> Sort.Order.desc("id"));
|
||||||
|
@ -404,6 +404,7 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@Override
|
||||||
public List<BaseCommentVO> convertToVo(@Nullable List<COMMENT> comments, @Nullable Comparator<BaseCommentVO> comparator) {
|
public List<BaseCommentVO> convertToVo(@Nullable List<COMMENT> comments, @Nullable Comparator<BaseCommentVO> comparator) {
|
||||||
if (CollectionUtils.isEmpty(comments)) {
|
if (CollectionUtils.isEmpty(comments)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
|
|
@ -200,7 +200,7 @@ public class RecoveryServiceImpl implements RecoveryService {
|
||||||
String postType = postMap.getOrDefault("postType", "post").toString();
|
String postType = postMap.getOrDefault("postType", "post").toString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (postType.equalsIgnoreCase("post")) {
|
if ("post".equalsIgnoreCase(postType)) {
|
||||||
// Handle post
|
// Handle post
|
||||||
result.add(handlePost(post, postMap));
|
result.add(handlePost(post, postMap));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue