mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Replace Java 8 methods
This commit is contained in:
parent
6bcf36913e
commit
523d155241
2 changed files with 12 additions and 3 deletions
|
|
@ -56,6 +56,9 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.github.wnameless.json.flattener.JsonFlattener;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -97,6 +100,7 @@ public class ElasticsearchInterpreter extends Interpreter {
|
|||
public static final String ELASTICSEARCH_BASIC_AUTH_USERNAME = "elasticsearch.basicauth.username";
|
||||
public static final String ELASTICSEARCH_BASIC_AUTH_PASSWORD = "elasticsearch.basicauth.password";
|
||||
|
||||
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
private ElasticsearchClient elsClient;
|
||||
private int resultSize = 10;
|
||||
|
||||
|
|
@ -260,7 +264,7 @@ public class ElasticsearchInterpreter extends Interpreter {
|
|||
|
||||
final String index = urlItems[0];
|
||||
final String type = urlItems[1];
|
||||
final String id = String.join("/", Arrays.copyOfRange(urlItems, 2, urlItems.length));
|
||||
final String id = StringUtils.join(Arrays.copyOfRange(urlItems, 2, urlItems.length), '/');
|
||||
|
||||
if (StringUtils.isEmpty(index)
|
||||
|| StringUtils.isEmpty(type)
|
||||
|
|
@ -302,14 +306,15 @@ public class ElasticsearchInterpreter extends Interpreter {
|
|||
final ActionResponse response = elsClient.get(indexTypeId[0], indexTypeId[1], indexTypeId[2]);
|
||||
|
||||
if (response.isSucceeded()) {
|
||||
final String json = response.getHit().getSourceAsString();
|
||||
final JsonObject json = response.getHit().getSourceAsJsonObject();
|
||||
final String jsonStr = gson.toJson(json);
|
||||
|
||||
addAngularObject(interpreterContext, "get", json);
|
||||
|
||||
return new InterpreterResult(
|
||||
InterpreterResult.Code.SUCCESS,
|
||||
InterpreterResult.Type.TEXT,
|
||||
json);
|
||||
jsonStr);
|
||||
}
|
||||
|
||||
return new InterpreterResult(InterpreterResult.Code.ERROR, "Document not found");
|
||||
|
|
|
|||
|
|
@ -126,6 +126,10 @@ public class ElasticsearchInterpreterTest {
|
|||
.get();
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(3600000);
|
||||
} catch (final Exception e) {}
|
||||
|
||||
final Properties props = new Properties();
|
||||
props.put(ElasticsearchInterpreter.ELASTICSEARCH_HOST, ELS_HOST);
|
||||
props.put(ElasticsearchInterpreter.ELASTICSEARCH_CLUSTER_NAME, ELS_CLUSTER_NAME);
|
||||
|
|
|
|||
Loading…
Reference in a new issue