diff --git a/src/main/java/org/opensearch/commons/InjectSecurity.java b/src/main/java/org/opensearch/commons/InjectSecurity.java index c6d581f6..1c79758f 100644 --- a/src/main/java/org/opensearch/commons/InjectSecurity.java +++ b/src/main/java/org/opensearch/commons/InjectSecurity.java @@ -14,7 +14,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.common.Strings; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.commons.authuser.User; @@ -111,7 +110,7 @@ public void inject(final String user, final List roles) { * @param user name */ public void injectUser(final String user) { - if (Strings.isNullOrEmpty(user)) { + if (user.isEmpty()) { return; } @@ -148,7 +147,7 @@ public void injectUserInfo(final User user) { joiner.add(java.lang.String.join(",", user.getBackendRoles())); joiner.add(java.lang.String.join(",", user.getRoles())); String requestedTenant = user.getRequestedTenant(); - if (!Strings.isNullOrEmpty(requestedTenant)) { + if (!requestedTenant.isEmpty()) { joiner.add(requestedTenant); } threadContext.putTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, joiner.toString()); @@ -181,7 +180,7 @@ public void injectRoles(final List roles) { * @return boolean */ public boolean injectProperty(final String property, final Object value) { - if (Strings.isNullOrEmpty(property) || value == null || threadContext.getTransient(property) != null) { + if (property == null || property.isEmpty() || value == null || threadContext.getTransient(property) != null) { log.debug("{}, InjectSecurity - cannot inject property: {}", Thread.currentThread().getName(), id); return false; } else { diff --git a/src/main/java/org/opensearch/commons/authuser/AuthUserRequestBuilder.java b/src/main/java/org/opensearch/commons/authuser/AuthUserRequestBuilder.java index 32602744..69ad353e 100644 --- a/src/main/java/org/opensearch/commons/authuser/AuthUserRequestBuilder.java +++ b/src/main/java/org/opensearch/commons/authuser/AuthUserRequestBuilder.java @@ -7,14 +7,13 @@ import org.opensearch.client.Request; import org.opensearch.client.RequestOptions; -import org.opensearch.common.Strings; import org.opensearch.commons.ConfigConstants; public class AuthUserRequestBuilder { private final String auth; public AuthUserRequestBuilder(String auth) { - if (Strings.isNullOrEmpty(auth)) { + if (auth.isEmpty()) { throw new IllegalArgumentException("Authorization token cannot be null"); } this.auth = auth; diff --git a/src/main/java/org/opensearch/commons/authuser/User.java b/src/main/java/org/opensearch/commons/authuser/User.java index b271b371..a2654b58 100644 --- a/src/main/java/org/opensearch/commons/authuser/User.java +++ b/src/main/java/org/opensearch/commons/authuser/User.java @@ -17,7 +17,6 @@ import org.apache.http.util.EntityUtils; import org.opensearch.client.Response; import org.opensearch.common.Nullable; -import org.opensearch.common.Strings; import org.opensearch.common.inject.internal.ToStringBuilder; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -89,7 +88,7 @@ public User(final Response response) throws IOException { @SuppressWarnings("unchecked") public User(String json) { - if (Strings.isNullOrEmpty(json)) { + if (json.isEmpty()) { throw new IllegalArgumentException("Response json cannot be null"); } @@ -158,12 +157,12 @@ public static User parse(XContentParser parser) throws IOException { * @return */ public static User parse(final String userString) { - if (Strings.isNullOrEmpty(userString)) { + if (userString == null || userString.isEmpty()) { return null; } String[] strs = userString.split("\\|"); - if ((strs.length == 0) || (Strings.isNullOrEmpty(strs[0]))) { + if (strs.length == 0 || strs[0] == null || strs[0].isEmpty()) { return null; } @@ -172,13 +171,13 @@ public static User parse(final String userString) { List roles = new ArrayList<>(); String requestedTenant = null; - if ((strs.length > 1) && !Strings.isNullOrEmpty(strs[1])) { + if ((strs.length > 1) && !strs[1].isEmpty()) { backendRoles.addAll(Arrays.asList(strs[1].split(","))); } - if ((strs.length > 2) && !Strings.isNullOrEmpty(strs[2])) { + if ((strs.length > 2) && !strs[2].isEmpty()) { roles.addAll(Arrays.asList(strs[2].split(","))); } - if ((strs.length > 3) && !Strings.isNullOrEmpty(strs[3])) { + if ((strs.length > 3) && !strs[3].isEmpty()) { requestedTenant = strs[3].trim(); } return new User(userName, backendRoles, roles, Arrays.asList(), requestedTenant); diff --git a/src/main/java/org/opensearch/commons/destination/message/LegacyBaseMessage.java b/src/main/java/org/opensearch/commons/destination/message/LegacyBaseMessage.java index 96bd06ba..511e544d 100644 --- a/src/main/java/org/opensearch/commons/destination/message/LegacyBaseMessage.java +++ b/src/main/java/org/opensearch/commons/destination/message/LegacyBaseMessage.java @@ -11,7 +11,6 @@ import java.util.Map; import org.apache.http.client.utils.URIBuilder; -import org.opensearch.common.Strings; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; @@ -31,7 +30,7 @@ public abstract class LegacyBaseMessage implements Writeable { if (destinationType == null) { throw new IllegalArgumentException("Channel type must be defined"); } - if (!Strings.hasLength(destinationName)) { + if (destinationName == null || destinationName.isEmpty()) { throw new IllegalArgumentException("Channel name must be defined"); } this.destinationType = destinationType; @@ -80,8 +79,8 @@ public URI getUri() { protected URI buildUri(String endpoint, String scheme, String host, int port, String path, Map queryParams) { try { - if (Strings.isNullOrEmpty(endpoint)) { - if (Strings.isNullOrEmpty(scheme)) { + if (endpoint.isEmpty()) { + if (scheme.isEmpty()) { scheme = "https"; } URIBuilder uriBuilder = new URIBuilder(); diff --git a/src/main/java/org/opensearch/commons/destination/message/LegacyChimeMessage.java b/src/main/java/org/opensearch/commons/destination/message/LegacyChimeMessage.java index 31b45d1f..4a47339c 100644 --- a/src/main/java/org/opensearch/commons/destination/message/LegacyChimeMessage.java +++ b/src/main/java/org/opensearch/commons/destination/message/LegacyChimeMessage.java @@ -7,7 +7,6 @@ import java.io.IOException; -import org.opensearch.common.Strings; import org.opensearch.common.io.stream.StreamInput; /** @@ -19,7 +18,7 @@ public class LegacyChimeMessage extends LegacyBaseMessage { private LegacyChimeMessage(final String destinationName, final String url, final String message) { super(LegacyDestinationType.LEGACY_CHIME, destinationName, message, url); - if (Strings.isNullOrEmpty(message)) { + if (message == null || message.isEmpty()) { throw new IllegalArgumentException("Message content is missing"); } diff --git a/src/main/java/org/opensearch/commons/destination/message/LegacyCustomWebhookMessage.java b/src/main/java/org/opensearch/commons/destination/message/LegacyCustomWebhookMessage.java index dbc4b7df..6f831bed 100644 --- a/src/main/java/org/opensearch/commons/destination/message/LegacyCustomWebhookMessage.java +++ b/src/main/java/org/opensearch/commons/destination/message/LegacyCustomWebhookMessage.java @@ -12,7 +12,6 @@ import org.apache.http.client.methods.HttpPatch; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; -import org.opensearch.common.Strings; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -45,28 +44,28 @@ private LegacyCustomWebhookMessage( ) { super(LegacyDestinationType.LEGACY_CUSTOM_WEBHOOK, destinationName, message); - if (!Strings.isNullOrEmpty(url)) { + if (url != null && !url.isEmpty()) { setUrl(url.trim()); } - if (Strings.isNullOrEmpty(message)) { + if (message == null || message.isEmpty()) { throw new IllegalArgumentException("Message content is missing"); } - this.scheme = Strings.isNullOrEmpty(scheme) ? "https" : scheme; + this.scheme = scheme == null || scheme.isEmpty() ? "https" : scheme; this.port = port == null ? -1 : port; - if (!Strings.isNullOrEmpty(path)) { + if (path != null && !path.isEmpty()) { if (!path.startsWith("/")) { this.path = "/" + path; } } - if (Strings.isNullOrEmpty(url) && Strings.isNullOrEmpty(host)) { + if ((url == null || url.isEmpty()) && (host == null || host.isEmpty())) { throw new IllegalArgumentException("Either fully qualified URL or host name should be provided"); } - if (Strings.isNullOrEmpty(method)) { + if (method == null || method.isEmpty()) { // Default to POST for backwards compatibility this.method = "POST"; } else if (!HttpPost.METHOD_NAME.equals(method) && !HttpPut.METHOD_NAME.equals(method) && !HttpPatch.METHOD_NAME.equals(method)) { @@ -239,7 +238,7 @@ public void writeTo(StreamOutput streamOutput) throws IOException { // Making LegacyCustomWebhookMessage streamable is purely to support the new pass through API from Alerting/ISM -> Notification // plugin // and it only supports LegacyCustomWebhookMessage when the url is already constructed by Alerting/ISM. - if (Strings.isNullOrEmpty(getUrl())) { + if (getUrl() == null || getUrl().isEmpty()) { throw new IllegalStateException("Cannot use LegacyCustomWebhookMessage across transport wire without defining full url."); } streamOutput.writeOptionalString(url); diff --git a/src/main/java/org/opensearch/commons/destination/message/LegacyEmailMessage.java b/src/main/java/org/opensearch/commons/destination/message/LegacyEmailMessage.java index 01810868..843833ad 100644 --- a/src/main/java/org/opensearch/commons/destination/message/LegacyEmailMessage.java +++ b/src/main/java/org/opensearch/commons/destination/message/LegacyEmailMessage.java @@ -9,7 +9,6 @@ import java.net.URI; import java.util.List; -import org.opensearch.common.Strings; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.commons.notifications.model.MethodType; @@ -41,19 +40,19 @@ private LegacyEmailMessage( ) { super(LegacyDestinationType.LEGACY_EMAIL, destinationName, message); - if (Strings.isNullOrEmpty(message)) { + if (message == null || message.isEmpty()) { throw new IllegalArgumentException("Message content is missing"); } - if (Strings.isNullOrEmpty(accountName)) { + if (accountName == null || accountName.isEmpty()) { throw new IllegalArgumentException("Account name should be provided"); } - if (Strings.isNullOrEmpty(host)) { + if (host == null || host.isEmpty()) { throw new IllegalArgumentException("Host name should be provided"); } - if (Strings.isNullOrEmpty(from)) { + if (from == null || from.isEmpty()) { throw new IllegalArgumentException("From address should be provided"); } @@ -66,7 +65,7 @@ private LegacyEmailMessage( this.host = host; this.port = port == null ? 25 : port; - if (Strings.isNullOrEmpty(method)) { + if ((method.isEmpty())) { // Default to "none" this.method = "none"; } else if (!MethodType.NONE.toString().equals(method) @@ -79,7 +78,7 @@ private LegacyEmailMessage( this.from = from; this.recipients = recipients; - this.subject = Strings.isNullOrEmpty(subject) ? destinationName : subject; + this.subject = (subject == null || subject.isEmpty()) ? destinationName : subject; } public LegacyEmailMessage(StreamInput streamInput) throws IOException { diff --git a/src/main/java/org/opensearch/commons/destination/message/LegacySNSMessage.java b/src/main/java/org/opensearch/commons/destination/message/LegacySNSMessage.java index f8cf6a5b..1b5114c0 100644 --- a/src/main/java/org/opensearch/commons/destination/message/LegacySNSMessage.java +++ b/src/main/java/org/opensearch/commons/destination/message/LegacySNSMessage.java @@ -7,7 +7,6 @@ import java.io.IOException; -import org.opensearch.common.Strings; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.commons.destination.util.Util; @@ -33,18 +32,18 @@ private LegacySNSMessage( ) { super(LegacyDestinationType.LEGACY_SNS, destinationName, message); - if (Strings.isNullOrEmpty(message)) { + if (message.isEmpty()) { throw new IllegalArgumentException("Message content is missing"); } - if (Strings.isNullOrEmpty(roleArn) || !Util.isValidIAMArn(roleArn)) { + if (roleArn.isEmpty() || !Util.isValidIAMArn(roleArn)) { throw new IllegalArgumentException("Role arn is missing/invalid: " + roleArn); } - if (Strings.isNullOrEmpty(topicArn) || !Util.isValidSNSArn(topicArn)) { + if (topicArn.isEmpty() || !Util.isValidSNSArn(topicArn)) { throw new IllegalArgumentException("Topic arn is missing/invalid: " + topicArn); } - if (Strings.isNullOrEmpty(message)) { + if (message.isEmpty()) { throw new IllegalArgumentException("Message content is missing"); } diff --git a/src/main/java/org/opensearch/commons/destination/message/LegacySlackMessage.java b/src/main/java/org/opensearch/commons/destination/message/LegacySlackMessage.java index 02d30bb4..55047273 100644 --- a/src/main/java/org/opensearch/commons/destination/message/LegacySlackMessage.java +++ b/src/main/java/org/opensearch/commons/destination/message/LegacySlackMessage.java @@ -7,7 +7,6 @@ import java.io.IOException; -import org.opensearch.common.Strings; import org.opensearch.common.io.stream.StreamInput; /** @@ -19,11 +18,11 @@ public class LegacySlackMessage extends LegacyBaseMessage { private LegacySlackMessage(final String destinationName, final String url, final String message) { super(LegacyDestinationType.LEGACY_SLACK, destinationName, message, url); - if (Strings.isNullOrEmpty(url)) { // add URL validation + if ((url.isEmpty())) { // add URL validation throw new IllegalArgumentException("Fully qualified URL is missing/invalid: " + url); } - if (Strings.isNullOrEmpty(message)) { + if (message == null || message.isEmpty()) { throw new IllegalArgumentException("Message content is missing"); } diff --git a/src/main/java/org/opensearch/commons/destination/util/Util.java b/src/main/java/org/opensearch/commons/destination/util/Util.java index 9cb65ccb..7eaa221e 100644 --- a/src/main/java/org/opensearch/commons/destination/util/Util.java +++ b/src/main/java/org/opensearch/commons/destination/util/Util.java @@ -7,7 +7,6 @@ import java.util.regex.Pattern; -import org.opensearch.common.Strings; import org.opensearch.common.ValidationException; public class Util { @@ -26,10 +25,10 @@ public static String getRegion(String arn) { } public static boolean isValidIAMArn(String arn) { - return Strings.hasLength(arn) && IAM_ARN_REGEX.matcher(arn).find(); + return !arn.isEmpty() && IAM_ARN_REGEX.matcher(arn).find(); } public static boolean isValidSNSArn(String arn) throws ValidationException { - return Strings.hasLength(arn) && SNS_ARN_REGEX.matcher(arn).find(); + return !arn.isEmpty() && SNS_ARN_REGEX.matcher(arn).find(); } } diff --git a/src/main/java/org/opensearch/commons/rest/SecureRestClientBuilder.java b/src/main/java/org/opensearch/commons/rest/SecureRestClientBuilder.java index d4d33e97..49ac8aa8 100644 --- a/src/main/java/org/opensearch/commons/rest/SecureRestClientBuilder.java +++ b/src/main/java/org/opensearch/commons/rest/SecureRestClientBuilder.java @@ -33,27 +33,26 @@ import org.opensearch.client.RestClient; import org.opensearch.client.RestClientBuilder; import org.opensearch.client.RestHighLevelClient; -import org.opensearch.common.Strings; import org.opensearch.common.settings.Settings; import org.opensearch.commons.ConfigConstants; /** * Provides builder to create low-level and high-level REST client to make calls to OpenSearch. - * + *

* Sample usage: - * SecureRestClientBuilder builder = new SecureRestClientBuilder(settings).build() - * RestClient restClient = builder.build(); - * + * SecureRestClientBuilder builder = new SecureRestClientBuilder(settings).build() + * RestClient restClient = builder.build(); + *

* Other usage: - * RestClient restClient = new SecureRestClientBuilder("localhost", 9200, false) - * .setUserPassword("admin", "admin") - * .setTrustCerts(trustStorePath) - * .build(); - * - * + * RestClient restClient = new SecureRestClientBuilder("localhost", 9200, false) + * .setUserPassword("admin", "admin") + * .setTrustCerts(trustStorePath) + * .build(); + *

+ *

* If https is enabled, creates RestClientBuilder using self-signed certificates or passed pem * as trusted. - * + *

* If https is not enabled, creates a http based client. */ public class SecureRestClientBuilder { @@ -74,6 +73,7 @@ public class SecureRestClientBuilder { /** * ONLY for integration tests. + * * @param host * @param port * @param httpSSLEnabled @@ -87,7 +87,7 @@ public SecureRestClientBuilder( final String user, final String passWord ) { - if (Strings.isNullOrEmpty(user) || Strings.isNullOrEmpty(passWord)) { + if (user.isEmpty() || passWord.isEmpty()) { throw new IllegalArgumentException("Invalid user or password"); } @@ -101,6 +101,7 @@ public SecureRestClientBuilder( /** * ONLY for integration tests. + * * @param httpHosts * @param httpSSLEnabled * @param user @@ -108,7 +109,7 @@ public SecureRestClientBuilder( */ public SecureRestClientBuilder(HttpHost[] httpHosts, final boolean httpSSLEnabled, final String user, final String passWord) { - if (Strings.isNullOrEmpty(user) || Strings.isNullOrEmpty(passWord)) { + if (user.isEmpty() || passWord.isEmpty()) { throw new IllegalArgumentException("Invalid user or password"); } @@ -143,6 +144,7 @@ public SecureRestClientBuilder(Settings settings, Path configPath, HttpHost[] ht /** * Creates a low-level Rest client. + * * @return * @throws IOException */ @@ -152,6 +154,7 @@ public RestClient build() throws IOException { /** * Creates a high-level Rest client. + * * @return * @throws IOException */ @@ -214,7 +217,7 @@ private SSLContext createSSLContext() throws IOException, GeneralSecurityExcepti if (httpSSLEnabled) { // Handle trust store String pemFile = getTrustPem(); - if (Strings.isNullOrEmpty(pemFile)) { + if (pemFile == null || pemFile.isEmpty()) { builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); } else { String pem = resolve(pemFile, configPath); @@ -233,7 +236,7 @@ private SSLContext createSSLContext() throws IOException, GeneralSecurityExcepti } private CredentialsProvider createCredsProvider() { - if (Strings.isNullOrEmpty(user) || Strings.isNullOrEmpty(passwd)) + if (user == null || user.isEmpty() || passwd == null || passwd.isEmpty()) return null; final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); @@ -284,7 +287,7 @@ private KeyStore getKeyStore() throws IOException, GeneralSecurityException { KeyStore keyStore = KeyStore.getInstance("jks"); String keyStoreFile = settings.get(ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH, null); String passwd = settings.get(ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD, null); - if (Strings.isNullOrEmpty(keyStoreFile) || Strings.isNullOrEmpty(passwd)) { + if (keyStoreFile == null || keyStoreFile.isEmpty() || passwd == null || passwd.isEmpty()) { return null; } String keyStorePath = resolve(keyStoreFile, configPath); diff --git a/src/main/kotlin/org/opensearch/commons/notifications/action/UpdateNotificationConfigRequest.kt b/src/main/kotlin/org/opensearch/commons/notifications/action/UpdateNotificationConfigRequest.kt index 414540d1..236d679f 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/action/UpdateNotificationConfigRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/action/UpdateNotificationConfigRequest.kt @@ -7,7 +7,6 @@ package org.opensearch.commons.notifications.action import org.opensearch.action.ActionRequest import org.opensearch.action.ActionRequestValidationException import org.opensearch.action.ValidateActions -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -116,7 +115,7 @@ class UpdateNotificationConfigRequest : ActionRequest, ToXContentObject { */ override fun validate(): ActionRequestValidationException? { var validationException: ActionRequestValidationException? = null - if (Strings.isNullOrEmpty(configId)) { + if (configId.isNullOrEmpty()) { validationException = ValidateActions.addValidationError("configId is null or empty", validationException) } return validationException diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/Channel.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/Channel.kt index 2345449b..197a5fd6 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/Channel.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/Channel.kt @@ -4,7 +4,6 @@ */ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -32,8 +31,8 @@ data class Channel( ) : BaseModel { init { - require(!Strings.isNullOrEmpty(name)) { "name is null or empty" } - require(!Strings.isNullOrEmpty(configId)) { "config id is null or empty" } + require(!name.isNullOrEmpty()) { "name is null or empty" } + require(!configId.isNullOrEmpty()) { "config id is null or empty" } } companion object { diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/ChannelMessage.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/ChannelMessage.kt index f0fd4aef..4b92e0e2 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/ChannelMessage.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/ChannelMessage.kt @@ -5,7 +5,6 @@ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -30,7 +29,7 @@ data class ChannelMessage( ) : BaseModel { init { - require(!Strings.isNullOrEmpty(textDescription)) { "text message part is null or empty" } + require(!textDescription.isNullOrEmpty()) { "text message part is null or empty" } } companion object { diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/Chime.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/Chime.kt index 3783c430..83c05fa4 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/Chime.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/Chime.kt @@ -4,7 +4,6 @@ */ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -25,7 +24,7 @@ data class Chime( ) : BaseConfigData { init { - require(!Strings.isNullOrEmpty(url)) { "URL is null or empty" } + require(!url.isNullOrEmpty()) { "URL is null or empty" } validateUrl(url) } diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/DeliveryStatus.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/DeliveryStatus.kt index 1e15a6b7..f1d16106 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/DeliveryStatus.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/DeliveryStatus.kt @@ -4,7 +4,6 @@ */ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -26,8 +25,8 @@ data class DeliveryStatus( ) : BaseModel { init { - require(!Strings.isNullOrEmpty(statusCode)) { "StatusCode is null or empty" } - require(!Strings.isNullOrEmpty(statusText)) { "statusText is null or empty" } + require(statusCode.isNotEmpty()) { "StatusCode is null or empty" } + require(statusText.isNotEmpty()) { "statusText is null or empty" } } companion object { diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/Email.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/Email.kt index 52cc8c4c..309f215c 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/Email.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/Email.kt @@ -4,7 +4,6 @@ */ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -30,7 +29,7 @@ data class Email( ) : BaseConfigData { init { - require(!Strings.isNullOrEmpty(emailAccountID)) { "emailAccountID is null or empty" } + require(emailAccountID.isNotEmpty()) { "emailAccountID is null or empty" } } companion object { diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/EventSource.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/EventSource.kt index a4625e0b..cbc68e51 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/EventSource.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/EventSource.kt @@ -4,7 +4,6 @@ */ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -31,7 +30,7 @@ data class EventSource( ) : BaseModel { init { - require(!Strings.isNullOrEmpty(title)) { "name is null or empty" } + require(title.isNotEmpty()) { "name is null or empty" } } companion object { diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/EventStatus.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/EventStatus.kt index 4ca07c2a..b314904b 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/EventStatus.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/EventStatus.kt @@ -5,7 +5,6 @@ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -35,8 +34,8 @@ data class EventStatus( ) : BaseModel { init { - require(!Strings.isNullOrEmpty(configId)) { "config id is null or empty" } - require(!Strings.isNullOrEmpty(configName)) { "config name is null or empty" } + require(configId.isNotEmpty()) { "config id is null or empty" } + require(configName.isNotEmpty()) { "config name is null or empty" } when (configType) { ConfigType.CHIME -> requireNotNull(deliveryStatus) ConfigType.WEBHOOK -> requireNotNull(deliveryStatus) diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/NotificationConfig.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/NotificationConfig.kt index 55e34808..3a0c8c57 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/NotificationConfig.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/NotificationConfig.kt @@ -4,7 +4,6 @@ */ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -35,7 +34,7 @@ data class NotificationConfig( ) : BaseModel { init { - require(!Strings.isNullOrEmpty(name)) { "name is null or empty" } + require(name.isNotEmpty()) { "name is null or empty" } if (!validateConfigData(configType, configData)) { throw IllegalArgumentException("ConfigType: $configType and data doesn't match") } diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/NotificationConfigInfo.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/NotificationConfigInfo.kt index af83376e..4c448062 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/NotificationConfigInfo.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/NotificationConfigInfo.kt @@ -5,7 +5,6 @@ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -32,7 +31,7 @@ data class NotificationConfigInfo( ) : BaseModel { init { - require(!Strings.isNullOrEmpty(configId)) { "config id is null or empty" } + require(configId.isNotEmpty()) { "config id is null or empty" } } companion object { diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/SesAccount.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/SesAccount.kt index ce169fed..c4c515e0 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/SesAccount.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/SesAccount.kt @@ -5,7 +5,6 @@ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -32,7 +31,7 @@ data class SesAccount( ) : BaseConfigData { init { - require(!Strings.isNullOrEmpty(awsRegion)) { "awsRegion is null or empty" } + require(awsRegion.isNotEmpty()) { "awsRegion is null or empty" } validateEmail(fromAddress) if (roleArn != null) { validateIamRoleArn(roleArn) diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/Slack.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/Slack.kt index aad4b7e7..25139a9f 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/Slack.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/Slack.kt @@ -4,7 +4,6 @@ */ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -25,7 +24,7 @@ data class Slack( ) : BaseConfigData { init { - require(!Strings.isNullOrEmpty(url)) { "URL is null or empty" } + require(url.isNotEmpty()) { "URL is null or empty" } validateUrl(url) } diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/SmtpAccount.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/SmtpAccount.kt index fc563bc7..b33db1e4 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/SmtpAccount.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/SmtpAccount.kt @@ -4,7 +4,6 @@ */ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -31,7 +30,7 @@ data class SmtpAccount( ) : BaseConfigData { init { - require(!Strings.isNullOrEmpty(host)) { "host is null or empty" } + require(host.isNotEmpty()) { "host is null or empty" } require(port > 0) { "port should be positive value" } validateEmail(fromAddress) } diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/Webhook.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/Webhook.kt index 806bf123..f5e7a6ec 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/Webhook.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/Webhook.kt @@ -4,7 +4,6 @@ */ package org.opensearch.commons.notifications.model -import org.opensearch.common.Strings import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -31,7 +30,7 @@ data class Webhook( ) : BaseConfigData { init { - require(!Strings.isNullOrEmpty(url)) { "URL is null or empty" } + require(!url.isNullOrEmpty()) { "URL is null or empty" } validateUrl(url) } diff --git a/src/test/java/org/opensearch/commons/authuser/UserTest.java b/src/test/java/org/opensearch/commons/authuser/UserTest.java index 4df30a44..dc6925f6 100644 --- a/src/test/java/org/opensearch/commons/authuser/UserTest.java +++ b/src/test/java/org/opensearch/commons/authuser/UserTest.java @@ -15,7 +15,6 @@ import java.util.Arrays; import org.junit.jupiter.api.Test; -import org.opensearch.common.Strings; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.settings.Settings; @@ -44,7 +43,7 @@ public void testEmptyConst() { @Test public void testParamsConstForNoTenantUser() { User user = testNoTenantUser(); - assertFalse(Strings.isNullOrEmpty(user.getName())); + assertFalse(user.getName().isEmpty()); assertEquals(2, user.getBackendRoles().size()); assertEquals(1, user.getRoles().size()); assertEquals(2, user.getCustomAttNames().size()); @@ -54,11 +53,11 @@ public void testParamsConstForNoTenantUser() { @Test public void testParamsConstForTenantUser() { User user = testTenantUser(); - assertFalse(Strings.isNullOrEmpty(user.getName())); + assertFalse(user.getName().isEmpty()); assertEquals(2, user.getBackendRoles().size()); assertEquals(1, user.getRoles().size()); assertEquals(2, user.getCustomAttNames().size()); - assertFalse(Strings.isNullOrEmpty(user.getRequestedTenant())); + assertFalse(user.getRequestedTenant().isEmpty()); } @Test