diff --git a/build.xml b/build.xml
index 6affa3a..cffea64 100644
--- a/build.xml
+++ b/build.xml
@@ -5,7 +5,7 @@
-
+
@@ -84,8 +84,8 @@
-
-
+
+
diff --git a/lib/HdrHistogram-2.1.9.jar b/lib/HdrHistogram-2.1.9.jar
new file mode 100644
index 0000000..efa2637
Binary files /dev/null and b/lib/HdrHistogram-2.1.9.jar differ
diff --git a/lib/accessors-smart-1.2.jar b/lib/accessors-smart-1.2.jar
new file mode 100644
index 0000000..f4505e9
Binary files /dev/null and b/lib/accessors-smart-1.2.jar differ
diff --git a/lib/aggs-matrix-stats-client-7.5.1.jar b/lib/aggs-matrix-stats-client-7.5.1.jar
new file mode 100644
index 0000000..d469f2e
Binary files /dev/null and b/lib/aggs-matrix-stats-client-7.5.1.jar differ
diff --git a/lib/asm-5.0.4.jar b/lib/asm-5.0.4.jar
new file mode 100644
index 0000000..cdb283d
Binary files /dev/null and b/lib/asm-5.0.4.jar differ
diff --git a/lib/commons-codec-1.11.jar b/lib/commons-codec-1.11.jar
new file mode 100644
index 0000000..2245120
Binary files /dev/null and b/lib/commons-codec-1.11.jar differ
diff --git a/lib/commons-logging-1.1.3.jar b/lib/commons-logging-1.1.3.jar
new file mode 100644
index 0000000..ab51254
Binary files /dev/null and b/lib/commons-logging-1.1.3.jar differ
diff --git a/lib/compiler-0.9.6.jar b/lib/compiler-0.9.6.jar
new file mode 100644
index 0000000..96578e3
Binary files /dev/null and b/lib/compiler-0.9.6.jar differ
diff --git a/lib/elasticsearch-7.5.1.jar b/lib/elasticsearch-7.5.1.jar
new file mode 100644
index 0000000..46df036
Binary files /dev/null and b/lib/elasticsearch-7.5.1.jar differ
diff --git a/lib/elasticsearch-cli-7.5.1.jar b/lib/elasticsearch-cli-7.5.1.jar
new file mode 100644
index 0000000..d65e2c5
Binary files /dev/null and b/lib/elasticsearch-cli-7.5.1.jar differ
diff --git a/lib/elasticsearch-core-7.5.1.jar b/lib/elasticsearch-core-7.5.1.jar
new file mode 100644
index 0000000..c33a7e6
Binary files /dev/null and b/lib/elasticsearch-core-7.5.1.jar differ
diff --git a/lib/elasticsearch-geo-7.5.1.jar b/lib/elasticsearch-geo-7.5.1.jar
new file mode 100644
index 0000000..5a2d130
Binary files /dev/null and b/lib/elasticsearch-geo-7.5.1.jar differ
diff --git a/lib/elasticsearch-rest-client-7.5.1.jar b/lib/elasticsearch-rest-client-7.5.1.jar
new file mode 100644
index 0000000..eeea30b
Binary files /dev/null and b/lib/elasticsearch-rest-client-7.5.1.jar differ
diff --git a/lib/elasticsearch-rest-high-level-client-7.5.1.jar b/lib/elasticsearch-rest-high-level-client-7.5.1.jar
new file mode 100644
index 0000000..68efe0c
Binary files /dev/null and b/lib/elasticsearch-rest-high-level-client-7.5.1.jar differ
diff --git a/lib/elasticsearch-secure-sm-7.5.1.jar b/lib/elasticsearch-secure-sm-7.5.1.jar
new file mode 100644
index 0000000..e2a113e
Binary files /dev/null and b/lib/elasticsearch-secure-sm-7.5.1.jar differ
diff --git a/lib/elasticsearch-ssl-config-7.5.1.jar b/lib/elasticsearch-ssl-config-7.5.1.jar
new file mode 100644
index 0000000..0c44a95
Binary files /dev/null and b/lib/elasticsearch-ssl-config-7.5.1.jar differ
diff --git a/lib/elasticsearch-x-content-7.5.1.jar b/lib/elasticsearch-x-content-7.5.1.jar
new file mode 100644
index 0000000..b1b6234
Binary files /dev/null and b/lib/elasticsearch-x-content-7.5.1.jar differ
diff --git a/lib/hppc-0.8.1.jar b/lib/hppc-0.8.1.jar
new file mode 100644
index 0000000..39a7c24
Binary files /dev/null and b/lib/hppc-0.8.1.jar differ
diff --git a/lib/httpasyncclient-4.1.4.jar b/lib/httpasyncclient-4.1.4.jar
new file mode 100644
index 0000000..e6b3b29
Binary files /dev/null and b/lib/httpasyncclient-4.1.4.jar differ
diff --git a/lib/httpclient-4.5.10.jar b/lib/httpclient-4.5.10.jar
new file mode 100644
index 0000000..d0c7821
Binary files /dev/null and b/lib/httpclient-4.5.10.jar differ
diff --git a/lib/httpcore-4.4.12.jar b/lib/httpcore-4.4.12.jar
new file mode 100644
index 0000000..1838672
Binary files /dev/null and b/lib/httpcore-4.4.12.jar differ
diff --git a/lib/httpcore-nio-4.4.12.jar b/lib/httpcore-nio-4.4.12.jar
new file mode 100644
index 0000000..b6183e6
Binary files /dev/null and b/lib/httpcore-nio-4.4.12.jar differ
diff --git a/lib/jackson-core-2.8.11.jar b/lib/jackson-core-2.8.11.jar
new file mode 100644
index 0000000..27caa12
Binary files /dev/null and b/lib/jackson-core-2.8.11.jar differ
diff --git a/lib/jackson-dataformat-cbor-2.8.11.jar b/lib/jackson-dataformat-cbor-2.8.11.jar
new file mode 100644
index 0000000..8330550
Binary files /dev/null and b/lib/jackson-dataformat-cbor-2.8.11.jar differ
diff --git a/lib/jackson-dataformat-smile-2.8.11.jar b/lib/jackson-dataformat-smile-2.8.11.jar
new file mode 100644
index 0000000..142c798
Binary files /dev/null and b/lib/jackson-dataformat-smile-2.8.11.jar differ
diff --git a/lib/jackson-dataformat-yaml-2.8.11.jar b/lib/jackson-dataformat-yaml-2.8.11.jar
new file mode 100644
index 0000000..9054d1e
Binary files /dev/null and b/lib/jackson-dataformat-yaml-2.8.11.jar differ
diff --git a/lib/jna-4.5.1.jar b/lib/jna-4.5.1.jar
new file mode 100644
index 0000000..e220187
Binary files /dev/null and b/lib/jna-4.5.1.jar differ
diff --git a/lib/joda-time-2.10.3.jar b/lib/joda-time-2.10.3.jar
new file mode 100644
index 0000000..0de2c0b
Binary files /dev/null and b/lib/joda-time-2.10.3.jar differ
diff --git a/lib/jopt-simple-5.0.2.jar b/lib/jopt-simple-5.0.2.jar
new file mode 100644
index 0000000..2c7a087
Binary files /dev/null and b/lib/jopt-simple-5.0.2.jar differ
diff --git a/lib/json-path-2.4.0.jar b/lib/json-path-2.4.0.jar
new file mode 100644
index 0000000..6229306
Binary files /dev/null and b/lib/json-path-2.4.0.jar differ
diff --git a/lib/json-smart-2.3.jar b/lib/json-smart-2.3.jar
new file mode 100644
index 0000000..0cd52ea
Binary files /dev/null and b/lib/json-smart-2.3.jar differ
diff --git a/lib/lang-mustache-client-7.5.1.jar b/lib/lang-mustache-client-7.5.1.jar
new file mode 100644
index 0000000..76db6dc
Binary files /dev/null and b/lib/lang-mustache-client-7.5.1.jar differ
diff --git a/lib/log4j-api-2.11.1.jar b/lib/log4j-api-2.11.1.jar
new file mode 100644
index 0000000..96362a6
Binary files /dev/null and b/lib/log4j-api-2.11.1.jar differ
diff --git a/lib/lucene-analyzers-common-8.3.0.jar b/lib/lucene-analyzers-common-8.3.0.jar
new file mode 100644
index 0000000..c1eca15
Binary files /dev/null and b/lib/lucene-analyzers-common-8.3.0.jar differ
diff --git a/lib/lucene-backward-codecs-8.3.0.jar b/lib/lucene-backward-codecs-8.3.0.jar
new file mode 100644
index 0000000..54972f5
Binary files /dev/null and b/lib/lucene-backward-codecs-8.3.0.jar differ
diff --git a/lib/lucene-core-8.3.0.jar b/lib/lucene-core-8.3.0.jar
new file mode 100644
index 0000000..b647ec0
Binary files /dev/null and b/lib/lucene-core-8.3.0.jar differ
diff --git a/lib/lucene-grouping-8.3.0.jar b/lib/lucene-grouping-8.3.0.jar
new file mode 100644
index 0000000..47fc8fc
Binary files /dev/null and b/lib/lucene-grouping-8.3.0.jar differ
diff --git a/lib/lucene-highlighter-8.3.0.jar b/lib/lucene-highlighter-8.3.0.jar
new file mode 100644
index 0000000..ae7f425
Binary files /dev/null and b/lib/lucene-highlighter-8.3.0.jar differ
diff --git a/lib/lucene-join-8.3.0.jar b/lib/lucene-join-8.3.0.jar
new file mode 100644
index 0000000..834bb8a
Binary files /dev/null and b/lib/lucene-join-8.3.0.jar differ
diff --git a/lib/lucene-memory-8.3.0.jar b/lib/lucene-memory-8.3.0.jar
new file mode 100644
index 0000000..46c9d1d
Binary files /dev/null and b/lib/lucene-memory-8.3.0.jar differ
diff --git a/lib/lucene-misc-8.3.0.jar b/lib/lucene-misc-8.3.0.jar
new file mode 100644
index 0000000..5f932fa
Binary files /dev/null and b/lib/lucene-misc-8.3.0.jar differ
diff --git a/lib/lucene-queries-8.3.0.jar b/lib/lucene-queries-8.3.0.jar
new file mode 100644
index 0000000..7723369
Binary files /dev/null and b/lib/lucene-queries-8.3.0.jar differ
diff --git a/lib/lucene-queryparser-8.3.0.jar b/lib/lucene-queryparser-8.3.0.jar
new file mode 100644
index 0000000..f606b55
Binary files /dev/null and b/lib/lucene-queryparser-8.3.0.jar differ
diff --git a/lib/lucene-sandbox-8.3.0.jar b/lib/lucene-sandbox-8.3.0.jar
new file mode 100644
index 0000000..a17813d
Binary files /dev/null and b/lib/lucene-sandbox-8.3.0.jar differ
diff --git a/lib/lucene-spatial-8.3.0.jar b/lib/lucene-spatial-8.3.0.jar
new file mode 100644
index 0000000..523f480
Binary files /dev/null and b/lib/lucene-spatial-8.3.0.jar differ
diff --git a/lib/lucene-spatial-extras-8.3.0.jar b/lib/lucene-spatial-extras-8.3.0.jar
new file mode 100644
index 0000000..90d4c52
Binary files /dev/null and b/lib/lucene-spatial-extras-8.3.0.jar differ
diff --git a/lib/lucene-spatial3d-8.3.0.jar b/lib/lucene-spatial3d-8.3.0.jar
new file mode 100644
index 0000000..a0b8b84
Binary files /dev/null and b/lib/lucene-spatial3d-8.3.0.jar differ
diff --git a/lib/lucene-suggest-8.3.0.jar b/lib/lucene-suggest-8.3.0.jar
new file mode 100644
index 0000000..dd97cf9
Binary files /dev/null and b/lib/lucene-suggest-8.3.0.jar differ
diff --git a/lib/mapper-extras-client-7.5.1.jar b/lib/mapper-extras-client-7.5.1.jar
new file mode 100644
index 0000000..50db20e
Binary files /dev/null and b/lib/mapper-extras-client-7.5.1.jar differ
diff --git a/lib/netty-buffer-4.1.43.Final.jar b/lib/netty-buffer-4.1.43.Final.jar
new file mode 100644
index 0000000..bf9a298
Binary files /dev/null and b/lib/netty-buffer-4.1.43.Final.jar differ
diff --git a/lib/netty-codec-4.1.43.Final.jar b/lib/netty-codec-4.1.43.Final.jar
new file mode 100644
index 0000000..bafba25
Binary files /dev/null and b/lib/netty-codec-4.1.43.Final.jar differ
diff --git a/lib/netty-codec-http-4.1.43.Final.jar b/lib/netty-codec-http-4.1.43.Final.jar
new file mode 100644
index 0000000..fbb830a
Binary files /dev/null and b/lib/netty-codec-http-4.1.43.Final.jar differ
diff --git a/lib/netty-common-4.1.43.Final.jar b/lib/netty-common-4.1.43.Final.jar
new file mode 100644
index 0000000..3bad97e
Binary files /dev/null and b/lib/netty-common-4.1.43.Final.jar differ
diff --git a/lib/netty-handler-4.1.43.Final.jar b/lib/netty-handler-4.1.43.Final.jar
new file mode 100644
index 0000000..7a2cac1
Binary files /dev/null and b/lib/netty-handler-4.1.43.Final.jar differ
diff --git a/lib/netty-resolver-4.1.43.Final.jar b/lib/netty-resolver-4.1.43.Final.jar
new file mode 100644
index 0000000..3a8ad38
Binary files /dev/null and b/lib/netty-resolver-4.1.43.Final.jar differ
diff --git a/lib/netty-transport-4.1.43.Final.jar b/lib/netty-transport-4.1.43.Final.jar
new file mode 100644
index 0000000..870e7c3
Binary files /dev/null and b/lib/netty-transport-4.1.43.Final.jar differ
diff --git a/lib/parent-join-client-7.5.1.jar b/lib/parent-join-client-7.5.1.jar
new file mode 100644
index 0000000..1f6f582
Binary files /dev/null and b/lib/parent-join-client-7.5.1.jar differ
diff --git a/lib/percolator-client-7.5.1.jar b/lib/percolator-client-7.5.1.jar
new file mode 100644
index 0000000..9144c02
Binary files /dev/null and b/lib/percolator-client-7.5.1.jar differ
diff --git a/lib/rank-eval-client-7.5.1.jar b/lib/rank-eval-client-7.5.1.jar
new file mode 100644
index 0000000..10cb622
Binary files /dev/null and b/lib/rank-eval-client-7.5.1.jar differ
diff --git a/lib/reindex-client-7.5.1.jar b/lib/reindex-client-7.5.1.jar
new file mode 100644
index 0000000..fad3b00
Binary files /dev/null and b/lib/reindex-client-7.5.1.jar differ
diff --git a/lib/slf4j-api-1.7.25.jar b/lib/slf4j-api-1.7.25.jar
new file mode 100644
index 0000000..0143c09
Binary files /dev/null and b/lib/slf4j-api-1.7.25.jar differ
diff --git a/lib/snakeyaml-1.17.jar b/lib/snakeyaml-1.17.jar
new file mode 100644
index 0000000..b0372a3
Binary files /dev/null and b/lib/snakeyaml-1.17.jar differ
diff --git a/lib/t-digest-3.2.jar b/lib/t-digest-3.2.jar
new file mode 100644
index 0000000..2f14401
Binary files /dev/null and b/lib/t-digest-3.2.jar differ
diff --git a/lib/transport-7.5.1.jar b/lib/transport-7.5.1.jar
new file mode 100644
index 0000000..cd0eb3f
Binary files /dev/null and b/lib/transport-7.5.1.jar differ
diff --git a/lib/transport-netty4-client-7.5.1.jar b/lib/transport-netty4-client-7.5.1.jar
new file mode 100644
index 0000000..eebe310
Binary files /dev/null and b/lib/transport-netty4-client-7.5.1.jar differ
diff --git a/plugin.xml b/plugin.xml
index c18d224..b230c14 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -3,14 +3,18 @@
com.fr.plugin.db.es.v10
yes
- 1.0
+ 1.1
10.0
2019-10-25
fanruan.richie
[2019-12-31]初始化插件。
]]>
+
+ net.minidev.json
+
diff --git a/pom.xml b/pom.xml
index fcc20c9..c59d855 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,6 @@
starter
10.0
-
jar
com.fr.plugin.db.es.v10
@@ -19,6 +18,11 @@
system
${project.basedir}/lib/finekit-10.0.jar
+
+ com.jayway.jsonpath
+ json-path
+ 2.4.0
+
org.elasticsearch.client
transport
@@ -45,10 +49,28 @@
org.apache.maven.plugins
maven-compiler-plugin
-
- 6
+
+ 8
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy
+ package
+
+ copy-dependencies
+
+
+
+ ${project.basedir}/lib
+
+
+
+
+
\ No newline at end of file
diff --git a/readme.md b/readme.md
index f424a57..ac487ad 100644
--- a/readme.md
+++ b/readme.md
@@ -1 +1,19 @@
-# elasticsearch数据集插件
\ No newline at end of file
+# Elasticsearch数据集插件
+
+## 新建Elasticsearch数据连接
+
+![connection](screenshots/connection.png)
+
+支持连接集群,以逗号分隔多个主机地址和端口即可,确保主机地址和端口数量一致。
+
+## 新建Elasticsearch数据集
+
+![tabledata](screenshots/tabledata.png)
+
+左侧区域是用于测试的,输入Elasticsearch命令后,点击执行按钮,可以在左下角输出区看到输出结果;
+
+右侧区域是用于实际查询的,每一个输入框区域都可以使用${p}的格式带入参数。
+
+## 预览Elasticsearch数据集
+
+![preview](screenshots/preview.png)
\ No newline at end of file
diff --git a/screenshots/connection.png b/screenshots/connection.png
new file mode 100644
index 0000000..ff88fff
Binary files /dev/null and b/screenshots/connection.png differ
diff --git a/screenshots/preview.png b/screenshots/preview.png
new file mode 100644
index 0000000..8f318fa
Binary files /dev/null and b/screenshots/preview.png differ
diff --git a/screenshots/tabledata.png b/screenshots/tabledata.png
new file mode 100644
index 0000000..1997cee
Binary files /dev/null and b/screenshots/tabledata.png differ
diff --git a/src/main/java/com/fr/plugin/db/es/fun/ConfigAttribute.java b/src/main/java/com/fr/plugin/db/es/fun/ConfigAttribute.java
new file mode 100644
index 0000000..a4d2c83
--- /dev/null
+++ b/src/main/java/com/fr/plugin/db/es/fun/ConfigAttribute.java
@@ -0,0 +1,85 @@
+package com.fr.plugin.db.es.fun;
+
+import com.fanruan.api.conf.BaseUniqueKey;
+import com.fanruan.api.conf.HolderKit;
+import com.fanruan.api.util.AssistKit;
+import com.fr.config.holder.Conf;
+import com.fr.stable.xml.XMLPrintWriter;
+import com.fr.stable.xml.XMLable;
+import com.fr.stable.xml.XMLableReader;
+
+/**
+ * @author richie
+ * @version 10.0
+ * Created by richie on 2020/1/2
+ */
+public class ConfigAttribute extends BaseUniqueKey implements XMLable {
+
+ public static final String XML_TAG = "ConfigAttribute";
+ private static final long serialVersionUID = -2125057720890342129L;
+
+ private Conf sorted = HolderKit.simple(false);
+ private Conf prepare = HolderKit.simple(false);
+
+
+ public ConfigAttribute() {
+
+ }
+
+ public boolean isSorted() {
+ return sorted.get();
+ }
+
+ public void setSorted(boolean sorted) {
+ this.sorted.set(sorted);
+ }
+
+ public boolean isPrepare() {
+ return prepare.get();
+ }
+
+ public void setPrepare(boolean prepare) {
+ this.prepare.set(prepare);
+ }
+
+
+ @Override
+ public void readXML(XMLableReader reader) {
+ if (reader.isChildNode()) {
+ String tagName = reader.getTagName();
+ if ("Attr".equals(tagName)) {
+ sorted.set(reader.getAttrAsBoolean("sorted", false));
+ prepare.set(reader.getAttrAsBoolean("prepare", false));
+ }
+ }
+ }
+
+ @Override
+ public void writeXML(XMLPrintWriter writer) {
+ writer.startTAG("Attr");
+ writer.attr("sorted", sorted.get());
+ writer.attr("prepare", prepare.get());
+ writer.end();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object clone() throws CloneNotSupportedException {
+ ConfigAttribute cloned = (ConfigAttribute) super.clone();
+ cloned.sorted = (Conf) sorted.clone();
+ cloned.prepare = (Conf) prepare.clone();
+ return cloned;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj instanceof ConfigAttribute
+ && AssistKit.equals(this.sorted, ((ConfigAttribute) obj).sorted)
+ && AssistKit.equals(this.prepare, ((ConfigAttribute) obj).prepare);
+ }
+
+ @Override
+ public int hashCode() {
+ return AssistKit.hashCode(sorted.get(), prepare.get());
+ }
+}
diff --git a/src/main/java/com/fr/plugin/db/es/fun/ElasticsearchConnection.java b/src/main/java/com/fr/plugin/db/es/fun/ElasticsearchConnection.java
index c23a556..b504fb0 100644
--- a/src/main/java/com/fr/plugin/db/es/fun/ElasticsearchConnection.java
+++ b/src/main/java/com/fr/plugin/db/es/fun/ElasticsearchConnection.java
@@ -1,6 +1,26 @@
package com.fr.plugin.db.es.fun;
+import com.fanruan.api.conf.HolderKit;
import com.fanruan.api.data.open.BaseConnection;
+import com.fanruan.api.i18n.I18nKit;
+import com.fanruan.api.log.LogKit;
+import com.fanruan.api.util.ArrayKit;
+import com.fanruan.api.util.StringKit;
+import com.fanruan.api.util.TypeKit;
+import com.fr.config.Identifier;
+import com.fr.config.holder.Conf;
+import com.fr.data.impl.Connection;
+import com.fr.plugin.db.es.fun.help.ElasticsearchClientFactory;
+import com.fr.stable.collections.combination.Pair;
+import org.apache.http.util.EntityUtils;
+import org.elasticsearch.client.Request;
+import org.elasticsearch.client.RequestOptions;
+import org.elasticsearch.client.Response;
+import org.elasticsearch.client.RestClient;
+import org.elasticsearch.client.RestHighLevelClient;
+
+import java.io.IOException;
+import java.util.List;
/**
* @author richie
@@ -9,16 +29,130 @@ import com.fanruan.api.data.open.BaseConnection;
*/
public class ElasticsearchConnection extends BaseConnection {
+ public static final int DEFAULT_ES_PORT = 9200;
+
+ @Identifier("host")
+ private Conf host = HolderKit.simple(StringKit.EMPTY);
+ @Identifier("port")
+ private Conf port = HolderKit.simple(String.valueOf(DEFAULT_ES_PORT));
+ @Identifier("username")
+ private Conf username = HolderKit.simple(StringKit.EMPTY);
+ @Identifier("password")
+ private Conf password = HolderKit.simple(StringKit.EMPTY);
+
+ public String getHost() {
+ return host.get();
+ }
+
+ public void setHost(String host) {
+ this.host.set(host);
+ }
+
+ public String getPort() {
+ return port.get();
+ }
+
+ public void setPort(String port) {
+ this.port.set(port);
+ }
+
+ public String getUsername() {
+ return username.get();
+ }
+
+ public void setUsername(String username) {
+ this.username.set(username);
+ }
+
+ public String getPassword() {
+ return password.get();
+ }
+
+ public void setPassword(String password) {
+ this.password.set(password);
+ }
+
@Override
public void testConnection() throws Exception {
+ RestHighLevelClient client = createRestHighLevelClient();
+ boolean r;
+ try {
+ r = client.ping(RequestOptions.DEFAULT);
+ if (!r) {
+ throw new Exception("Failed");
+ }
+ } catch (Exception e) {
+ throw new Exception(e);
+ } finally {
+ client.close();
+ }
+ }
+
+ public RestHighLevelClient createRestHighLevelClient() {
+ Pair setting = setting();
+ return ElasticsearchClientFactory.buildHighLevelClient(setting.getFirst(), setting.getSecond(), getUsername(), getPassword());
+ }
+
+ public RestClient createClient() {
+ Pair setting = setting();
+ return ElasticsearchClientFactory.buildClient(setting.getFirst(), setting.getSecond(), getUsername(), getPassword());
+ }
+ private Pair setting() {
+ String host = getHost();
+ String port = getPort();
+ String[] hosts = host.split(",");
+ String[] portArr = port.split(",");
+ Integer[] ports = new Integer[portArr.length];
+ for (int i = 0; i < portArr.length; i ++) {
+ ports[i] = Integer.parseInt(portArr[i]);
+ }
+ return new Pair(hosts, ports);
}
@Override
- public String connectMessage(boolean b) {
+ public void addConnection(List list, String connectionName, Class extends Connection>[] acceptTypes) {
+ for (Class extends com.fr.data.impl.Connection> accept : acceptTypes) {
+ if (TypeKit.classInstanceOf(getClass(), accept)) {
+ list.add(connectionName);
+ break;
+ }
+ }
+ }
+
+ @Override
+ public String[] summary(String... args) {
+ if (ArrayKit.getLength(args) < 3) {
+ return ArrayKit.EMPTY_STRING_ARRAY;
+ }
+ RestClient client = createClient();
+ Request request = new Request(args[0], args[1]);
+ request.setJsonEntity(args[2]);
+ try {
+ Response response = client.performRequest(request);
+ return new String[]{EntityUtils.toString(response.getEntity())};
+ } catch (Exception e) {
+ LogKit.error(e.getMessage(), e);
+ } finally {
+ try {
+ client.close();
+ } catch (IOException e) {
+ LogKit.error(e.getMessage(), e);
+ }
+ }
return null;
}
+ @Override
+ public String connectMessage(boolean status) {
+ if (status) {
+ return I18nKit.getLocText("Plugin-Elasticsearch_Connection_Successfully") + "!";
+ } else {
+ return I18nKit.getLocText("Plugin-Elasticsearch_Connection_Failed") + "!";
+ }
+
+ }
+
@Override
public String getDriver() {
return null;
diff --git a/src/main/java/com/fr/plugin/db/es/fun/ElasticsearchDataModel.java b/src/main/java/com/fr/plugin/db/es/fun/ElasticsearchDataModel.java
index de4e824..b1654fa 100644
--- a/src/main/java/com/fr/plugin/db/es/fun/ElasticsearchDataModel.java
+++ b/src/main/java/com/fr/plugin/db/es/fun/ElasticsearchDataModel.java
@@ -2,6 +2,18 @@ package com.fr.plugin.db.es.fun;
import com.fanruan.api.data.open.BaseDataModel;
import com.fanruan.api.err.TableDataException;
+import com.fanruan.api.util.StringKit;
+import com.fr.plugin.db.es.fun.assist.SimpleDataModel;
+import com.fr.plugin.db.es.fun.category.ResultStandardizeSelector;
+import com.fr.plugin.db.es.fun.type.ConverterType;
+import com.fr.script.Calculator;
+import org.apache.http.util.EntityUtils;
+import org.elasticsearch.client.Request;
+import org.elasticsearch.client.Response;
+import org.elasticsearch.client.RestClient;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
/**
* @author richie
@@ -10,36 +22,112 @@ import com.fanruan.api.err.TableDataException;
*/
public class ElasticsearchDataModel extends BaseDataModel {
- public ElasticsearchDataModel() {
+ private transient Calculator calculator;
+ private transient ElasticsearchConnection connection;
+ private transient String endPoint;
+ private transient String query;
+ private transient String script;
+ private transient ConverterType converterType;
+ private transient RestClient client;
+ private transient ConfigAttribute configAttribute;
+ private transient int rowCount;
+ private String[] columnNames;
+ private List> data;
+ public ElasticsearchDataModel(
+ Calculator calculator,
+ ElasticsearchConnection connection,
+ String endPoint,
+ String query,
+ String script,
+ ConverterType converterType,
+ ConfigAttribute configAttribute,
+ int rowCount) {
+ this.calculator = calculator;
+ this.connection = connection;
+ this.endPoint = endPoint;
+ this.query = query;
+ this.script = script;
+ this.converterType = converterType;
+ this.configAttribute = configAttribute;
+ this.rowCount = rowCount;
}
- private void initData() throws Exception {
+ private void fetchData() throws TableDataException {
+ if (data == null) {
+ synchronized (ElasticsearchDataModel.class) {
+ if (data == null) {
+ try {
+ initData();
+ } catch (Exception e) {
+ throw new TableDataException(e.getMessage(), e);
+ }
+ }
+ }
+ }
+ }
+ private void initData() throws Exception {
+ if (client == null) {
+ client = connection.createClient();
+ String text;
+ if (StringKit.isNotBlank(endPoint)) {
+ Request request = new Request("GET", endPoint);
+ request.setJsonEntity(query);
+ Response response = client.performRequest(request);
+ text = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
+ } else {
+ text = StringKit.EMPTY;
+ }
+ SimpleDataModel simple = ResultStandardizeSelector.select(converterType).result(text, script, configAttribute, rowCount);
+ if (simple != null) {
+ this.columnNames = simple.getColumnNames();
+ this.data = simple.getData();
+ }
+ }
}
@Override
public int getColumnCount() throws TableDataException {
- return 0;
+ fetchData();
+ return columnNames == null ? 0 : columnNames.length;
}
@Override
- public String getColumnName(int i) throws TableDataException {
- return null;
+ public String getColumnName(int columnIndex) throws TableDataException {
+ fetchData();
+ return columnNames == null ? null : columnNames[columnIndex];
+ }
+
+ @Override
+ public boolean hasRow(int rowIndex) throws com.fr.general.data.TableDataException {
+ fetchData();
+ return data != null && data.size() > rowIndex;
}
@Override
public int getRowCount() throws TableDataException {
- return 0;
+ fetchData();
+ return data == null ? 0 : data.size();
}
@Override
- public Object getValueAt(int i, int i1) throws TableDataException {
+ public Object getValueAt(int rowIndex, int columnIndex) throws TableDataException {
+ fetchData();
+ if (data != null && data.size() > rowIndex) {
+ List