Browse Source

新增请求类型

master 1.4
richie 4 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>
<name><![CDATA[Elasticsearch数据集]]></name>
<active>yes</active>
<version>1.3</version>
<version>1.4</version>
<env-version>10.0</env-version>
<jartime>2019-10-25</jartime>
<vendor>fanruan.richie</vendor>
<description><![CDATA[Elasticsearch数据查询。]]></description>
<change-notes><![CDATA[
[2020-03-07]远程设计序列化问题<br/>
[2020-03-11]新增查询请求类型。<br/>
[2020-03-07]远程设计序列化问题。<br/>
[2020-01-07]修复一个写xml的错误。<br/>
[2020-01-02]完成插件大部分功能,正式发布。<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.category.ResultStandardizeSelector;
import com.fr.plugin.db.es.fun.type.ConverterType;
import com.fr.plugin.db.es.fun.type.QueryType;
import com.fr.script.Calculator;
import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request;
@ -26,6 +27,7 @@ public class ElasticsearchDataModel extends BaseDataModel {
private transient ElasticsearchConnection connection;
private transient String endPoint;
private transient String query;
private transient QueryType queryType;
private transient String script;
private transient ConverterType converterType;
private transient RestClient client;
@ -39,6 +41,7 @@ public class ElasticsearchDataModel extends BaseDataModel {
ElasticsearchConnection connection,
String endPoint,
String query,
QueryType queryType,
String script,
ConverterType converterType,
ConfigAttribute configAttribute,
@ -47,6 +50,7 @@ public class ElasticsearchDataModel extends BaseDataModel {
this.connection = connection;
this.endPoint = endPoint;
this.query = query;
this.queryType = queryType;
this.script = script;
this.converterType = converterType;
this.configAttribute = configAttribute;
@ -72,7 +76,7 @@ public class ElasticsearchDataModel extends BaseDataModel {
client = connection.createClient();
String text;
if (StringKit.isNotBlank(endPoint)) {
Request request = new Request("GET", endPoint);
Request request = new Request(queryType.getType(), endPoint);
request.setJsonEntity(query);
Response response = client.performRequest(request);
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.plugin.db.es.fun.help.RenderUtils;
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.script.Calculator;
import com.fr.stable.NameReference;
@ -39,6 +40,8 @@ public class ElasticsearchTableData extends BaseTableData {
private Conf<String> endPoint = HolderKit.simple(StringKit.EMPTY);
@Identifier("query")
private Conf<String> query = HolderKit.simple(StringKit.EMPTY);
@Identifier("queryType")
private Conf<String> queryType = HolderKit.simple(QueryType.GET.getType());
@Identifier("script")
private Conf<String> script = HolderKit.simple(StringKit.EMPTY);
@Identifier("converterType")
@ -74,6 +77,14 @@ public class ElasticsearchTableData extends BaseTableData {
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() {
return script.get();
}
@ -116,6 +127,7 @@ public class ElasticsearchTableData extends BaseTableData {
connection,
RenderUtils.calculateQuery(endPoint.get(), ps),
RenderUtils.calculateQuery(query.get(), ps),
getQueryType(),
RenderUtils.calculateQuery(script.get(), ps),
getConverterType(),
getConfigAttribute(),
@ -148,6 +160,10 @@ public class ElasticsearchTableData extends BaseTableData {
if ((tmpVal = reader.getElementValue()) != null) {
this.setQuery(tmpVal);
}
} else if ("QueryType".equals(tmpName)) {
if ((tmpVal = reader.getElementValue()) != null) {
this.setQueryType(QueryType.parse(tmpVal));
}
} if ("Script".equals(tmpName)) {
if ((tmpVal = reader.getElementValue()) != null) {
this.setScript(tmpVal);
@ -171,6 +187,7 @@ public class ElasticsearchTableData extends BaseTableData {
XmlKit.writeXMLable(writer, configAttribute.get(), ConfigAttribute.XML_TAG);
}
writer.startTAG("Query").textNode(getQuery()).end();
writer.startTAG("QueryType").textNode(getQueryType().getType()).end();
writer.startTAG("Script").textNode(getScript()).end();
writer.startTAG("Attr");
writer.attr("endPoint", getEndPoint());
@ -185,6 +202,7 @@ public class ElasticsearchTableData extends BaseTableData {
cloned.endPoint = (Conf<String>) endPoint.clone();
cloned.converterType = (Conf<Integer>) converterType.clone();
cloned.query = (Conf<String>) query.clone();
cloned.queryType = (Conf<String>) queryType.clone();
cloned.script = (Conf<String>) script.clone();
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.plugin.db.es.fun.ConfigAttribute;
import com.fr.plugin.db.es.fun.type.ConverterType;
import com.fr.plugin.db.es.fun.type.QueryType;
import javax.swing.*;
import java.awt.*;
@ -28,6 +29,7 @@ public class ElasticsearchQueryPane extends BasicPane {
private UITextField endPointTextField;
private UIDictionaryComboBox<ConverterType> converterTypeComboBox;
private UIDictionaryComboBox<QueryType> queryTypeComboBox;
private UISyntaxTextArea queryTextPane;
private UISyntaxTextArea scriptTextPane;
private UIDictionaryComboBox<Boolean> sortedComboBox;
@ -44,11 +46,15 @@ public class ElasticsearchQueryPane extends BasicPane {
double p = TableLayoutKit.PREFERRED;
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};
endPointTextField = new UITextField();
queryTypeComboBox = new UIDictionaryComboBox<>(
new QueryType[]{QueryType.GET, QueryType.POST},
new String[]{QueryType.GET.getType(), QueryType.POST.getType()});
queryTextPane = new UISyntaxTextArea();
converterTypeComboBox = new UIDictionaryComboBox<>(new ConverterType[]{
@ -76,6 +82,7 @@ public class ElasticsearchQueryPane extends BasicPane {
);
Component[][] coms = new Component[][]{
{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_Result_Type")+ ":"), converterTypeComboBox},
{new UILabel(DesignKit.i18nText("Plugin-Elasticsearch_Result_Script")+ ":"), createConditionTextPane(scriptTextPane)},
@ -116,6 +123,14 @@ public class ElasticsearchQueryPane extends BasicPane {
converterTypeComboBox.setSelectedItem(converterType);
}
public QueryType getQueryType() {
return queryTypeComboBox.getSelectedItem();
}
public void setQueryType(QueryType queryType) {
queryTypeComboBox.setSelectedItem(queryType);
}
public String getQuery() {
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.setConfigAttr(tableData.getConfigAttribute());
queryPane.setQuery(tableData.getQuery());
queryPane.setQueryType(tableData.getQueryType());
queryPane.setConverterTypeComboBox(tableData.getConverterType());
queryPane.setScript(tableData.getScript());
}
@ -178,6 +179,7 @@ public class ElasticsearchTableDataPane extends BaseTableDataPane<ElasticsearchT
java.util.List<ParameterProvider> providerList = editorPane.update();
tableData.setParameters(providerList.toArray(new ParameterProvider[0]));
tableData.setEndPoint(queryPane.getEndPoint());
tableData.setQueryType(queryPane.getQueryType());
tableData.setQuery(queryPane.getQuery());
tableData.setConverterType(queryPane.getConverterType());
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_Endpoint=Endpoint
Plugin-Elasticsearch_Query=Query
Plugin-Elasticsearch_Query_Type=Method
Plugin-Elasticsearch_Sort_Key=Sort key
Plugin-Elasticsearch_Key_Prepare=Key Prepare
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_Endpoint=Endpoint
Plugin-Elasticsearch_Query=Query
Plugin-Elasticsearch_Query_Type=Method
Plugin-Elasticsearch_Sort_Key=Sort key
Plugin-Elasticsearch_Key_Prepare=Key Prepare
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_Endpoint=\u7AEF\u70B9
Plugin-Elasticsearch_Query=\u67E5\u8BE2\u8BED\u53E5
Plugin-Elasticsearch_Query_Type=\u8BF7\u6C42\u7C7B\u578B
Plugin-Elasticsearch_Sort_Key=\u952E\u6392\u5E8F
Plugin-Elasticsearch_Key_Prepare=\u9884\u8BFB\u5217\u540D
Plugin-Elasticsearch_Result_Type=\u89C4\u6574\u7C7B\u578B

Loading…
Cancel
Save