From f032606b8ff77d91331d2f2bbd6c46cce69663b6 Mon Sep 17 00:00:00 2001 From: pipinet Date: Mon, 18 Dec 2023 21:40:27 +0800 Subject: [PATCH] fix: add message code --- .../cdi/{CdiMessages.java => Messages.java} | 11 ++-- cdi/src/main/java/com/qwlabs/cdi/Primary.java | 1 + .../cdi/partition/PartitionInterceptor.java | 8 +-- .../qwlabs/cdi/partition/PartitionResult.java | 4 +- .../cdi/partition/PartitionResultTest.java | 2 +- .../com/qwlabs/ff/DefaultFeatureFlags.java | 2 +- ...eatureFlagsMessages.java => Messages.java} | 13 ++--- .../java/com/qwlabs/lang/LimitedRunner.java | 2 +- .../java/com/qwlabs/lang/QueueWorker.java | 2 +- message-ranges.txt | 23 +++++++++ .../src/main/java/com/qwlabs/q/Messages.java | 27 ++++++++++ .../src/main/java/com/qwlabs/q/QMessages.java | 25 ---------- .../java/com/qwlabs/q/cdi/QEngineAware.java | 4 +- .../java/com/qwlabs/q/cdi/QEngineImpl.java | 8 +-- .../graphql/models/CreateUploadUrlsInput.java | 6 +-- .../com/qwlabs/storage/minio/MinioConfig.java | 8 +-- .../storage/minio/MinioStorageEngine.java | 4 +- .../java/com/qwlabs/storage/s3/S3Config.java | 8 +-- .../com/qwlabs/storage/messages/Messages.java | 50 +++++++++++++++++++ .../storage/messages/StorageMessages.java | 49 ------------------ .../storage/services/StorageContext.java | 10 ++-- .../storage/services/StorageEngine.java | 14 +++--- .../services/StorageEngineDispatcher.java | 4 +- .../services/StoragePlannerDispatcher.java | 4 +- .../qwlabs/storage/url/UrlStorageEngine.java | 10 ++-- 25 files changed, 165 insertions(+), 134 deletions(-) rename cdi/src/main/java/com/qwlabs/cdi/{CdiMessages.java => Messages.java} (53%) rename feature-flags/src/main/java/com/qwlabs/ff/{FeatureFlagsMessages.java => Messages.java} (52%) create mode 100644 message-ranges.txt create mode 100644 q-api/src/main/java/com/qwlabs/q/Messages.java delete mode 100644 q-api/src/main/java/com/qwlabs/q/QMessages.java create mode 100644 storage/src/main/java/com/qwlabs/storage/messages/Messages.java delete mode 100644 storage/src/main/java/com/qwlabs/storage/messages/StorageMessages.java diff --git a/cdi/src/main/java/com/qwlabs/cdi/CdiMessages.java b/cdi/src/main/java/com/qwlabs/cdi/Messages.java similarity index 53% rename from cdi/src/main/java/com/qwlabs/cdi/CdiMessages.java rename to cdi/src/main/java/com/qwlabs/cdi/Messages.java index 894b120..8c46937 100644 --- a/cdi/src/main/java/com/qwlabs/cdi/CdiMessages.java +++ b/cdi/src/main/java/com/qwlabs/cdi/Messages.java @@ -7,10 +7,13 @@ import static org.jboss.logging.Messages.getBundle; -@MessageBundle(projectCode = "CDI") -public interface CdiMessages { +@SuppressWarnings("checkstyle:MagicNumber") +@MessageBundle(projectCode = "DORA") +public interface Messages { + int BASE = 0; @Inject - CdiMessages INSTANCE = getBundle(CdiMessages.class); - @Message(value = "代码错误: {0}", format = Message.Format.MESSAGE_FORMAT) + Messages INSTANCE = getBundle(Messages.class); + + @Message(id = BASE + 1, value = "Code error: {0}", format = Message.Format.MESSAGE_FORMAT) CodeException codeError(String message); } diff --git a/cdi/src/main/java/com/qwlabs/cdi/Primary.java b/cdi/src/main/java/com/qwlabs/cdi/Primary.java index a10868f..e349ce4 100644 --- a/cdi/src/main/java/com/qwlabs/cdi/Primary.java +++ b/cdi/src/main/java/com/qwlabs/cdi/Primary.java @@ -1,6 +1,7 @@ package com.qwlabs.cdi; import jakarta.inject.Qualifier; + import java.lang.annotation.Retention; import java.lang.annotation.Target; diff --git a/cdi/src/main/java/com/qwlabs/cdi/partition/PartitionInterceptor.java b/cdi/src/main/java/com/qwlabs/cdi/partition/PartitionInterceptor.java index 5e5db80..324340d 100644 --- a/cdi/src/main/java/com/qwlabs/cdi/partition/PartitionInterceptor.java +++ b/cdi/src/main/java/com/qwlabs/cdi/partition/PartitionInterceptor.java @@ -1,6 +1,6 @@ package com.qwlabs.cdi.partition; -import com.qwlabs.cdi.CdiMessages; +import com.qwlabs.cdi.Messages; import com.qwlabs.lang.BufferedCall; import com.qwlabs.lang.C2; import com.qwlabs.lang.F2; @@ -59,7 +59,7 @@ private PartitionByParameter lookupPartitionBy(InvocationContext context) { return buildPartitionByParameter(context, index); } } - throw CdiMessages.INSTANCE.codeError("Can not found @PartitionBy in method:" + context.getMethod().getName()); + throw Messages.INSTANCE.codeError("Can not found @PartitionBy in method:" + context.getMethod().getName()); } private boolean hasPartitionBy(Annotation[] parameterAnnotations) { @@ -108,7 +108,7 @@ public void add(BufferedCall bufferedCall) { bufferedCall.add((Collection) data); return; } - throw CdiMessages.INSTANCE.codeError("PartitionBy can not support type " + type); + throw Messages.INSTANCE.codeError("PartitionBy can not support type " + type); } public R call(List data, InvocationContext context) throws Exception { @@ -133,7 +133,7 @@ private Object transformData(List data) { if (Collection.class.isAssignableFrom(type)) { return data; } - throw CdiMessages.INSTANCE.codeError("PartitionBy can not support type " + type.getName()); + throw Messages.INSTANCE.codeError("PartitionBy can not support type " + type.getName()); } public boolean needCall(int size) { diff --git a/cdi/src/main/java/com/qwlabs/cdi/partition/PartitionResult.java b/cdi/src/main/java/com/qwlabs/cdi/partition/PartitionResult.java index d4b5755..03fe0aa 100644 --- a/cdi/src/main/java/com/qwlabs/cdi/partition/PartitionResult.java +++ b/cdi/src/main/java/com/qwlabs/cdi/partition/PartitionResult.java @@ -1,6 +1,6 @@ package com.qwlabs.cdi.partition; -import com.qwlabs.cdi.CdiMessages; +import com.qwlabs.cdi.Messages; import java.util.List; import java.util.Set; @@ -25,7 +25,7 @@ public static R get(Stream data, Class returnType) { if (Long.TYPE.isAssignableFrom(returnType) || Long.class.isAssignableFrom(returnType)) { return (R) getLongData(data); } - throw CdiMessages.INSTANCE.codeError("PartitionResult can not support type " + returnType.getName()); + throw Messages.INSTANCE.codeError("PartitionResult can not support type " + returnType.getName()); } private static Long getLongData(Stream data) { diff --git a/cdi/src/test/java/com/qwlabs/cdi/partition/PartitionResultTest.java b/cdi/src/test/java/com/qwlabs/cdi/partition/PartitionResultTest.java index dbab56d..255d6b6 100644 --- a/cdi/src/test/java/com/qwlabs/cdi/partition/PartitionResultTest.java +++ b/cdi/src/test/java/com/qwlabs/cdi/partition/PartitionResultTest.java @@ -65,6 +65,6 @@ void should_exception() { var exception = assertThrows(CodeException.class, () -> PartitionResult.get(data, Map.class)); - assertThat(exception.getMessage(), is("代码错误: PartitionResult can not support type java.util.Map")); + assertThat(exception.getMessage(), is("DORA000001: Code error: PartitionResult can not support type java.util.Map")); } } diff --git a/feature-flags/src/main/java/com/qwlabs/ff/DefaultFeatureFlags.java b/feature-flags/src/main/java/com/qwlabs/ff/DefaultFeatureFlags.java index 77ca62a..dda1519 100644 --- a/feature-flags/src/main/java/com/qwlabs/ff/DefaultFeatureFlags.java +++ b/feature-flags/src/main/java/com/qwlabs/ff/DefaultFeatureFlags.java @@ -25,6 +25,6 @@ public FeatureFlag get(String feature) { return instances.stream() .filter(instance -> Objects.equals(instance.feature(), feature)) .findFirst() - .orElseThrow(() -> FeatureFlagsMessages.INSTANCE.featureNotFound(feature)); + .orElseThrow(() -> Messages.INSTANCE.featureNotFound(feature)); } } diff --git a/feature-flags/src/main/java/com/qwlabs/ff/FeatureFlagsMessages.java b/feature-flags/src/main/java/com/qwlabs/ff/Messages.java similarity index 52% rename from feature-flags/src/main/java/com/qwlabs/ff/FeatureFlagsMessages.java rename to feature-flags/src/main/java/com/qwlabs/ff/Messages.java index 40ebf4c..e9cbe88 100755 --- a/feature-flags/src/main/java/com/qwlabs/ff/FeatureFlagsMessages.java +++ b/feature-flags/src/main/java/com/qwlabs/ff/Messages.java @@ -2,18 +2,19 @@ import com.qwlabs.exceptions.CodeException; +import jakarta.inject.Inject; import org.jboss.logging.annotations.Message; import org.jboss.logging.annotations.MessageBundle; -import jakarta.inject.Inject; - import static org.jboss.logging.Messages.getBundle; -@MessageBundle(projectCode = "FEATURE-FLAGS") -public interface FeatureFlagsMessages { +@SuppressWarnings("checkstyle:MagicNumber") +@MessageBundle(projectCode = "DORA") +public interface Messages { + int BASE = 3000; @Inject - FeatureFlagsMessages INSTANCE = getBundle(FeatureFlagsMessages.class); + Messages INSTANCE = getBundle(Messages.class); - @Message(value = "Can not found feature: {0}", format = Message.Format.MESSAGE_FORMAT) + @Message(id = BASE, value = "Can not found feature: {0}", format = Message.Format.MESSAGE_FORMAT) CodeException featureNotFound(String feature); } diff --git a/lang/src/main/java/com/qwlabs/lang/LimitedRunner.java b/lang/src/main/java/com/qwlabs/lang/LimitedRunner.java index 8757496..f9e8b30 100644 --- a/lang/src/main/java/com/qwlabs/lang/LimitedRunner.java +++ b/lang/src/main/java/com/qwlabs/lang/LimitedRunner.java @@ -1,8 +1,8 @@ package com.qwlabs.lang; +import jakarta.validation.constraints.NotNull; import lombok.extern.slf4j.Slf4j; -import jakarta.validation.constraints.NotNull; import java.util.concurrent.atomic.LongAdder; import java.util.function.Consumer; diff --git a/lang/src/main/java/com/qwlabs/lang/QueueWorker.java b/lang/src/main/java/com/qwlabs/lang/QueueWorker.java index d55352b..9bf49a0 100644 --- a/lang/src/main/java/com/qwlabs/lang/QueueWorker.java +++ b/lang/src/main/java/com/qwlabs/lang/QueueWorker.java @@ -1,9 +1,9 @@ package com.qwlabs.lang; +import jakarta.annotation.Nullable; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.extern.slf4j.Slf4j; -import jakarta.annotation.Nullable; import java.time.Duration; import java.util.Objects; diff --git a/message-ranges.txt b/message-ranges.txt new file mode 100644 index 0000000..e9889c6 --- /dev/null +++ b/message-ranges.txt @@ -0,0 +1,23 @@ +# This document is intended to establish the ranges for message IDs in the various sub-projects. + +# Range = owner +000001-000999 = cdi +001000-001999 = q-api +002000-002999 = storage-api +003000-003999 = feature-flags +004000-004999 = +005000-005999 = +006000-006999 = +007000-007999 = +008000-008999 = +009000-009999 = +010000-010999 = +011000-011999 = +012000-012999 = +013000-013999 = +014000-014999 = +015000-015999 = +016000-016999 = +017000-017999 = +018000-018999 = +019000-019999 = diff --git a/q-api/src/main/java/com/qwlabs/q/Messages.java b/q-api/src/main/java/com/qwlabs/q/Messages.java new file mode 100644 index 0000000..33694fd --- /dev/null +++ b/q-api/src/main/java/com/qwlabs/q/Messages.java @@ -0,0 +1,27 @@ +package com.qwlabs.q; + +import com.qwlabs.exceptions.BadRequestException; +import com.qwlabs.exceptions.CodeException; +import jakarta.inject.Inject; +import org.jboss.logging.annotations.Message; +import org.jboss.logging.annotations.MessageBundle; + +import static org.jboss.logging.Messages.getBundle; + + +@SuppressWarnings("checkstyle:MagicNumber") +@MessageBundle(projectCode = "DORA") +public interface Messages { + int BASE = 1000; + @Inject + Messages INSTANCE = getBundle(Messages.class); + + @Message(id = BASE, value = "Invalid dialect: {0}", format = Message.Format.MESSAGE_FORMAT) + CodeException invalidDialect(String dialect); + + @Message(id = BASE + 1, value = "Invalid query: {0}", format = Message.Format.MESSAGE_FORMAT) + BadRequestException invalidQuery(String query); + + @Message(id = BASE + 2, value = "Q Engine not found", format = Message.Format.MESSAGE_FORMAT) + CodeException engineNotFound(); +} diff --git a/q-api/src/main/java/com/qwlabs/q/QMessages.java b/q-api/src/main/java/com/qwlabs/q/QMessages.java deleted file mode 100644 index fccddb0..0000000 --- a/q-api/src/main/java/com/qwlabs/q/QMessages.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.qwlabs.q; - -import com.qwlabs.exceptions.BadRequestException; -import com.qwlabs.exceptions.CodeException; -import org.jboss.logging.annotations.Message; -import org.jboss.logging.annotations.MessageBundle; - -import jakarta.inject.Inject; - -import static org.jboss.logging.Messages.getBundle; - -@MessageBundle(projectCode = "Q") -public interface QMessages { - @Inject - QMessages INSTANCE = getBundle(QMessages.class); - - @Message(value = "Invalid dialect: {0}", format = Message.Format.MESSAGE_FORMAT) - CodeException invalidDialect(String dialect); - - @Message(value = "Invalid query: {0}", format = Message.Format.MESSAGE_FORMAT) - BadRequestException invalidQuery(String query); - - @Message(value = "Q Engine not found", format = Message.Format.MESSAGE_FORMAT) - CodeException engineNotFound(); -} diff --git a/q-api/src/main/java/com/qwlabs/q/cdi/QEngineAware.java b/q-api/src/main/java/com/qwlabs/q/cdi/QEngineAware.java index d22c799..a9a8a2b 100644 --- a/q-api/src/main/java/com/qwlabs/q/cdi/QEngineAware.java +++ b/q-api/src/main/java/com/qwlabs/q/cdi/QEngineAware.java @@ -1,8 +1,8 @@ package com.qwlabs.q.cdi; import com.qwlabs.cdi.SafeCDI; +import com.qwlabs.q.Messages; import com.qwlabs.q.QEngine; -import com.qwlabs.q.QMessages; import jakarta.enterprise.inject.Instance; @@ -10,6 +10,6 @@ public interface QEngineAware { default QEngine engine() { return SafeCDI.select(QEngine.class) .map(Instance::get) - .orElseThrow(QMessages.INSTANCE::engineNotFound); + .orElseThrow(Messages.INSTANCE::engineNotFound); } } diff --git a/q-api/src/main/java/com/qwlabs/q/cdi/QEngineImpl.java b/q-api/src/main/java/com/qwlabs/q/cdi/QEngineImpl.java index 5d5b1f3..f216651 100644 --- a/q-api/src/main/java/com/qwlabs/q/cdi/QEngineImpl.java +++ b/q-api/src/main/java/com/qwlabs/q/cdi/QEngineImpl.java @@ -3,8 +3,8 @@ import com.qwlabs.cdi.dispatch.DispatchInstance; import com.qwlabs.exceptions.ServiceException; import com.qwlabs.lang.S2; +import com.qwlabs.q.Messages; import com.qwlabs.q.QEngine; -import com.qwlabs.q.QMessages; import com.qwlabs.q.conditions.QCondition; import com.qwlabs.q.formatters.QFormatter; import com.qwlabs.q.parsers.QParser; @@ -34,7 +34,7 @@ public QEngineImpl(Instance formatters, @Nullable public String format(@NotNull String dialect, @Nullable QCondition condition) { if (S2.isEmpty(dialect)) { - throw QMessages.INSTANCE.invalidDialect(dialect); + throw Messages.INSTANCE.invalidDialect(dialect); } if (condition == null) { return null; @@ -50,7 +50,7 @@ public String format(@NotNull String dialect, @Nullable QCondition condition) { @Nullable public QCondition parse(@NotNull String dialect, @Nullable String query) { if (S2.isEmpty(dialect)) { - throw QMessages.INSTANCE.invalidDialect(dialect); + throw Messages.INSTANCE.invalidDialect(dialect); } if (query == null) { return null; @@ -62,7 +62,7 @@ public QCondition parse(@NotNull String dialect, @Nullable String query) { throw e; } catch (Exception e) { LOGGER.error("Invalid q. dialect:{} query: {}", dialect, query, e); - throw QMessages.INSTANCE.invalidQuery(query); + throw Messages.INSTANCE.invalidQuery(query); } } } diff --git a/storage-graphql/src/main/java/com/qwlabs/storage/graphql/models/CreateUploadUrlsInput.java b/storage-graphql/src/main/java/com/qwlabs/storage/graphql/models/CreateUploadUrlsInput.java index 686ad8f..97b068f 100644 --- a/storage-graphql/src/main/java/com/qwlabs/storage/graphql/models/CreateUploadUrlsInput.java +++ b/storage-graphql/src/main/java/com/qwlabs/storage/graphql/models/CreateUploadUrlsInput.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.qwlabs.jackson.Jackson; -import com.qwlabs.storage.messages.StorageMessages; +import com.qwlabs.storage.messages.Messages; import com.qwlabs.storage.services.StorageContext; import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotNull; @@ -45,8 +45,8 @@ private Map ofContext() { } if (context instanceof String) { return Jackson.read((String) context, CONTENT_TYPE) - .orElseThrow(() -> StorageMessages.INSTANCE.invalidContent((String) context)); + .orElseThrow(() -> Messages.INSTANCE.invalidContent((String) context)); } - throw StorageMessages.INSTANCE.invalidContent(context.toString()); + throw Messages.INSTANCE.invalidContent(context.toString()); } } diff --git a/storage-minio/src/main/java/com/qwlabs/storage/minio/MinioConfig.java b/storage-minio/src/main/java/com/qwlabs/storage/minio/MinioConfig.java index 6996499..7a5d5f6 100644 --- a/storage-minio/src/main/java/com/qwlabs/storage/minio/MinioConfig.java +++ b/storage-minio/src/main/java/com/qwlabs/storage/minio/MinioConfig.java @@ -1,7 +1,7 @@ package com.qwlabs.storage.minio; import com.qwlabs.lang.S2; -import com.qwlabs.storage.messages.StorageMessages; +import com.qwlabs.storage.messages.Messages; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -16,13 +16,13 @@ public class MinioConfig { public void validate() { if (S2.isBlank(url)) { - throw StorageMessages.INSTANCE.lostConfig("url"); + throw Messages.INSTANCE.lostConfig("url"); } if (S2.isBlank(accessKey)) { - throw StorageMessages.INSTANCE.lostConfig("accessKey"); + throw Messages.INSTANCE.lostConfig("accessKey"); } if (S2.isBlank(secretKey)) { - throw StorageMessages.INSTANCE.lostConfig("secretKey"); + throw Messages.INSTANCE.lostConfig("secretKey"); } } } diff --git a/storage-minio/src/main/java/com/qwlabs/storage/minio/MinioStorageEngine.java b/storage-minio/src/main/java/com/qwlabs/storage/minio/MinioStorageEngine.java index e8aae5e..610d3d9 100644 --- a/storage-minio/src/main/java/com/qwlabs/storage/minio/MinioStorageEngine.java +++ b/storage-minio/src/main/java/com/qwlabs/storage/minio/MinioStorageEngine.java @@ -2,7 +2,7 @@ import com.google.common.collect.Lists; -import com.qwlabs.storage.messages.StorageMessages; +import com.qwlabs.storage.messages.Messages; import com.qwlabs.storage.models.CompleteUploadCommand; import com.qwlabs.storage.models.GetDownloadUrlCommand; import com.qwlabs.storage.models.GetObjectCommand; @@ -62,7 +62,7 @@ public String completeUpload(CompleteUploadCommand command) { ListPartsResult result = minioClient.listParts( command.getBucket(), command.getObjectName(), command.getUploadId()); if (result.partList().size() != command.getPartCount()) { - throw StorageMessages.INSTANCE.invalidPartCount(command.getPartCount(), + throw Messages.INSTANCE.invalidPartCount(command.getPartCount(), result.partList().size()); } List parts = result.partList(); diff --git a/storage-s3/src/main/java/com/qwlabs/storage/s3/S3Config.java b/storage-s3/src/main/java/com/qwlabs/storage/s3/S3Config.java index c367361..3d01e22 100644 --- a/storage-s3/src/main/java/com/qwlabs/storage/s3/S3Config.java +++ b/storage-s3/src/main/java/com/qwlabs/storage/s3/S3Config.java @@ -1,7 +1,7 @@ package com.qwlabs.storage.s3; import com.qwlabs.lang.S2; -import com.qwlabs.storage.messages.StorageMessages; +import com.qwlabs.storage.messages.Messages; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -17,13 +17,13 @@ public class S3Config { public void validate() { if (S2.isBlank(url)) { - throw StorageMessages.INSTANCE.lostConfig("url"); + throw Messages.INSTANCE.lostConfig("url"); } if (S2.isBlank(accessKey)) { - throw StorageMessages.INSTANCE.lostConfig("accessKey"); + throw Messages.INSTANCE.lostConfig("accessKey"); } if (S2.isBlank(secretKey)) { - throw StorageMessages.INSTANCE.lostConfig("secretKey"); + throw Messages.INSTANCE.lostConfig("secretKey"); } } } diff --git a/storage/src/main/java/com/qwlabs/storage/messages/Messages.java b/storage/src/main/java/com/qwlabs/storage/messages/Messages.java new file mode 100644 index 0000000..916d0d0 --- /dev/null +++ b/storage/src/main/java/com/qwlabs/storage/messages/Messages.java @@ -0,0 +1,50 @@ +package com.qwlabs.storage.messages; + + +import com.qwlabs.exceptions.BadRequestException; +import com.qwlabs.exceptions.CodeException; +import com.qwlabs.exceptions.NotImplementedException; +import jakarta.inject.Inject; +import org.jboss.logging.annotations.Message; +import org.jboss.logging.annotations.MessageBundle; + +import static org.jboss.logging.Messages.getBundle; + +@SuppressWarnings("checkstyle:MagicNumber") +@MessageBundle(projectCode = "DORA") +public interface Messages { + int BASE = 2000; + + @Inject + Messages INSTANCE = getBundle(Messages.class); + + @Message(id = BASE, value = "{0} does not support {1} operation", format = Message.Format.MESSAGE_FORMAT) + BadRequestException notSupported(String provider, String operation); + + @Message(id = BASE + 1, value = "Unable to find the storage planner corresponding to {0}", format = Message.Format.MESSAGE_FORMAT) + CodeException notFoundStoragePlanner(String businessType); + + @Message(id = BASE + 2, value = "Unable to find the {0} attribute in the context", format = Message.Format.MESSAGE_FORMAT) + BadRequestException notFoundContextAttribute(String attributeName); + + @Message(id = BASE + 3, value = "Property name in context: {0}, value: {1}, type is not {2}", format = Message.Format.MESSAGE_FORMAT) + BadRequestException invalidContextAttributeType(String attributeName, String value, String type); + + @Message(id = BASE + 4, value = "Inconsistent number of part, expected: {0} Actual: {1}", format = Message.Format.MESSAGE_FORMAT) + BadRequestException invalidPartCount(int expected, int actual); + + @Message(id = BASE + 5, value = "Unable to find storage service corresponding to: {0}", format = Message.Format.MESSAGE_FORMAT) + CodeException notFoundStorageService(String provider); + + @Message(id = BASE + 6, value = "Unable to find: {0} configuration", format = Message.Format.MESSAGE_FORMAT) + CodeException lostConfig(String config); + + @Message(id = BASE + 7, value = "Get file exception: bucketName: {0} objectName: {1}: message: {2}", format = Message.Format.MESSAGE_FORMAT) + BadRequestException failedToGetFile(String bucketName, String objectName, String message); + + @Message(id = BASE + 8, value = "not implemented", format = Message.Format.MESSAGE_FORMAT) + NotImplementedException notImplemented(); + + @Message(id = BASE + 9, value = "Invalid context: {0}", format = Message.Format.MESSAGE_FORMAT) + BadRequestException invalidContent(String context); +} diff --git a/storage/src/main/java/com/qwlabs/storage/messages/StorageMessages.java b/storage/src/main/java/com/qwlabs/storage/messages/StorageMessages.java deleted file mode 100644 index e6b46c5..0000000 --- a/storage/src/main/java/com/qwlabs/storage/messages/StorageMessages.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.qwlabs.storage.messages; - - -import com.qwlabs.exceptions.BadRequestException; -import com.qwlabs.exceptions.CodeException; -import com.qwlabs.exceptions.NotImplementedException; -import org.jboss.logging.annotations.Message; -import org.jboss.logging.annotations.MessageBundle; - -import jakarta.inject.Inject; - -import static org.jboss.logging.Messages.getBundle; - -@MessageBundle(projectCode = "STORAGE") -public interface StorageMessages { - - @Inject - StorageMessages INSTANCE = getBundle(StorageMessages.class); - - @Message(value = "{0}不支持{1}操作", format = Message.Format.MESSAGE_FORMAT) - BadRequestException notSupported(String provider, String operate); - - @Message(value = "找不到:{0}对应的存储规划器", format = Message.Format.MESSAGE_FORMAT) - CodeException notFoundStoragePlanner(String businessType); - - @Message(value = "上下文中找不到:{0}属性", format = Message.Format.MESSAGE_FORMAT) - BadRequestException notFoundContextAttribute(String attributeName); - - @Message(value = "上下文中属性 名称:{0}, 值:{1} 类型不是{2}", format = Message.Format.MESSAGE_FORMAT) - BadRequestException invalidContextAttributeType(String attributeName, String value, String type); - - @Message(value = "分片数量不一致, 期待:{0} 实际:{1}", format = Message.Format.MESSAGE_FORMAT) - BadRequestException invalidPartCount(int expected, int actual); - - @Message(value = "找不到:{0}对应的存储服务", format = Message.Format.MESSAGE_FORMAT) - CodeException notFoundStorageService(String provider); - - @Message(value = "找不到:{0}配置", format = Message.Format.MESSAGE_FORMAT) - CodeException lostConfig(String config); - - @Message(value = "获取文件异常: bucketName:{0} objectName:{1}:message:{2}", format = Message.Format.MESSAGE_FORMAT) - BadRequestException failedToGetFile(String bucketName, String objectName, String message); - - @Message(value = "未实现", format = Message.Format.MESSAGE_FORMAT) - NotImplementedException notImplemented(); - - @Message(value = "无效的上下文:{0}", format = Message.Format.MESSAGE_FORMAT) - BadRequestException invalidContent(String context); -} diff --git a/storage/src/main/java/com/qwlabs/storage/services/StorageContext.java b/storage/src/main/java/com/qwlabs/storage/services/StorageContext.java index 2255363..ff8a4d4 100644 --- a/storage/src/main/java/com/qwlabs/storage/services/StorageContext.java +++ b/storage/src/main/java/com/qwlabs/storage/services/StorageContext.java @@ -4,7 +4,7 @@ import com.google.common.collect.Maps; import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; -import com.qwlabs.storage.messages.StorageMessages; +import com.qwlabs.storage.messages.Messages; import jakarta.annotation.Nullable; import java.util.Map; @@ -29,22 +29,22 @@ public String getBusinessType() { public String getFileName() { return getString(ATTRIBUTE_FILE_NAME) - .orElseThrow(() -> StorageMessages.INSTANCE.notFoundContextAttribute(ATTRIBUTE_FILE_NAME)); + .orElseThrow(() -> Messages.INSTANCE.notFoundContextAttribute(ATTRIBUTE_FILE_NAME)); } public String getFileHash() { return getString(ATTRIBUTE_FILE_HASH) - .orElseThrow(() -> StorageMessages.INSTANCE.notFoundContextAttribute(ATTRIBUTE_FILE_HASH)); + .orElseThrow(() -> Messages.INSTANCE.notFoundContextAttribute(ATTRIBUTE_FILE_HASH)); } public String getFileContentType() { return getString(ATTRIBUTE_FILE_CONTENT_TYPE) - .orElseThrow(() -> StorageMessages.INSTANCE.notFoundContextAttribute(ATTRIBUTE_FILE_CONTENT_TYPE)); + .orElseThrow(() -> Messages.INSTANCE.notFoundContextAttribute(ATTRIBUTE_FILE_CONTENT_TYPE)); } public Integer getFilePartCount() { return getInteger(ATTRIBUTE_FILE_PART_COUNT) - .orElseThrow(() -> StorageMessages.INSTANCE.notFoundContextAttribute(ATTRIBUTE_FILE_PART_COUNT)); + .orElseThrow(() -> Messages.INSTANCE.notFoundContextAttribute(ATTRIBUTE_FILE_PART_COUNT)); } public StorageContext put(String attributeName, String attributeValue) { diff --git a/storage/src/main/java/com/qwlabs/storage/services/StorageEngine.java b/storage/src/main/java/com/qwlabs/storage/services/StorageEngine.java index 6a83734..0f856e7 100644 --- a/storage/src/main/java/com/qwlabs/storage/services/StorageEngine.java +++ b/storage/src/main/java/com/qwlabs/storage/services/StorageEngine.java @@ -1,7 +1,7 @@ package com.qwlabs.storage.services; -import com.qwlabs.storage.messages.StorageMessages; +import com.qwlabs.storage.messages.Messages; import com.qwlabs.storage.models.CompleteUploadCommand; import com.qwlabs.storage.models.GetDownloadUrlCommand; import com.qwlabs.storage.models.GetObjectCommand; @@ -17,27 +17,27 @@ public interface StorageEngine { default UploadUrl createUploadUrl(GetUploadUrlCommand command) { - throw StorageMessages.INSTANCE.notImplemented(); + throw Messages.INSTANCE.notImplemented(); } default UploadUrls createUploadUrls(GetUploadUrlsCommand command) { - throw StorageMessages.INSTANCE.notImplemented(); + throw Messages.INSTANCE.notImplemented(); } default String completeUpload(CompleteUploadCommand command) { - throw StorageMessages.INSTANCE.notImplemented(); + throw Messages.INSTANCE.notImplemented(); } default String getDownloadUrl(GetDownloadUrlCommand command) { - throw StorageMessages.INSTANCE.notImplemented(); + throw Messages.INSTANCE.notImplemented(); } default InputStream getObject(GetObjectCommand command) { - throw StorageMessages.INSTANCE.notImplemented(); + throw Messages.INSTANCE.notImplemented(); } default StorageObject putObject(PutObjectCommand command) { - throw StorageMessages.INSTANCE.notImplemented(); + throw Messages.INSTANCE.notImplemented(); } default String putObjectForUrl(PutObjectCommand command) { diff --git a/storage/src/main/java/com/qwlabs/storage/services/StorageEngineDispatcher.java b/storage/src/main/java/com/qwlabs/storage/services/StorageEngineDispatcher.java index 9b14485..6ae2a1a 100644 --- a/storage/src/main/java/com/qwlabs/storage/services/StorageEngineDispatcher.java +++ b/storage/src/main/java/com/qwlabs/storage/services/StorageEngineDispatcher.java @@ -2,7 +2,7 @@ import com.qwlabs.cdi.dispatch.DispatchInstance; import com.qwlabs.cdi.Primary; -import com.qwlabs.storage.messages.StorageMessages; +import com.qwlabs.storage.messages.Messages; import com.qwlabs.storage.models.CompleteUploadCommand; import com.qwlabs.storage.models.GetDownloadUrlCommand; import com.qwlabs.storage.models.GetObjectCommand; @@ -29,7 +29,7 @@ public StorageEngineDispatcher(Instance instance) { private StorageEngine get(String provider) { return dispatcher.getOptional(provider) - .orElseThrow(() -> StorageMessages.INSTANCE.notFoundStorageService(provider)); + .orElseThrow(() -> Messages.INSTANCE.notFoundStorageService(provider)); } @Override diff --git a/storage/src/main/java/com/qwlabs/storage/services/StoragePlannerDispatcher.java b/storage/src/main/java/com/qwlabs/storage/services/StoragePlannerDispatcher.java index a342e2d..69d4311 100644 --- a/storage/src/main/java/com/qwlabs/storage/services/StoragePlannerDispatcher.java +++ b/storage/src/main/java/com/qwlabs/storage/services/StoragePlannerDispatcher.java @@ -2,7 +2,7 @@ import com.qwlabs.cdi.dispatch.DispatchInstance; import com.qwlabs.cdi.Primary; -import com.qwlabs.storage.messages.StorageMessages; +import com.qwlabs.storage.messages.Messages; import com.qwlabs.storage.models.StoragePlan; import jakarta.enterprise.context.ApplicationScoped; @@ -27,7 +27,7 @@ public StoragePlan plan(StorageContext context) { Objects.requireNonNull(businessType, "context can not be null."); return this.dispatcher.getOptional(context) .map(planner -> planner.plan(context)) - .orElseThrow(() -> StorageMessages.INSTANCE.notFoundStoragePlanner(businessType)); + .orElseThrow(() -> Messages.INSTANCE.notFoundStoragePlanner(businessType)); } } diff --git a/storage/src/main/java/com/qwlabs/storage/url/UrlStorageEngine.java b/storage/src/main/java/com/qwlabs/storage/url/UrlStorageEngine.java index 9b09a30..1fdc586 100644 --- a/storage/src/main/java/com/qwlabs/storage/url/UrlStorageEngine.java +++ b/storage/src/main/java/com/qwlabs/storage/url/UrlStorageEngine.java @@ -2,7 +2,7 @@ import com.qwlabs.cdi.dispatch.Dispatchable; -import com.qwlabs.storage.messages.StorageMessages; +import com.qwlabs.storage.messages.Messages; import com.qwlabs.storage.models.CompleteUploadCommand; import com.qwlabs.storage.models.GetDownloadUrlCommand; import com.qwlabs.storage.models.GetObjectCommand; @@ -23,12 +23,12 @@ public class UrlStorageEngine implements StorageEngine, Dispatchable { @Override public UploadUrls createUploadUrls(GetUploadUrlsCommand command) { - throw StorageMessages.INSTANCE.notSupported(PROVIDER, "upload"); + throw Messages.INSTANCE.notSupported(PROVIDER, "upload"); } @Override public String completeUpload(CompleteUploadCommand command) { - throw StorageMessages.INSTANCE.notSupported(PROVIDER, "upload"); + throw Messages.INSTANCE.notSupported(PROVIDER, "upload"); } @Override @@ -38,12 +38,12 @@ public String getDownloadUrl(GetDownloadUrlCommand command) { @Override public InputStream getObject(GetObjectCommand command) { - throw StorageMessages.INSTANCE.notSupported(PROVIDER, "download"); + throw Messages.INSTANCE.notSupported(PROVIDER, "download"); } @Override public StorageObject putObject(PutObjectCommand command) { - throw StorageMessages.INSTANCE.notSupported(PROVIDER, "putObject"); + throw Messages.INSTANCE.notSupported(PROVIDER, "putObject"); } @Override