forked from TrueCloudLab/frostfs-sdk-java
[#14] add lombok and refactor exceptions. Provide validator.
Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
parent
15cf0893c7
commit
388428af76
87 changed files with 819 additions and 970 deletions
|
@ -1,17 +1,20 @@
|
|||
package info.frostfs.sdk.jdo;
|
||||
|
||||
import info.frostfs.sdk.annotations.AtLeastOneIsFilled;
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.ChannelCredentials;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
|
||||
@Getter
|
||||
@FieldNameConstants
|
||||
@AtLeastOneIsFilled(fields = {ClientSettings.Fields.host, ClientSettings.Fields.channel})
|
||||
public class ClientSettings {
|
||||
private static final String ERROR_TEMPLATE = "%s required parameter.";
|
||||
private static final String KEY_NAME = "Key";
|
||||
private static final String HOST_AND_CHANNEL_NAME = "Host or Channel";
|
||||
|
||||
@NotNull
|
||||
private final String key;
|
||||
|
||||
private String host;
|
||||
private ChannelCredentials credentials;
|
||||
private Channel channel;
|
||||
|
@ -19,51 +22,16 @@ public class ClientSettings {
|
|||
public ClientSettings(String key, String host) {
|
||||
this.key = key;
|
||||
this.host = host;
|
||||
validate();
|
||||
}
|
||||
|
||||
public ClientSettings(String key, String host, ChannelCredentials credentials) {
|
||||
this.key = key;
|
||||
this.host = host;
|
||||
this.credentials = credentials;
|
||||
validate();
|
||||
}
|
||||
|
||||
public ClientSettings(String key, Channel channel) {
|
||||
this.key = key;
|
||||
this.channel = channel;
|
||||
validate();
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public ChannelCredentials getCredentials() {
|
||||
return credentials;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void validate() {
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
|
||||
if (StringUtils.isEmpty(key)) {
|
||||
errorMessage.append(String.format(ERROR_TEMPLATE, KEY_NAME)).append(System.lineSeparator());
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(host) && isNull(channel)) {
|
||||
errorMessage.append(String.format(ERROR_TEMPLATE, HOST_AND_CHANNEL_NAME)).append(System.lineSeparator());
|
||||
}
|
||||
|
||||
if (errorMessage.length() != 0) {
|
||||
throw new IllegalArgumentException(errorMessage.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue