jeantil commented on code in PR #2960:
URL: https://github.com/apache/james-project/pull/2960#discussion_r2973427854
##########
server/blob/blob-api/src/main/java/org/apache/james/blob/api/BlobStoreDAO.java:
##########
@@ -25,23 +25,77 @@
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Map;
+import java.util.Optional;
import org.reactivestreams.Publisher;
+import com.google.common.base.CharMatcher;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.ByteSource;
import com.google.common.io.FileBackedOutputStream;
public interface BlobStoreDAO {
record BlobMetadataName(String name) {
- // TODO validation (a-z,A-Z,0-9 -_) &length 128 char & non empty
+ private static final CharMatcher CHAR_MATCHER =
CharMatcher.inRange('a', 'z')
+ .or(CharMatcher.inRange('A', 'Z'))
+ .or(CharMatcher.inRange('0', '9'))
+ .or(CharMatcher.is('-'));
+
+ public BlobMetadataName {
+ Preconditions.checkArgument(CHAR_MATCHER.matchesAllOf(name),
"Invalid char in metadata name. Must be a-z,A-Z,0-9 or - got " + name);
+ Preconditions.checkArgument(name.length() < 128, "Metadata name is
too long. Size exceed 128 chars");
+ }
}
+
record BlobMetadataValue(String value) {
+ public BlobMetadataValue {
+ Preconditions.checkArgument(value.length() < 128, "Metadata value
is too long. Size exceed 128 chars");
+ }
+ }
+
+ record ContentTransferEncoding(String value) {
+ public static BlobMetadataName NAME = new
BlobMetadataName("content-transfer-encoding");
+ public static ContentTransferEncoding ZSTD = new
ContentTransferEncoding("zstd");
+
+ public static ContentTransferEncoding fromValue(BlobMetadataValue
value) {
+ return new ContentTransferEncoding(value.value());
+ }
+
+ public ContentTransferEncoding {
+ Preconditions.checkArgument(value.length() < 128,
"ContentTransferEncoding value is too long. Size exceed 128 chars");
+ }
+
+ public BlobMetadataValue asValue() {
+ return new BlobMetadataValue(value);
+ }
}
+ record BlobMetadata(Map<BlobMetadataName, BlobMetadataValue> metadata) {
Review Comment:
sorry if I was unclear, for some reason githib's UI didn't want to handle
diff mode yesterday somehow
for naming my suggestion is
```suggestion
record BlobMetadata(Map<BlobMetadataName, BlobMetadataValue> value) {
```
The tests are in the next commit but that's where I noticed the
`.metadata().metadata()` changing that to value ( turns it in
.metadata().value())` which is a pattern I use ahdn have seen used for
ValueObjectÅ› or objects with a similar intent.
I'm quite sure there are already cases of such a pattern in james
would you mind adding a `get(BlobMetadataName name)` directly on the
`BlobMetadata` which delegates to the map obviously ?
This would reduce the need for consumers to dereference the full underlying
map in order to get an attribute other than content encoding? and improve
encapsulation as well as promote the immutability of the api.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]