This is an automated email from the ASF dual-hosted git repository.
pdallig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 7c08a828eb [ZEPPELIN-6262] Refactor ElasticsearchClientTypeBuilder for
safer enum handling and blank input support
7c08a828eb is described below
commit 7c08a828eb2a172273732ecca3214eed592eccb2
Author: Gyeongtae Park <[email protected]>
AuthorDate: Tue Jul 29 16:36:19 2025 +0900
[ZEPPELIN-6262] Refactor ElasticsearchClientTypeBuilder for safer enum
handling and blank input support
### What is this PR for?
This PR refactors the ElasticsearchClientTypeBuilder class to improve its
robustness and readability:
- Replaces StringUtils.isEmpty() with StringUtils.isBlank() to treat
whitespace-only strings as invalid input
- Simplifies enum parsing by removing redundant checks and using a
try-catch block around Enum.valueOf(...)
- Ensures that invalid or null inputs gracefully fall back to
ElasticsearchClientType.UNKNOWN
### What type of PR is it?
Refactoring
### Todos
* [x] - Verify existing tests
### What is the Jira issue?
* Jira: https://issues.apache.org/jira/browse/ZEPPELIN-6262
### How should this be tested?
N/A
### Screenshots (if appropriate)
N/A
### Questions:
* Does the license files need to update? No.
* Is there breaking changes for older versions? No.
* Does this needs documentation? No.
Closes #5002 from ParkGyeongTae/ZEPPELIN-6262.
Signed-off-by: Philipp Dallig <[email protected]>
---
.../client/ElasticsearchClientTypeBuilder.java | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git
a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeBuilder.java
b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeBuilder.java
index 619cb4a6bc..e36c9b4a5d 100644
---
a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeBuilder.java
+++
b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeBuilder.java
@@ -19,12 +19,8 @@ package org.apache.zeppelin.elasticsearch.client;
import org.apache.commons.lang3.StringUtils;
-import java.util.Arrays;
-
import static
org.apache.zeppelin.elasticsearch.client.ElasticsearchClientType.TRANSPORT;
import static
org.apache.zeppelin.elasticsearch.client.ElasticsearchClientType.UNKNOWN;
-import static
org.apache.zeppelin.elasticsearch.client.ElasticsearchClientType.valueOf;
-import static
org.apache.zeppelin.elasticsearch.client.ElasticsearchClientType.values;
public class ElasticsearchClientTypeBuilder {
@@ -47,18 +43,17 @@ public class ElasticsearchClientTypeBuilder {
@Override
public ElasticsearchClientType build() {
- boolean isEmpty = StringUtils.isEmpty(propertyValue);
- return isEmpty ?
- DEFAULT_ELASTICSEARCH_CLIENT_TYPE :
- getElasticsearchClientType(propertyValue);
+ return StringUtils.isBlank(propertyValue) ?
+ DEFAULT_ELASTICSEARCH_CLIENT_TYPE :
+ getElasticsearchClientType(propertyValue);
}
private ElasticsearchClientType getElasticsearchClientType(String
propertyValue){
- boolean isExistingValue =
- Arrays
- .stream(values())
- .anyMatch(clientType ->
clientType.toString().equalsIgnoreCase(propertyValue));
- return isExistingValue ? valueOf(propertyValue.toUpperCase()) : UNKNOWN;
+ try {
+ return ElasticsearchClientType.valueOf(propertyValue.toUpperCase());
+ } catch (IllegalArgumentException e) {
+ return UNKNOWN;
+ }
}
}
}