-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce a ResolvedBucketName type to avoid temporal coupling (and e… #1754
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/**************************************************************** | ||
* Licensed to the Apache Software Foundation (ASF) under one * | ||
* or more contributor license agreements. See the NOTICE file * | ||
* distributed with this work for additional information * | ||
* regarding copyright ownership. The ASF licenses this file * | ||
* to you 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 * | ||
* * | ||
* http://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 org.apache.james.blob.api; | ||
|
||
import com.google.common.base.MoreObjects; | ||
import com.google.common.base.Preconditions; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.Objects; | ||
|
||
public final class ResolvedBucketName { | ||
public static ResolvedBucketName of(String value) { | ||
return new ResolvedBucketName(value); | ||
} | ||
|
||
private final String value; | ||
|
||
private ResolvedBucketName(String value) { | ||
Preconditions.checkNotNull(value); | ||
Preconditions.checkArgument(StringUtils.isNotBlank(value), "`value` cannot be blank"); | ||
|
||
this.value = value; | ||
} | ||
|
||
public String asString() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public final boolean equals(Object o) { | ||
if (o instanceof ResolvedBucketName) { | ||
ResolvedBucketName that = (ResolvedBucketName) o; | ||
return Objects.equals(this.value, that.value); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public final int hashCode() { | ||
return Objects.hash(value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("value", value) | ||
.toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import org.apache.james.blob.api.BucketName; | ||
|
||
import com.google.common.base.Preconditions; | ||
import org.apache.james.blob.api.ResolvedBucketName; | ||
|
||
public class BucketNameResolver { | ||
static class Builder { | ||
|
@@ -84,33 +85,39 @@ private BucketNameResolver(Optional<BucketName> namespace, Optional<String> pref | |
this.prefix = prefix; | ||
} | ||
|
||
BucketName resolve(BucketName bucketName) { | ||
ResolvedBucketName resolve(BucketName bucketName) { | ||
Preconditions.checkNotNull(bucketName); | ||
|
||
if (isNameSpace(bucketName)) { | ||
return bucketName; | ||
return ResolvedBucketName.of(bucketName.asString()); | ||
} | ||
return prefix | ||
.map(bucketPrefix -> BucketName.of(bucketPrefix + bucketName.asString())) | ||
.orElse(bucketName); | ||
.map(bucketPrefix -> ResolvedBucketName.of(bucketPrefix + bucketName.asString())) | ||
.orElse(ResolvedBucketName.of(bucketName.asString())); | ||
} | ||
|
||
Optional<BucketName> unresolve(BucketName bucketName) { | ||
Optional<BucketName> unresolve(ResolvedBucketName bucketName) { | ||
if (isNameSpace(bucketName)) { | ||
return Optional.of(bucketName); | ||
return Optional.of(BucketName.of(bucketName.asString())); | ||
} | ||
|
||
return prefix.map(p -> { | ||
if (bucketName.asString().startsWith(p)) { | ||
return Optional.of(BucketName.of(bucketName.asString().substring(p.length()))); | ||
} | ||
return Optional.<BucketName>empty(); | ||
}).orElse(Optional.of(bucketName)); | ||
}).orElse(Optional.of(BucketName.of(bucketName.asString()))); | ||
} | ||
|
||
private boolean isNameSpace(BucketName bucketName) { | ||
return namespace | ||
.map(existingNamespace -> existingNamespace.equals(bucketName)) | ||
.map(existingNamespace -> existingNamespace.asString().equals(bucketName.asString())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 thought: the namespace term is also called defaultBucketName in other places ( it is called namespace in the configuration file, the configuration builder accepts a namespace setter but when building the actual configuration object it injects the namespace into a field named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❔ question: why change the equality from I understand why it is necessary in the overload of |
||
.orElse(false); | ||
} | ||
|
||
private boolean isNameSpace(ResolvedBucketName bucketName) { | ||
return namespace | ||
.map(existingNamespace -> existingNamespace.asString().equals(bucketName.asString())) | ||
.orElse(false); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This POJO is defined in the API but only used in blob-s3.
I think introducing it is a good idea, but we should avoid poluting the API and move it into blob-s3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @chibenwa ,
Do you have a plan to migrate to Java 14 (or 16), this will prevent from lot of code like this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we upgrade better a LTS version, so 17 (or even 21 would be better, but maybe too big of a jump?)
I would support such a migration, but I'm not sure the all community is ready to upgrade their java version :)
Could perhaps start a thread on the ML though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You
is out of place, as a community we should embrasse awe
.I would personnalyy support a switch to Java 17 or even 21.
Do you think you can pull off a mail on this topic on the mailing lists?