Browse Source

新增请求类型

master 1.4
richie 5 years ago
parent
commit
fe39ddeaee
  1. 5
      plugin.xml
  2. 6
      src/main/java/com/fr/plugin/db/es/fun/ElasticsearchDataModel.java
  3. 18
      src/main/java/com/fr/plugin/db/es/fun/ElasticsearchTableData.java
  4. 30
      src/main/java/com/fr/plugin/db/es/fun/type/QueryType.java
  5. 17
      src/main/java/com/fr/plugin/db/es/ui/ElasticsearchQueryPane.java
  6. 2
      src/main/java/com/fr/plugin/db/es/ui/ElasticsearchTableDataPane.java
  7. 1
      src/main/resources/com/fr/plugin/db/es/locale/es.properties
  8. 1
      src/main/resources/com/fr/plugin/db/es/locale/es_en_US.properties
  9. 1
      src/main/resources/com/fr/plugin/db/es/locale/es_zh_CN.properties

5
plugin.xml

@ -3,13 +3,14 @@
<id>com.fr.plugin.db.es.v10</id> <id>com.fr.plugin.db.es.v10</id>
<name><![CDATA[Elasticsearch数据集]]></name> <name><![CDATA[Elasticsearch数据集]]></name>
<active>yes</active> <active>yes</active>
<version>1.3</version> <version>1.4</version>
<env-version>10.0</env-version> <env-version>10.0</env-version>
<jartime>2019-10-25</jartime> <jartime>2019-10-25</jartime>
<vendor>fanruan.richie</vendor> <vendor>fanruan.richie</vendor>
<description><![CDATA[Elasticsearch数据查询。]]></description> <description><![CDATA[Elasticsearch数据查询。]]></description>
<change-notes><![CDATA[ <change-notes><![CDATA[
[2020-03-07]远程设计序列化问题<br/> [2020-03-11]新增查询请求类型。<br/>
[2020-03-07]远程设计序列化问题。<br/>
[2020-01-07]修复一个写xml的错误。<br/> [2020-01-07]修复一个写xml的错误。<br/>
[2020-01-02]完成插件大部分功能,正式发布。<br/> [2020-01-02]完成插件大部分功能,正式发布。<br/>
[2019-12-31]初始化插件。<br/> [2019-12-31]初始化插件。<br/>

6
src/main/java/com/fr/plugin/db/es/fun/ElasticsearchDataModel.java

@ -6,6 +6,7 @@ import com.fanruan.api.util.StringKit;
import com.fr.plugin.db.es.fun.assist.SimpleDataModel; 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.category.ResultStandardizeSelector;
import com.fr.plugin.db.es.fun.type.ConverterType; import com.fr.plugin.db.es.fun.type.ConverterType;
import com.fr.plugin.db.es.fun.type.QueryType;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
@ -26,6 +27,7 @@ public class ElasticsearchDataModel extends BaseDataModel {
private transient ElasticsearchConnection connection; private transient ElasticsearchConnection connection;
private transient String endPoint; private transient String endPoint;
private transient String query; private transient String query;
private transient QueryType queryType;
private transient String script; private transient String script;
private transient ConverterType converterType; private transient ConverterType converterType;
private transient RestClient client; private transient RestClient client;
@ -39,6 +41,7 @@ public class ElasticsearchDataModel extends BaseDataModel {
ElasticsearchConnection connection, ElasticsearchConnection connection,
String endPoint, String endPoint,
String query, String query,
QueryType queryType,
String script, String script,
ConverterType converterType, ConverterType converterType,
ConfigAttribute configAttribute, ConfigAttribute configAttribute,
@ -47,6 +50,7 @@ public class ElasticsearchDataModel extends BaseDataModel {
this.connection = connection; this.connection = connection;
this.endPoint = endPoint; this.endPoint = endPoint;
this.query = query; this.query = query;
this.queryType = queryType;
this.script = script; this.script = script;
this.converterType = converterType; this.converterType = converterType;
this.configAttribute = configAttribute; this.configAttribute = configAttribute;
@ -72,7 +76,7 @@ public class ElasticsearchDataModel extends BaseDataModel {
client = connection.createClient(); client = connection.createClient();
String text; String text;
if (StringKit.isNotBlank(endPoint)) { if (StringKit.isNotBlank(endPoint)) {
Request request = new Request("GET", endPoint); Request request = new Request(queryType.getType(), endPoint);
request.setJsonEntity(query); request.setJsonEntity(query);
Response response = client.performRequest(request); Response response = client.performRequest(request);
text = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); text = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);

18
src/main/java/com/fr/plugin/db/es/fun/ElasticsearchTableData.java

@ -14,6 +14,7 @@ import com.fr.general.data.DataModel;
import com.fr.intelli.record.Focus; import com.fr.intelli.record.Focus;
import com.fr.plugin.db.es.fun.help.RenderUtils; import com.fr.plugin.db.es.fun.help.RenderUtils;
import com.fr.plugin.db.es.fun.type.ConverterType; import com.fr.plugin.db.es.fun.type.ConverterType;
import com.fr.plugin.db.es.fun.type.QueryType;
import com.fr.record.analyzer.EnableMetrics; import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.NameReference; import com.fr.stable.NameReference;
@ -39,6 +40,8 @@ public class ElasticsearchTableData extends BaseTableData {
private Conf<String> endPoint = HolderKit.simple(StringKit.EMPTY); private Conf<String> endPoint = HolderKit.simple(StringKit.EMPTY);
@Identifier("query") @Identifier("query")
private Conf<String> query = HolderKit.simple(StringKit.EMPTY); private Conf<String> query = HolderKit.simple(StringKit.EMPTY);
@Identifier("queryType")
private Conf<String> queryType = HolderKit.simple(QueryType.GET.getType());
@Identifier("script") @Identifier("script")
private Conf<String> script = HolderKit.simple(StringKit.EMPTY); private Conf<String> script = HolderKit.simple(StringKit.EMPTY);
@Identifier("converterType") @Identifier("converterType")
@ -74,6 +77,14 @@ public class ElasticsearchTableData extends BaseTableData {
this.query.set(query); this.query.set(query);
} }
public QueryType getQueryType() {
return QueryType.parse(queryType.get());
}
public void setQueryType(QueryType queryType) {
this.queryType.set(queryType.getType());
}
public String getScript() { public String getScript() {
return script.get(); return script.get();
} }
@ -116,6 +127,7 @@ public class ElasticsearchTableData extends BaseTableData {
connection, connection,
RenderUtils.calculateQuery(endPoint.get(), ps), RenderUtils.calculateQuery(endPoint.get(), ps),
RenderUtils.calculateQuery(query.get(), ps), RenderUtils.calculateQuery(query.get(), ps),
getQueryType(),
RenderUtils.calculateQuery(script.get(), ps), RenderUtils.calculateQuery(script.get(), ps),
getConverterType(), getConverterType(),
getConfigAttribute(), getConfigAttribute(),
@ -148,6 +160,10 @@ public class ElasticsearchTableData extends BaseTableData {
if ((tmpVal = reader.getElementValue()) != null) { if ((tmpVal = reader.getElementValue()) != null) {
this.setQuery(tmpVal); this.setQuery(tmpVal);
} }
} else if ("QueryType".equals(tmpName)) {
if ((tmpVal = reader.getElementValue()) != null) {
this.setQueryType(QueryType.parse(tmpVal));
}
} if ("Script".equals(tmpName)) { } if ("Script".equals(tmpName)) {
if ((tmpVal = reader.getElementValue()) != null) { if ((tmpVal = reader.getElementValue()) != null) {
this.setScript(tmpVal); this.setScript(tmpVal);
@ -171,6 +187,7 @@ public class ElasticsearchTableData extends BaseTableData {
XmlKit.writeXMLable(writer, configAttribute.get(), ConfigAttribute.XML_TAG); XmlKit.writeXMLable(writer, configAttribute.get(), ConfigAttribute.XML_TAG);
} }
writer.startTAG("Query").textNode(getQuery()).end(); writer.startTAG("Query").textNode(getQuery()).end();
writer.startTAG("QueryType").textNode(getQueryType().getType()).end();
writer.startTAG("Script").textNode(getScript()).end(); writer.startTAG("Script").textNode(getScript()).end();
writer.startTAG("Attr"); writer.startTAG("Attr");
writer.attr("endPoint", getEndPoint()); writer.attr("endPoint", getEndPoint());
@ -185,6 +202,7 @@ public class ElasticsearchTableData extends BaseTableData {
cloned.endPoint = (Conf<String>) endPoint.clone(); cloned.endPoint = (Conf<String>) endPoint.clone();
cloned.converterType = (Conf<Integer>) converterType.clone(); cloned.converterType = (Conf<Integer>) converterType.clone();
cloned.query = (Conf<String>) query.clone(); cloned.query = (Conf<String>) query.clone();
cloned.queryType = (Conf<String>) queryType.clone();
cloned.script = (Conf<String>) script.clone(); cloned.script = (Conf<String>) script.clone();
return cloned; return cloned;
} }

30
src/main/java/com/fr/plugin/db/es/fun/type/QueryType.java

@ -0,0 +1,30 @@
package com.fr.plugin.db.es.fun.type;
/**
* @author richie
* @version 10.0
* Created by richie on 2020/3/11
*/
public enum QueryType {
GET("GET"), POST("POST");
private String type;
QueryType(String type) {
this.type = type;
}
public String getType() {
return type;
}
public static QueryType parse(String text) {
for (QueryType qt : values()) {
if (qt.type.equals(text)) {
return qt;
}
}
return GET;
}
}

17
src/main/java/com/fr/plugin/db/es/ui/ElasticsearchQueryPane.java

@ -13,6 +13,7 @@ import com.fanruan.api.design.ui.layout.TableLayoutKit;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.plugin.db.es.fun.ConfigAttribute; import com.fr.plugin.db.es.fun.ConfigAttribute;
import com.fr.plugin.db.es.fun.type.ConverterType; import com.fr.plugin.db.es.fun.type.ConverterType;
import com.fr.plugin.db.es.fun.type.QueryType;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -28,6 +29,7 @@ public class ElasticsearchQueryPane extends BasicPane {
private UITextField endPointTextField; private UITextField endPointTextField;
private UIDictionaryComboBox<ConverterType> converterTypeComboBox; private UIDictionaryComboBox<ConverterType> converterTypeComboBox;
private UIDictionaryComboBox<QueryType> queryTypeComboBox;
private UISyntaxTextArea queryTextPane; private UISyntaxTextArea queryTextPane;
private UISyntaxTextArea scriptTextPane; private UISyntaxTextArea scriptTextPane;
private UIDictionaryComboBox<Boolean> sortedComboBox; private UIDictionaryComboBox<Boolean> sortedComboBox;
@ -44,11 +46,15 @@ public class ElasticsearchQueryPane extends BasicPane {
double p = TableLayoutKit.PREFERRED; double p = TableLayoutKit.PREFERRED;
double f = TableLayoutKit.FILL; double f = TableLayoutKit.FILL;
double[] rowSize = {p, p, p, p, p, p}; double[] rowSize = {p, p, p, p, p, p, p};
double[] columnSize = {p, f}; double[] columnSize = {p, f};
endPointTextField = new UITextField(); endPointTextField = new UITextField();
queryTypeComboBox = new UIDictionaryComboBox<>(
new QueryType[]{QueryType.GET, QueryType.POST},
new String[]{QueryType.GET.getType(), QueryType.POST.getType()});
queryTextPane = new UISyntaxTextArea(); queryTextPane = new UISyntaxTextArea();
converterTypeComboBox = new UIDictionaryComboBox<>(new ConverterType[]{ converterTypeComboBox = new UIDictionaryComboBox<>(new ConverterType[]{
@ -76,6 +82,7 @@ public class ElasticsearchQueryPane extends BasicPane {
); );
Component[][] coms = new Component[][]{ Component[][] coms = new Component[][]{
{new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Endpoint") + ":"), endPointTextField}, {new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Endpoint") + ":"), endPointTextField},
{new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Query_Type") + ":"), queryTypeComboBox},
{new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Query") + ":"), createConditionTextPane(queryTextPane)}, {new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Query") + ":"), createConditionTextPane(queryTextPane)},
{new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Result_Type")+ ":"), converterTypeComboBox}, {new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Result_Type")+ ":"), converterTypeComboBox},
{new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Result_Script")+ ":"), createConditionTextPane(scriptTextPane)}, {new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Result_Script")+ ":"), createConditionTextPane(scriptTextPane)},
@ -116,6 +123,14 @@ public class ElasticsearchQueryPane extends BasicPane {
converterTypeComboBox.setSelectedItem(converterType); converterTypeComboBox.setSelectedItem(converterType);
} }
public QueryType getQueryType() {
return queryTypeComboBox.getSelectedItem();
}
public void setQueryType(QueryType queryType) {
queryTypeComboBox.setSelectedItem(queryType);
}
public String getQuery() { public String getQuery() {
return queryTextPane.getText(); return queryTextPane.getText();
} }

2
src/main/java/com/fr/plugin/db/es/ui/ElasticsearchTableDataPane.java

@ -164,6 +164,7 @@ public class ElasticsearchTableDataPane extends BaseTableDataPane<ElasticsearchT
queryPane.setEndPoint(tableData.getEndPoint()); queryPane.setEndPoint(tableData.getEndPoint());
queryPane.setConfigAttr(tableData.getConfigAttribute()); queryPane.setConfigAttr(tableData.getConfigAttribute());
queryPane.setQuery(tableData.getQuery()); queryPane.setQuery(tableData.getQuery());
queryPane.setQueryType(tableData.getQueryType());
queryPane.setConverterTypeComboBox(tableData.getConverterType()); queryPane.setConverterTypeComboBox(tableData.getConverterType());
queryPane.setScript(tableData.getScript()); queryPane.setScript(tableData.getScript());
} }
@ -178,6 +179,7 @@ public class ElasticsearchTableDataPane extends BaseTableDataPane<ElasticsearchT
java.util.List<ParameterProvider> providerList = editorPane.update(); java.util.List<ParameterProvider> providerList = editorPane.update();
tableData.setParameters(providerList.toArray(new ParameterProvider[0])); tableData.setParameters(providerList.toArray(new ParameterProvider[0]));
tableData.setEndPoint(queryPane.getEndPoint()); tableData.setEndPoint(queryPane.getEndPoint());
tableData.setQueryType(queryPane.getQueryType());
tableData.setQuery(queryPane.getQuery()); tableData.setQuery(queryPane.getQuery());
tableData.setConverterType(queryPane.getConverterType()); tableData.setConverterType(queryPane.getConverterType());
tableData.setConfigAttribute(queryPane.getConfigAttr()); tableData.setConfigAttribute(queryPane.getConfigAttr());

1
src/main/resources/com/fr/plugin/db/es/locale/es.properties

@ -13,6 +13,7 @@ Plugin-Elasticsearch_Sort_Default=Default
Plugin-Elasticsearch_Prepare_Keys_Default=Default Plugin-Elasticsearch_Prepare_Keys_Default=Default
Plugin-Elasticsearch_Endpoint=Endpoint Plugin-Elasticsearch_Endpoint=Endpoint
Plugin-Elasticsearch_Query=Query Plugin-Elasticsearch_Query=Query
Plugin-Elasticsearch_Query_Type=Method
Plugin-Elasticsearch_Sort_Key=Sort key Plugin-Elasticsearch_Sort_Key=Sort key
Plugin-Elasticsearch_Key_Prepare=Key Prepare Plugin-Elasticsearch_Key_Prepare=Key Prepare
Plugin-Elasticsearch_Result_Type=Processor Type Plugin-Elasticsearch_Result_Type=Processor Type

1
src/main/resources/com/fr/plugin/db/es/locale/es_en_US.properties

@ -13,6 +13,7 @@ Plugin-Elasticsearch_Sort_Default=Default
Plugin-Elasticsearch_Prepare_Keys_Default=Default Plugin-Elasticsearch_Prepare_Keys_Default=Default
Plugin-Elasticsearch_Endpoint=Endpoint Plugin-Elasticsearch_Endpoint=Endpoint
Plugin-Elasticsearch_Query=Query Plugin-Elasticsearch_Query=Query
Plugin-Elasticsearch_Query_Type=Method
Plugin-Elasticsearch_Sort_Key=Sort key Plugin-Elasticsearch_Sort_Key=Sort key
Plugin-Elasticsearch_Key_Prepare=Key Prepare Plugin-Elasticsearch_Key_Prepare=Key Prepare
Plugin-Elasticsearch_Result_Type=Processor Type Plugin-Elasticsearch_Result_Type=Processor Type

1
src/main/resources/com/fr/plugin/db/es/locale/es_zh_CN.properties

@ -13,6 +13,7 @@ Plugin-Elasticsearch_Sort_Default=\u9ED8\u8BA4
Plugin-Elasticsearch_Prepare_Keys_Default=\u9ED8\u8BA4 Plugin-Elasticsearch_Prepare_Keys_Default=\u9ED8\u8BA4
Plugin-Elasticsearch_Endpoint=\u7AEF\u70B9 Plugin-Elasticsearch_Endpoint=\u7AEF\u70B9
Plugin-Elasticsearch_Query=\u67E5\u8BE2\u8BED\u53E5 Plugin-Elasticsearch_Query=\u67E5\u8BE2\u8BED\u53E5
Plugin-Elasticsearch_Query_Type=\u8BF7\u6C42\u7C7B\u578B
Plugin-Elasticsearch_Sort_Key=\u952E\u6392\u5E8F Plugin-Elasticsearch_Sort_Key=\u952E\u6392\u5E8F
Plugin-Elasticsearch_Key_Prepare=\u9884\u8BFB\u5217\u540D Plugin-Elasticsearch_Key_Prepare=\u9884\u8BFB\u5217\u540D
Plugin-Elasticsearch_Result_Type=\u89C4\u6574\u7C7B\u578B Plugin-Elasticsearch_Result_Type=\u89C4\u6574\u7C7B\u578B

Loading…
Cancel
Save