diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6dcf8dd..f52383d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,12 +29,6 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Qodana Scan - uses: JetBrains/qodana-action@v2024.1 - env: - QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} - - name: "Print maven version" - run: mvn -version - name: Build with Maven run: mvn clean test - name: Upload test results to Codecov diff --git a/base-framework-cache-starter/src/test/java/com/fuhouyu/framework/cache/CacheServiceTest.java b/base-framework-cache-starter/src/test/java/com/fuhouyu/framework/cache/CacheServiceTest.java index b5dbd05..39e1cdd 100644 --- a/base-framework-cache-starter/src/test/java/com/fuhouyu/framework/cache/CacheServiceTest.java +++ b/base-framework-cache-starter/src/test/java/com/fuhouyu/framework/cache/CacheServiceTest.java @@ -62,7 +62,7 @@ void setup() { } @Test - void testStringCache() throws InterruptedException { + void testStringCache() { cacheService.set(cacheBigKey, cacheValue); assertEquals(cacheValue, cacheService.get(cacheBigKey)); @@ -71,8 +71,6 @@ void testStringCache() throws InterruptedException { cacheService.set(cacheBigKey, cacheValue, 3, TimeUnit.SECONDS); assertEquals(cacheValue, cacheService.get(cacheBigKey)); - Thread.sleep(1000 * 3); - assertNull(cacheService.get(cacheBigKey)); List list = List.of(cacheValue); cacheService.set(cacheBigKey, list); @@ -82,7 +80,7 @@ void testStringCache() throws InterruptedException { } @Test - void testHashCache() throws InterruptedException { + void testHashCache() { String hashKey = UUID.randomUUID().toString().replace("-", "").substring(8); cacheService.putHash(cacheBigKey, hashKey, cacheValue); assertEquals(cacheValue, cacheService.getHash(cacheBigKey, hashKey)); @@ -96,8 +94,6 @@ void testHashCache() throws InterruptedException { cacheService.putHash(cacheBigKey, hashKey, cacheValue, 3, TimeUnit.SECONDS); assertEquals(cacheValue, cacheService.getHash(cacheBigKey, hashKey)); - Thread.sleep(1000 * 3); - assertNull(cacheService.getHash(cacheBigKey, hashKey)); List list = List.of(cacheValue); cacheService.putHash(cacheBigKey, hashKey, list); @@ -108,7 +104,7 @@ void testHashCache() throws InterruptedException { } @Test - void testSetCache() throws InterruptedException { + void testSetCache() { cacheService.addToSet(cacheBigKey, cacheValue); cacheService.getSet(cacheBigKey).forEach(value -> assertEquals(cacheValue, value)); @@ -116,12 +112,10 @@ void testSetCache() throws InterruptedException { cacheService.addToSet(cacheBigKey, cacheValue, 3, TimeUnit.SECONDS); cacheService.getSet(cacheBigKey).forEach(value -> assertEquals(cacheValue, value)); - Thread.sleep(1000 * 3); - assertTrue(cacheService.getSet(cacheBigKey).isEmpty()); } @Test - void testListCache() throws InterruptedException { + void testListCache() { cacheService.pushToList(cacheBigKey, cacheValue); cacheService.getList(cacheBigKey).forEach(value -> assertEquals(cacheValue, value)); @@ -129,8 +123,6 @@ void testListCache() throws InterruptedException { cacheService.pushToList(cacheBigKey, cacheValue, 3, TimeUnit.SECONDS); cacheService.getList(cacheBigKey).forEach(value -> assertEquals(cacheValue, value)); - Thread.sleep(1000 * 3); - assertTrue(cacheService.getList(cacheBigKey).isEmpty()); } @Test diff --git a/base-framework-common/src/main/java/com/fuhouyu/framework/constants/ConfigPropertiesConstant.java b/base-framework-common/src/main/java/com/fuhouyu/framework/constants/ConfigPropertiesConstant.java index 6541b71..a4cf895 100644 --- a/base-framework-common/src/main/java/com/fuhouyu/framework/constants/ConfigPropertiesConstant.java +++ b/base-framework-common/src/main/java/com/fuhouyu/framework/constants/ConfigPropertiesConstant.java @@ -24,11 +24,15 @@ * @author fuhouyu * @since 2024/8/14 12:57 */ -public interface ConfigPropertiesConstant { +public class ConfigPropertiesConstant { /** * 配置类的前缀 */ - String PROPERTIES_PREFIX = "base.framework."; + public static final String PROPERTIES_PREFIX = "base.framework."; + + private ConfigPropertiesConstant() { + + } } diff --git a/base-framework-common/src/main/java/com/fuhouyu/framework/constants/HttpRequestHeaderConstant.java b/base-framework-common/src/main/java/com/fuhouyu/framework/constants/HttpRequestHeaderConstant.java index 51f7cee..8fd08ab 100644 --- a/base-framework-common/src/main/java/com/fuhouyu/framework/constants/HttpRequestHeaderConstant.java +++ b/base-framework-common/src/main/java/com/fuhouyu/framework/constants/HttpRequestHeaderConstant.java @@ -24,49 +24,48 @@ * @author fuhouyu * @since 2024/8/15 19:54 */ -public interface HttpRequestHeaderConstant { +public class HttpRequestHeaderConstant { - // 自定义请求头 /** * 自定义的用户详情请求头 */ - String USERINFO_HEADER = "X-Custom-Userinfo"; - - // 标准请求头 + public static final String USERINFO_HEADER = "X-Custom-Userinfo"; + // 自定义请求头 /** * 客户端版本 */ - String CLIENT_VERSION_HEADER = "Client-Version"; + public static final String CLIENT_VERSION_HEADER = "Client-Version"; + // 标准请求头 /** * 用户代理 */ - String USER_AGENT_HEADER = "User-Agent"; - + public static final String USER_AGENT_HEADER = "User-Agent"; /** * 消息内容类型 */ - String CONTENT_TYPE = "Content-Type"; - + public static final String CONTENT_TYPE = "Content-Type"; /** * 消息内容长度 */ - String CONTENT_LENGTH = "Content-Length"; - + public static final String CONTENT_LENGTH = "Content-Length"; /** * 消息内容编码 */ - String CONTENT_ENCODING = "Content-Encoding"; - - // nginx转发的请求头 + public static final String CONTENT_ENCODING = "Content-Encoding"; /** * 真实ip地址 */ - String X_REAL_IP = "X-Real-IP"; + public static final String X_REAL_IP = "X-Real-IP"; + // nginx转发的请求头 /** * 来自 */ - String X_FORWARDED_FOR = "X-Forwarded-For"; + public static final String X_FORWARDED_FOR = "X-Forwarded-For"; + + private HttpRequestHeaderConstant() { + + } } diff --git a/base-framework-common/src/main/java/com/fuhouyu/framework/exception/FileException.java b/base-framework-common/src/main/java/com/fuhouyu/framework/exception/FileException.java new file mode 100644 index 0000000..cb06fa2 --- /dev/null +++ b/base-framework-common/src/main/java/com/fuhouyu/framework/exception/FileException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.fuhouyu.framework.exception; + +/** + *

+ * 文件异常 + *

+ * + * @author fuhouyu + * @since 2024/10/6 11:32 + */ +public class FileException extends RuntimeException { + + public FileException() { + this(null); + } + + public FileException(Throwable cause) { + super("Cannot parse JSON", cause); + } +} diff --git a/base-framework-common/src/main/java/com/fuhouyu/framework/response/RestResult.java b/base-framework-common/src/main/java/com/fuhouyu/framework/response/RestResult.java index 09a8ecc..54914a5 100644 --- a/base-framework-common/src/main/java/com/fuhouyu/framework/response/RestResult.java +++ b/base-framework-common/src/main/java/com/fuhouyu/framework/response/RestResult.java @@ -63,7 +63,7 @@ public class RestResult implements Serializable { * 响应数据 */ @Schema(name = "data", description = "响应数据,该值可能为空", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private T data; + private transient T data; private RestResult() { diff --git a/base-framework-common/src/main/java/com/fuhouyu/framework/utils/ClassUtils.java b/base-framework-common/src/main/java/com/fuhouyu/framework/utils/ClassUtils.java index 25b08b5..9e48448 100644 --- a/base-framework-common/src/main/java/com/fuhouyu/framework/utils/ClassUtils.java +++ b/base-framework-common/src/main/java/com/fuhouyu/framework/utils/ClassUtils.java @@ -41,7 +41,7 @@ public static Class loadClass(String className) { try { return (Class) Class.forName(className); } catch (ClassNotFoundException e) { - throw new RuntimeException(String.format("%s class not found", className), e); + throw new IllegalArgumentException(String.format("%s class not found", className), e); } } } diff --git a/base-framework-common/src/main/java/com/fuhouyu/framework/utils/FileUtil.java b/base-framework-common/src/main/java/com/fuhouyu/framework/utils/FileUtil.java index 5276626..ebba8ee 100644 --- a/base-framework-common/src/main/java/com/fuhouyu/framework/utils/FileUtil.java +++ b/base-framework-common/src/main/java/com/fuhouyu/framework/utils/FileUtil.java @@ -17,6 +17,9 @@ package com.fuhouyu.framework.utils; +import com.fuhouyu.framework.exception.FileException; +import lombok.NonNull; + import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -59,7 +62,7 @@ public static void createDirectorIfNotExists(Path path) { try { Files.createDirectories(path); } catch (IOException e) { - throw new RuntimeException(e); + throw new FileException(e); } } @@ -72,7 +75,7 @@ public static void deleteFileIfExists(Path path) { try { Files.deleteIfExists(path); } catch (IOException e) { - throw new RuntimeException(e); + throw new FileException(e); } } @@ -186,13 +189,15 @@ public static void deleteDirect(Path directPath) throws IOException { } Files.walkFileTree(directPath, new SimpleFileVisitor<>() { @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + @NonNull + public FileVisitResult visitFile(@NonNull Path file, @NonNull BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override + @NonNull public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (exc == null) { Files.delete(dir); @@ -265,7 +270,7 @@ public static String calculateFileDigest(Path path, } return HexUtil.encodeToHexString(digest.digest()); } catch (IOException e) { - throw new RuntimeException(e); + throw new FileException(e); } } diff --git a/base-framework-common/src/main/java/com/fuhouyu/framework/utils/JacksonUtil.java b/base-framework-common/src/main/java/com/fuhouyu/framework/utils/JacksonUtil.java index 1bac51b..6017e87 100644 --- a/base-framework-common/src/main/java/com/fuhouyu/framework/utils/JacksonUtil.java +++ b/base-framework-common/src/main/java/com/fuhouyu/framework/utils/JacksonUtil.java @@ -43,6 +43,10 @@ */ public class JacksonUtil { + private JacksonUtil() { + + } + private static final ObjectMapper OBJECT_MAPPER; static { diff --git a/base-framework-context/src/main/java/com/fuhouyu/framework/context/AbstractThredLocalContextHolderStrategy.java b/base-framework-context/src/main/java/com/fuhouyu/framework/context/AbstractThredLocalContextHolderStrategy.java index 83e5b0e..4040c32 100644 --- a/base-framework-context/src/main/java/com/fuhouyu/framework/context/AbstractThredLocalContextHolderStrategy.java +++ b/base-framework-context/src/main/java/com/fuhouyu/framework/context/AbstractThredLocalContextHolderStrategy.java @@ -26,30 +26,30 @@ */ public abstract class AbstractThredLocalContextHolderStrategy implements ContextHolderStrategy> { - private final ThreadLocal> THREAD_LOCAL; + private final ThreadLocal> threadLocal; protected AbstractThredLocalContextHolderStrategy(ThreadLocal> threadLocal) { - THREAD_LOCAL = threadLocal; + this.threadLocal = threadLocal; } @Override public void clearContext() { - THREAD_LOCAL.remove(); + threadLocal.remove(); } @Override public Context getContext() { - return THREAD_LOCAL.get(); + return threadLocal.get(); } @Override public void setContext(Context context) { - THREAD_LOCAL.set(context); + threadLocal.set(context); } @Override public Boolean isEmptyContext() { - return THREAD_LOCAL.get() == null; + return threadLocal.get() == null; } } diff --git a/base-framework-context/src/main/java/com/fuhouyu/framework/context/request/RequestContextHolder.java b/base-framework-context/src/main/java/com/fuhouyu/framework/context/request/RequestContextHolder.java index d3f2c12..eff1401 100644 --- a/base-framework-context/src/main/java/com/fuhouyu/framework/context/request/RequestContextHolder.java +++ b/base-framework-context/src/main/java/com/fuhouyu/framework/context/request/RequestContextHolder.java @@ -31,6 +31,10 @@ */ public class RequestContextHolder { + private RequestContextHolder() { + + } + private static final ContextHolderStrategy> CONTEXT_HOLDER_STRATEGY; static { diff --git a/base-framework-context/src/main/java/com/fuhouyu/framework/context/user/DefaultUserDetail.java b/base-framework-context/src/main/java/com/fuhouyu/framework/context/user/DefaultUserDetail.java index aa0b79a..4fd87a5 100644 --- a/base-framework-context/src/main/java/com/fuhouyu/framework/context/user/DefaultUserDetail.java +++ b/base-framework-context/src/main/java/com/fuhouyu/framework/context/user/DefaultUserDetail.java @@ -53,6 +53,6 @@ public class DefaultUserDetail implements Serializable, User { private String refAccountId; - private Map additionalInformation; + private transient Map additionalInformation; } diff --git a/base-framework-context/src/main/java/com/fuhouyu/framework/context/user/UserContextHolder.java b/base-framework-context/src/main/java/com/fuhouyu/framework/context/user/UserContextHolder.java index d8c691e..812b13b 100644 --- a/base-framework-context/src/main/java/com/fuhouyu/framework/context/user/UserContextHolder.java +++ b/base-framework-context/src/main/java/com/fuhouyu/framework/context/user/UserContextHolder.java @@ -31,6 +31,10 @@ */ public class UserContextHolder { + private UserContextHolder() { + + } + private static final ContextHolderStrategy> CONTEXT_HOLDER_STRATEGY; static { diff --git a/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/DefaultKmsAutoConfigure.java b/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/DefaultKmsAutoConfigure.java index 50bee7b..6e25872 100644 --- a/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/DefaultKmsAutoConfigure.java +++ b/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/DefaultKmsAutoConfigure.java @@ -56,7 +56,6 @@ @ConditionalOnMissingBean(KmsService.class) @EnableConfigurationProperties(KmsDefaultProperties.class) public class DefaultKmsAutoConfigure { - private static final String SM2_KEYPAIR_STORE_PATH = "/tmp/keypair"; private final KmsDefaultProperties properties; @@ -162,12 +161,11 @@ private CMac initCmac(SM4 sm4) { */ private SM2 generatorSm2() { KmsDefaultProperties.Sm2Properties sm2Properties = this.properties.getSm2(); - if (!sm2Properties.getAutoGenerate()) { + if (Boolean.FALSE.equals(sm2Properties.getAutoGenerate())) { throw new KmsException("sm2 公私钥未设置,且未启用自动生成"); } - String parentPath = Objects.isNull(sm2Properties.getAutoGenerateLocalPath()) ? - SM2_KEYPAIR_STORE_PATH : sm2Properties.getAutoGenerateLocalPath(); + String parentPath = sm2Properties.getAutoGenerateLocalPath(); Path publicKeyPath = Path.of(parentPath, "publicKey"); Path privateKeyPath = Path.of(parentPath, "privateKey"); if (Files.exists(publicKeyPath) && Files.exists(privateKeyPath)) { diff --git a/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/properties/KmsDefaultProperties.java b/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/properties/KmsDefaultProperties.java index 4527930..b79ab8a 100644 --- a/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/properties/KmsDefaultProperties.java +++ b/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/properties/KmsDefaultProperties.java @@ -72,7 +72,7 @@ public static class Sm2Properties { /** * 自动生成后存储的路径 */ - private String autoGenerateLocalPath; + private String autoGenerateLocalPath = "/tmp/keypair"; /** * 公钥key diff --git a/base-framework-log-starter/src/main/java/com/fuhouyu/framework/log/core/LogRecordAspectj.java b/base-framework-log-starter/src/main/java/com/fuhouyu/framework/log/core/LogRecordAspectj.java index eacbe26..fdbdbb1 100644 --- a/base-framework-log-starter/src/main/java/com/fuhouyu/framework/log/core/LogRecordAspectj.java +++ b/base-framework-log-starter/src/main/java/com/fuhouyu/framework/log/core/LogRecordAspectj.java @@ -17,6 +17,7 @@ package com.fuhouyu.framework.log.core; import com.fuhouyu.framework.context.user.UserContextHolder; +import com.fuhouyu.framework.log.exception.LogException; import com.fuhouyu.framework.log.model.LogRecord; import com.fuhouyu.framework.utils.JacksonUtil; import com.fuhouyu.framework.utils.LoggerUtil; @@ -130,10 +131,10 @@ protected void handleLog(final JoinPoint joinPoint, com.fuhouyu.framework.log.an result = JacksonUtil.writeValueAsString(content); } catch (ParseException ex) { LoggerUtil.error(LOGGER, "log content: {} parse failed", logRecord.content(), ex); - throw new RuntimeException(ex); + throw new LogException(ex); } catch (Exception ex) { LoggerUtil.error(LOGGER, "log other error: {} ", content, ex); - throw new RuntimeException(ex); + throw new LogException(ex); } LogRecord logRecordEntity = new LogRecord(); logRecordEntity.setSystemName(systemName); diff --git a/base-framework-log-starter/src/main/java/com/fuhouyu/framework/log/exception/LogException.java b/base-framework-log-starter/src/main/java/com/fuhouyu/framework/log/exception/LogException.java new file mode 100644 index 0000000..885d4a4 --- /dev/null +++ b/base-framework-log-starter/src/main/java/com/fuhouyu/framework/log/exception/LogException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.fuhouyu.framework.log.exception; + +/** + *

+ * 日志异常 + *

+ * + * @author fuhouyu + * @since 2024/10/6 11:51 + */ +public class LogException extends RuntimeException { + + public LogException() { + this(null); + } + + public LogException(Throwable cause) { + super("Cannot parse JSON", cause); + } +} diff --git a/base-framework-log-starter/src/test/java/com/fuhouyu/framework/log/LogRecordStoreServiceImplTest.java b/base-framework-log-starter/src/test/java/com/fuhouyu/framework/log/LogRecordStoreServiceImpl.java similarity index 95% rename from base-framework-log-starter/src/test/java/com/fuhouyu/framework/log/LogRecordStoreServiceImplTest.java rename to base-framework-log-starter/src/test/java/com/fuhouyu/framework/log/LogRecordStoreServiceImpl.java index 0ac5f2a..ae9be93 100644 --- a/base-framework-log-starter/src/test/java/com/fuhouyu/framework/log/LogRecordStoreServiceImplTest.java +++ b/base-framework-log-starter/src/test/java/com/fuhouyu/framework/log/LogRecordStoreServiceImpl.java @@ -37,9 +37,9 @@ * @since 2024/8/17 23:26 */ @TestComponent -public class LogRecordStoreServiceImplTest { +public class LogRecordStoreServiceImpl { - private static final Logger LOGGER = LoggerFactory.getLogger(LogRecordStoreServiceImplTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(LogRecordStoreServiceImpl.class); public String getUsername() { return "test-user"; diff --git a/base-framework-log-starter/src/test/java/com/fuhouyu/framework/log/LogRecordStoreTest.java b/base-framework-log-starter/src/test/java/com/fuhouyu/framework/log/LogRecordStoreTest.java index 7930941..697d11c 100644 --- a/base-framework-log-starter/src/test/java/com/fuhouyu/framework/log/LogRecordStoreTest.java +++ b/base-framework-log-starter/src/test/java/com/fuhouyu/framework/log/LogRecordStoreTest.java @@ -45,7 +45,7 @@ class LogRecordStoreTest { @Autowired - private LogRecordStoreServiceImplTest logRecordStoreServiceImplTest; + private LogRecordStoreServiceImpl logRecordStoreServiceImpl; @BeforeEach void setUp() { @@ -58,7 +58,7 @@ void setUp() { @Test void testLogStoreService() { - RestResult result = logRecordStoreServiceImplTest.success(); + RestResult result = logRecordStoreServiceImpl.success(); Assert.isTrue(result.getData(), "日志返回结果不正确"); } diff --git a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/constants/FileResourceMetadataConstant.java b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/constants/FileResourceMetadataConstant.java index f1b9091..7c78071 100644 --- a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/constants/FileResourceMetadataConstant.java +++ b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/constants/FileResourceMetadataConstant.java @@ -24,9 +24,12 @@ * @author fuhouyu * @since 2024/8/19 15:33 */ -public interface FileResourceMetadataConstant { +public class FileResourceMetadataConstant { - String ETAG = "etag"; + public static final String ETAG = "etag"; + public static final String LAST_MODIFIED = "Last-Modified"; - String LAST_MODIFIED = "Last-Modified"; + private FileResourceMetadataConstant() { + + } } diff --git a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/model/DownloadResourceRequest.java b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/model/DownloadResourceRequest.java index 87c1282..5bc4fd8 100644 --- a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/model/DownloadResourceRequest.java +++ b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/model/DownloadResourceRequest.java @@ -36,7 +36,7 @@ public class DownloadResourceRequest extends BaseResourceRequest { /** * 每个分片下载的大小,默认 1mb */ - private long partSize = 1024 * 1024; + private long partSize = 1024 * 1024L; /** * 下载的线程数 diff --git a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/model/ResourceMetadata.java b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/model/ResourceMetadata.java index e48c0f4..186e39a 100644 --- a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/model/ResourceMetadata.java +++ b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/model/ResourceMetadata.java @@ -40,12 +40,12 @@ public class ResourceMetadata implements Serializable { /** * http规范请求头元数据 */ - protected Map metadata = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + protected transient Map metadata = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); /** * 用户自定义的元数据信息 */ - private Map userMetadata = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + private transient Map userMetadata = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); /** * 添加自定义元数据 diff --git a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/service/impl/LocalFileServiceImpl.java b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/service/impl/LocalFileServiceImpl.java index fa682cc..2b7a2f0 100644 --- a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/service/impl/LocalFileServiceImpl.java +++ b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/service/impl/LocalFileServiceImpl.java @@ -111,7 +111,7 @@ public PutResourceResult uploadFile(PutResourceRequest putResourceRequest) throw return new PutResourceResult(bucketName, objectKey, etag); } catch (FileNotFoundException e) { - throw new ResourceException(String.format("%s 文件不存在", file.getAbsolutePath()), e); + throw new ResourceException("上传文件不存在", e); } catch (IOException e) { throw new ResourceException(e.getMessage(), e); } @@ -172,7 +172,7 @@ public UploadCompleteMultipartResult completeMultipartUpload(UploadCompleteMulti Path bucketNameAndObjectPath = Paths.get(TMP_DIRECT, uploadId, uploadId); bucketNameAndObjectKey = new String(Files.readAllBytes(bucketNameAndObjectPath)).split(SPACER); } catch (IOException e) { - throw new RuntimeException(e); + throw new IllegalArgumentException(e); } String bucketName = bucketNameAndObjectKey[0]; String objectKey = bucketNameAndObjectKey[1]; @@ -204,7 +204,7 @@ public ListMultipartResult listParts(ListMultipartRequest listMultipartRequest) listMultipartResult.setNextPartNumberMaker(partNumberMaker + maxParts); - this.listFilePathCallback(tmpPath, uploadId, (paths) -> + this.listFilePathCallback(tmpPath, paths -> paths.filter(f -> !f.getFileName().endsWith(uploadId)) .sorted(Comparator.comparingInt(o -> Integer.parseInt(o.getFileName().toString()))) .skip(partNumberMaker) @@ -236,12 +236,12 @@ public boolean doesObjectExist(String bucketName, String objectKey) { } @Override - public ListResourceResult listFiles(ListResourceRequest listFileRequest) throws ResourceException { + public ListResourceResult listFiles(ListResourceRequest listFileRequest) { throw new UnsupportedOperationException("这里暂时不做实现"); } @Override - public CopyResourceResult copyFile(String sourceBucketName, String sourceObjectKey, String destBucketName, String destObjectKey) throws ResourceException { + public CopyResourceResult copyFile(String sourceBucketName, String sourceObjectKey, String destBucketName, String destObjectKey) { try { Path targetPath = Paths.get(destBucketName, destBucketName); FileUtil.copyFile(Paths.get(sourceBucketName, sourceObjectKey), @@ -256,12 +256,12 @@ public CopyResourceResult copyFile(String sourceBucketName, String sourceObjectK copyResourceResult.setLastModified(lastModifiedTime); return copyResourceResult; } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); + throw new IllegalArgumentException(e.getMessage(), e); } } @Override - public void deleteFile(String bucketName, String objectKey) throws ResourceException { + public void deleteFile(String bucketName, String objectKey) { FileUtil.deleteFileIfExists(Paths.get(bucketName, objectKey)); } @@ -341,20 +341,6 @@ private void doReadFileToBytes(FileChannel fileChannel, } - /** - * 设置文件属性 - * - * @param path 路径 - * @param resourceMetadata 文件资源元数据 - * @throws IOException io异常 - */ - private void setFileMetadata(Path path, ResourceMetadata resourceMetadata) throws IOException { - if (Objects.isNull(resourceMetadata)) { - return; - } - FileUtil.setFileAttributeAll(path, resourceMetadata.getUserMetadata()); - } - /** * 从文件中获取元数据返回 * @@ -387,19 +373,17 @@ private ResourceMetadata getFileResourceMetadata(Path path) throws ResourceExcep */ public String mergeFile(Path tmpUploadFilePath, Path targetPath, String uploadId) throws ResourceException { try { - this.listFilePathCallback(tmpUploadFilePath, uploadId, (paths) -> { - paths.filter(f -> !f.getFileName().endsWith(uploadId)) - .sorted(Comparator.comparingInt(o -> Integer.parseInt(o.getFileName().toString()))) - .forEach(filePath -> { - try (FileChannel sourceFileChannel = FileChannel.open(filePath, StandardOpenOption.READ); - FileChannel targetFileChannel = FileChannel.open(targetPath, - StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.APPEND)) { - sourceFileChannel.transferTo(0, sourceFileChannel.size(), targetFileChannel); - } catch (IOException e) { - throw new RuntimeException(e); - } - }); - }); + this.listFilePathCallback(tmpUploadFilePath, paths -> paths.filter(f -> !f.getFileName().endsWith(uploadId)) + .sorted(Comparator.comparingInt(o -> Integer.parseInt(o.getFileName().toString()))) + .forEach(filePath -> { + try (FileChannel sourceFileChannel = FileChannel.open(filePath, StandardOpenOption.READ); + FileChannel targetFileChannel = FileChannel.open(targetPath, + StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.APPEND)) { + sourceFileChannel.transferTo(0, sourceFileChannel.size(), targetFileChannel); + } catch (IOException e) { + throw new IllegalArgumentException(e); + } + })); FileUtil.deleteDirect(tmpUploadFilePath); return FileUtil.calculateFileDigest(targetPath, this.getMd5MessageDigest()); } catch (IOException e) { @@ -411,10 +395,9 @@ public String mergeFile(Path tmpUploadFilePath, Path targetPath, String uploadId * 列出父级路径下的所有分片的文件 * * @param parentPath 父级路径 - * @param uploadId 上传的文件id * @throws ResourceException 资源服务异常 */ - private void listFilePathCallback(Path parentPath, String uploadId, + private void listFilePathCallback(Path parentPath, Callback> filesCallback) throws ResourceException { if (!Files.exists(parentPath)) { throw new ResourceException("分片文件不存在"); @@ -460,7 +443,7 @@ private MessageDigest getMd5MessageDigest() { try { return MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("No Such Algorithm" + e.getMessage(), e); + throw new IllegalArgumentException("No Such Algorithm" + e.getMessage(), e); } } } diff --git a/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/authentication/AuthenticationProviderTest.java b/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/authentication/AuthenticationProvider.java similarity index 98% rename from base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/authentication/AuthenticationProviderTest.java rename to base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/authentication/AuthenticationProvider.java index e8c5637..9a2609d 100644 --- a/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/authentication/AuthenticationProviderTest.java +++ b/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/authentication/AuthenticationProvider.java @@ -31,7 +31,7 @@ * @since 2024/8/24 22:19 */ @TestComponent -public class AuthenticationProviderTest { +public class AuthenticationProvider { @Bean diff --git a/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/WebAutoConfigure.java b/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/WebAutoConfigure.java index c6bcb2b..3e9fcf4 100644 --- a/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/WebAutoConfigure.java +++ b/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/WebAutoConfigure.java @@ -18,7 +18,6 @@ import com.fuhouyu.framework.kms.service.KmsService; import com.fuhouyu.framework.web.config.WebMvcAutoConfigure; -import com.fuhouyu.framework.web.exception.WebExceptionHandler; import com.fuhouyu.framework.web.filter.DefaultHttpBodyFilter; import com.fuhouyu.framework.web.filter.HttpBodyFilter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; diff --git a/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/constants/FormTokenConstant.java b/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/constants/FormTokenConstant.java index 2a16021..15ef6c8 100644 --- a/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/constants/FormTokenConstant.java +++ b/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/constants/FormTokenConstant.java @@ -33,7 +33,7 @@ public class FormTokenConstant { /** * 默认为十分钟过期 */ - public static final long EXPIRE_TIME = 60 * 10; + public static final long EXPIRE_TIME = 60 * 10L; private FormTokenConstant() { } diff --git a/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/exception/WebServiceException.java b/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/exception/WebServiceException.java index fe4b0c8..118edac 100644 --- a/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/exception/WebServiceException.java +++ b/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/exception/WebServiceException.java @@ -38,7 +38,7 @@ public class WebServiceException extends RuntimeException { private final String message; - private final ResponseCode responseStatus; + private final transient ResponseCode responseStatus; public WebServiceException(ResponseCode responseStatus) { this.responseStatus = responseStatus; diff --git a/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/filter/HttpRequestBodyAdvice.java b/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/filter/HttpRequestBodyAdvice.java index a41bd49..640f25d 100644 --- a/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/filter/HttpRequestBodyAdvice.java +++ b/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/filter/HttpRequestBodyAdvice.java @@ -79,7 +79,7 @@ private InputStream decryptionBody() { try (InputStream inputStream = inputMessage.getBody()) { bytes = inputStream.readAllBytes(); } catch (IOException e) { - throw new RuntimeException("read body failed " + e.getMessage(), e); + throw new IllegalArgumentException("read body failed " + e.getMessage(), e); } return new ByteArrayInputStream(httpBodyFilter.decryptionBody(bytes)); } diff --git a/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/fileter/HttpControllerTest.java b/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/fileter/HttpControllerTest.java index 3893716..ab503f6 100644 --- a/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/fileter/HttpControllerTest.java +++ b/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/fileter/HttpControllerTest.java @@ -66,10 +66,6 @@ void testEnc() throws Exception { Map map = new HashMap<>(); map.put("body", HexUtil.encodeToHexString(bodyBytes)); -// mockMvc.perform( -// MockMvcRequestBuilders.get("/base/v1/form/token") -// -// ).andExpect(status().isOk()); mockMvc.perform( MockMvcRequestBuilders.post("/v1/test/enc") .contentType(MediaType.APPLICATION_JSON) diff --git a/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/FormTokenControllerTest.java b/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/FormTokenController.java similarity index 96% rename from base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/FormTokenControllerTest.java rename to base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/FormTokenController.java index ce92082..d25dffa 100644 --- a/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/FormTokenControllerTest.java +++ b/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/FormTokenController.java @@ -30,7 +30,7 @@ * @since 2024/8/17 23:22 */ @TestComponent -public class FormTokenControllerTest { +public class FormTokenController { @NoRepeatSubmit public RestResult success() { diff --git a/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/WebFormNoRepeatSubmitTest.java b/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/WebFormNoRepeatSubmitTest.java index 0720acb..21783d4 100644 --- a/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/WebFormNoRepeatSubmitTest.java +++ b/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/WebFormNoRepeatSubmitTest.java @@ -45,11 +45,11 @@ class WebFormNoRepeatSubmitTest { @Autowired - private FormTokenControllerTest formTokenControllerTest; + private FormTokenController formTokenController; @Test void testNoRepeatSubmit() { - RestResult restResult = formTokenControllerTest.success(); + RestResult restResult = formTokenController.success(); Assert.isTrue(restResult.getData(), "表单防重复提交验证失败。"); } } diff --git a/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/utils/BeanConvertUtilTest.java b/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/utils/BeanConvertUtilTest.java index 0732c25..bcf0e84 100644 --- a/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/utils/BeanConvertUtilTest.java +++ b/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/utils/BeanConvertUtilTest.java @@ -17,15 +17,9 @@ package com.fuhouyu.framework.web.utils; import com.fuhouyu.framework.context.user.DefaultUserDetail; -import com.fuhouyu.framework.context.user.User; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.util.Assert; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; /** *

@@ -51,19 +45,7 @@ void setUp() { @Test void testBeanConvert() { DefaultUserDetail copyUserDetail = BeanConvertUtil.convertTo(userDetail, DefaultUserDetail::new); - Assert.isTrue(Objects.equals(copyUserDetail.getId(), userDetail.getId()), - "对象复制失败"); - - List sourceList = new ArrayList<>(); - sourceList.add(userDetail); - - List sourceLinkedList = new LinkedList<>(); - sourceLinkedList.add(userDetail); - - List targetList = BeanConvertUtil.convertListTo(sourceList, DefaultUserDetail::new); - List targetLinkedList = BeanConvertUtil.convertListTo(sourceLinkedList, DefaultUserDetail::new); - System.out.println(); - + Assertions.assertEquals(copyUserDetail.getId(), userDetail.getId(), "对象复制失败"); } } diff --git a/qodana.yaml b/qodana.yaml deleted file mode 100644 index 3ac8a9a..0000000 --- a/qodana.yaml +++ /dev/null @@ -1,11 +0,0 @@ -#-------------------------------------------------------------------------------# -# Qodana analysis is configured by qodana.yaml file # -# https://www.jetbrains.com/help/qodana/qodana-yaml.html # -#-------------------------------------------------------------------------------# -version: "1.0" - -#Specify inspection profile for code analysis -profile: - name: qodana.starter - -linter: jetbrains/qodana-jvm:2024.2