diff --git a/src/main/java/org/codelibs/fess/app/web/admin/esreq/AdminEsreqAction.java b/src/main/java/org/codelibs/fess/app/web/admin/esreq/AdminEsreqAction.java new file mode 100644 index 000000000..cd158353d --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/admin/esreq/AdminEsreqAction.java @@ -0,0 +1,153 @@ +/* + * Copyright 2012-2016 CodeLibs Project and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.codelibs.fess.app.web.admin.esreq; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Locale; + +import org.codelibs.core.io.CopyUtil; +import org.codelibs.core.io.ReaderUtil; +import org.codelibs.core.lang.StringUtil; +import org.codelibs.elasticsearch.runner.net.Curl; +import org.codelibs.elasticsearch.runner.net.CurlRequest; +import org.codelibs.elasticsearch.runner.net.CurlResponse; +import org.codelibs.fess.Constants; +import org.codelibs.fess.app.web.base.FessAdminAction; +import org.codelibs.fess.util.ResourceUtil; +import org.lastaflute.web.Execute; +import org.lastaflute.web.response.ActionResponse; +import org.lastaflute.web.response.HtmlResponse; +import org.lastaflute.web.ruts.process.ActionRuntime; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author shinsuke + */ +public class AdminEsreqAction extends FessAdminAction { + + private static final Logger logger = LoggerFactory.getLogger(AdminEsreqAction.class); + + @Override + protected void setupHtmlData(final ActionRuntime runtime) { + super.setupHtmlData(runtime); + runtime.registerData("helpLink", systemHelper.getHelpLink(fessConfig.getOnlineHelpNameEsreq())); + } + + @Execute + public HtmlResponse index() { + return asListHtml(() -> saveToken()); + } + + @Execute + public ActionResponse upload(final UploadForm form) { + validate(form, messages -> {}, () -> asListHtml(null)); + verifyToken(() -> asListHtml(() -> saveToken())); + + String header = null; + final StringBuilder buf = new StringBuilder(1000); + try (final BufferedReader reader = new BufferedReader(new InputStreamReader(form.requestFile.getInputStream(), Constants.UTF_8))) { + header = ReaderUtil.readLine(reader); + String line; + while ((line = ReaderUtil.readLine(reader)) != null) { + buf.append(line); + } + } catch (final Exception e) { + throwValidationError(messages -> messages.addErrorsFailedToReadRequestFile(GLOBAL, e.getMessage()), () -> { + return asListHtml(() -> saveToken()); + }); + } + + final CurlRequest curlRequest = getCurlRequest(header); + if (curlRequest == null) { + final String msg = header; + throwValidationError(messages -> messages.addErrorsInvalidHeaderForRequestFile(GLOBAL, msg), () -> { + return asListHtml(() -> saveToken()); + }); + } + + try (final CurlResponse response = curlRequest.body(buf.toString()).execute()) { + final File tempFile = File.createTempFile("esreq_", ".json"); + try (final InputStream in = response.getContentAsStream()) { + CopyUtil.copy(in, tempFile); + } catch (final Exception e1) { + if (tempFile != null && tempFile.exists() && !tempFile.delete()) { + logger.warn("Failed to delete " + tempFile.getAbsolutePath()); + } + throw e1; + } + return asStream("es_" + System.currentTimeMillis() + ".json").contentTypeOctetStream().stream(out -> { + try (final InputStream in = new FileInputStream(tempFile)) { + out.write(in); + } finally { + if (tempFile.exists() && !tempFile.delete()) { + logger.warn("Failed to delete " + tempFile.getAbsolutePath()); + } + } + }); + } catch (final Exception e) { + logger.warn("Failed to process request file: " + form.requestFile.getFileName(), e); + throwValidationError(messages -> messages.addErrorsInvalidHeaderForRequestFile(GLOBAL, e.getMessage()), () -> { + return asListHtml(() -> saveToken()); + }); + } + return redirect(getClass()); // no-op + } + + private CurlRequest getCurlRequest(String header) { + if (StringUtil.isBlank(header)) { + return null; + } + + final String[] values = header.split(" "); + if (values.length != 2) { + return null; + } + + final String url; + if (values[1].startsWith("/")) { + url = ResourceUtil.getElasticsearchHttpUrl() + values[1]; + } else { + url = ResourceUtil.getElasticsearchHttpUrl() + "/" + values[1]; + } + + switch (values[0].toUpperCase(Locale.ROOT)) { + case "GET": + return Curl.get(url); + case "POST": + return Curl.post(url); + case "PUT": + return Curl.put(url); + case "DELETE": + return Curl.delete(url); + default: + break; + } + return null; + } + + private HtmlResponse asListHtml(Runnable runnable) { + if (runnable != null) { + runnable.run(); + } + return asHtml(path_AdminEsreq_AdminEsreqJsp).useForm(UploadForm.class); + } + +} diff --git a/src/main/java/org/codelibs/fess/app/web/admin/esreq/UploadForm.java b/src/main/java/org/codelibs/fess/app/web/admin/esreq/UploadForm.java new file mode 100644 index 000000000..5acb62777 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/admin/esreq/UploadForm.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012-2016 CodeLibs Project and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.codelibs.fess.app.web.admin.esreq; + +import org.lastaflute.web.ruts.multipart.MultipartFormFile; +import org.lastaflute.web.validation.Required; + +public class UploadForm { + + @Required + public MultipartFormFile requestFile; +} diff --git a/src/main/java/org/codelibs/fess/mylasta/action/FessHtmlPath.java b/src/main/java/org/codelibs/fess/mylasta/action/FessHtmlPath.java index 8d6212c33..c13274694 100644 --- a/src/main/java/org/codelibs/fess/mylasta/action/FessHtmlPath.java +++ b/src/main/java/org/codelibs/fess/mylasta/action/FessHtmlPath.java @@ -149,6 +149,9 @@ public interface FessHtmlPath { /** The path of the HTML: /admin/error/admin_error.jsp */ HtmlNext path_AdminError_AdminErrorJsp = new HtmlNext("/admin/error/admin_error.jsp"); + /** The path of the HTML: /admin/esreq/admin_esreq.jsp */ + HtmlNext path_AdminEsreq_AdminEsreqJsp = new HtmlNext("/admin/esreq/admin_esreq.jsp"); + /** The path of the HTML: /admin/failureurl/admin_failureurl.jsp */ HtmlNext path_AdminFailureurl_AdminFailureurlJsp = new HtmlNext("/admin/failureurl/admin_failureurl.jsp"); diff --git a/src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java b/src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java index 73bbf74ad..9adf7a3cd 100644 --- a/src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java +++ b/src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java @@ -2355,6 +2355,18 @@ public class FessLabels extends ActionMessages { /** The key of the message: Version From */ public static final String LABELS_target_version = "{labels.target_version}"; + /** The key of the message: Request to elasticsearch */ + public static final String LABELS_esreq_configuration = "{labels.esreq_configuration}"; + + /** The key of the message: Request File */ + public static final String LABELS_esreq_request_file = "{labels.esreq_request_file}"; + + /** The key of the message: Request File */ + public static final String LABELS_REQUEST_FILE = "{labels.requestFile}"; + + /** The key of the message: Send */ + public static final String LABELS_esreq_button_upload = "{labels.esreq_button_upload}"; + /** * Assert the property is not null. * @param property The value of the property. (NotNull) diff --git a/src/main/java/org/codelibs/fess/mylasta/action/FessMessages.java b/src/main/java/org/codelibs/fess/mylasta/action/FessMessages.java index fa775a64b..8c4bf916c 100644 --- a/src/main/java/org/codelibs/fess/mylasta/action/FessMessages.java +++ b/src/main/java/org/codelibs/fess/mylasta/action/FessMessages.java @@ -287,6 +287,12 @@ public class FessMessages extends FessLabels { /** The key of the message: Failed to upgrade from {0}: {1} */ public static final String ERRORS_failed_to_upgrade_from = "{errors.failed_to_upgrade_from}"; + /** The key of the message: Failed to read request file: {0} */ + public static final String ERRORS_failed_to_read_request_file = "{errors.failed_to_read_request_file}"; + + /** The key of the message: Invalid header: {0} */ + public static final String ERRORS_invalid_header_for_request_file = "{errors.invalid_header_for_request_file}"; + /** The key of the message: The given query has unknown condition. */ public static final String ERRORS_invalid_query_unknown = "{errors.invalid_query_unknown}"; @@ -1677,6 +1683,36 @@ public class FessMessages extends FessLabels { return this; } + /** + * Add the created action message for the key 'errors.failed_to_read_request_file' with parameters. + *
+     * message: Failed to read request file: {0}
+     * 
+ * @param property The property name for the message. (NotNull) + * @param arg0 The parameter arg0 for message. (NotNull) + * @return this. (NotNull) + */ + public FessMessages addErrorsFailedToReadRequestFile(String property, String arg0) { + assertPropertyNotNull(property); + add(property, new ActionMessage(ERRORS_failed_to_read_request_file, arg0)); + return this; + } + + /** + * Add the created action message for the key 'errors.invalid_header_for_request_file' with parameters. + *
+     * message: Invalid header: {0}
+     * 
+ * @param property The property name for the message. (NotNull) + * @param arg0 The parameter arg0 for message. (NotNull) + * @return this. (NotNull) + */ + public FessMessages addErrorsInvalidHeaderForRequestFile(String property, String arg0) { + assertPropertyNotNull(property); + add(property, new ActionMessage(ERRORS_invalid_header_for_request_file, arg0)); + return this; + } + /** * Add the created action message for the key 'errors.invalid_query_unknown' with parameters. *
diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
index a6f25faea..d0b55b9d7 100644
--- a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
+++ b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
@@ -694,6 +694,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. upgrade */
     String ONLINE_HELP_NAME_UPGRADE = "online.help.name.upgrade";
 
+    /** The key of the configuration. e.g. esreq */
+    String ONLINE_HELP_NAME_ESREQ = "online.help.name.esreq";
+
     /** The key of the configuration. e.g. ja */
     String ONLINE_HELP_SUPPORTED_LANGS = "online.help.supported.langs";
 
@@ -3020,6 +3023,13 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
      */
     String getOnlineHelpNameUpgrade();
 
+    /**
+     * Get the value for the key 'online.help.name.esreq'. 
+ * The value is, e.g. esreq
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + */ + String getOnlineHelpNameEsreq(); + /** * Get the value for the key 'online.help.supported.langs'.
* The value is, e.g. ja
@@ -4771,6 +4781,10 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction return get(FessConfig.ONLINE_HELP_NAME_UPGRADE); } + public String getOnlineHelpNameEsreq() { + return get(FessConfig.ONLINE_HELP_NAME_ESREQ); + } + public String getOnlineHelpSupportedLangs() { return get(FessConfig.ONLINE_HELP_SUPPORTED_LANGS); } diff --git a/src/main/resources/fess_config.properties b/src/main/resources/fess_config.properties index 82b1b8689..7515e5d19 100644 --- a/src/main/resources/fess_config.properties +++ b/src/main/resources/fess_config.properties @@ -373,6 +373,7 @@ online.help.name.scheduler=scheduler online.help.name.crawlinginfo=crawlinginfo online.help.name.backup=backup online.help.name.upgrade=upgrade +online.help.name.esreq=esreq online.help.supported.langs=ja diff --git a/src/main/resources/fess_label.properties b/src/main/resources/fess_label.properties index 27a8fc585..ba06e2768 100644 --- a/src/main/resources/fess_label.properties +++ b/src/main/resources/fess_label.properties @@ -775,3 +775,7 @@ labels.upgrade_data_migration=Data Migration labels.upgrade_start_button=Start labels.targetVersion=Version labels.target_version=Version From +labels.esreq_configuration=Request to elasticsearch +labels.esreq_request_file=Request File +labels.requestFile=Request File +labels.esreq_button_upload=Send diff --git a/src/main/resources/fess_label_en.properties b/src/main/resources/fess_label_en.properties index 6513b8ccf..c29fb2ae7 100644 --- a/src/main/resources/fess_label_en.properties +++ b/src/main/resources/fess_label_en.properties @@ -775,3 +775,7 @@ labels.upgrade_data_migration=Data Migration labels.upgrade_start_button=Start labels.targetVersion=Version labels.target_version=Version From +labels.esreq_configuration=Request to elasticsearch +labels.esreq_request_file=Request File +labels.requestFile=Request File +labels.esreq_button_upload=Send diff --git a/src/main/resources/fess_label_ja.properties b/src/main/resources/fess_label_ja.properties index ecf923373..720aa77b2 100644 --- a/src/main/resources/fess_label_ja.properties +++ b/src/main/resources/fess_label_ja.properties @@ -775,3 +775,7 @@ labels.upgrade_data_migration=\u30c7\u30fc\u30bf\u79fb\u884c labels.upgrade_start_button=\u958b\u59cb labels.targetVersion=\u5bfe\u8c61\u30d0\u30fc\u30b8\u30e7\u30f3 labels.target_version=\u5bfe\u8c61\u30d0\u30fc\u30b8\u30e7\u30f3 +labels.esreq_configuration=elasticsearch\u3078\u306e\u30ea\u30af\u30a8\u30b9\u30c8 +labels.esreq_request_file=\u30ea\u30af\u30a8\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb +labels.requestFile=\u30ea\u30af\u30a8\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb +labels.esreq_button_upload=\u9001\u4fe1 diff --git a/src/main/resources/fess_message.properties b/src/main/resources/fess_message.properties index 215755c2a..141b7a863 100644 --- a/src/main/resources/fess_message.properties +++ b/src/main/resources/fess_message.properties @@ -117,6 +117,8 @@ errors.no_user_for_changing_password=The current password is incorrect. errors.failed_to_change_password=Failed to change your password. errors.unknown_version_for_upgrade=Unknown version information. errors.failed_to_upgrade_from=Failed to upgrade from {0}: {1} +errors.failed_to_read_request_file=Failed to read request file: {0} +errors.invalid_header_for_request_file=Invalid header: {0} errors.invalid_query_unknown=The given query has unknown condition. errors.invalid_query_parse_error=The given query is invalid. diff --git a/src/main/resources/fess_message_en.properties b/src/main/resources/fess_message_en.properties index b678fff1d..176b540e5 100644 --- a/src/main/resources/fess_message_en.properties +++ b/src/main/resources/fess_message_en.properties @@ -117,6 +117,8 @@ errors.no_user_for_changing_password=The current password is incorrect. errors.failed_to_change_password=Failed to change your password. errors.unknown_version_for_upgrade=Unknown version information. errors.failed_to_upgrade_from=Failed to upgrade from {0}. +errors.failed_to_read_request_file=Failed to read request file: {0} +errors.invalid_header_for_request_file=Invalid header: {0} errors.invalid_query_unknown=The given query has unknown condition. errors.invalid_query_parse_error=The given query is invalid. diff --git a/src/main/resources/fess_message_ja.properties b/src/main/resources/fess_message_ja.properties index 40354cec1..bd0f3d063 100644 --- a/src/main/resources/fess_message_ja.properties +++ b/src/main/resources/fess_message_ja.properties @@ -124,6 +124,8 @@ errors.no_user_for_changing_password=\u73fe\u5728\u306e\u30d1\u30b9\u30ef\u30fc\ errors.failed_to_change_password=\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u5909\u66f4\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002 errors.unknown_version_for_upgrade=\u4e0d\u660e\u306a\u30d0\u30fc\u30b8\u30e7\u30f3\u60c5\u5831\u3067\u3059\u3002 errors.failed_to_upgrade_from={0}\u304b\u3089\u306e\u30a2\u30c3\u30d7\u30b0\u30ec\u30fc\u30c9\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002 +errors.failed_to_read_request_file=\u30ea\u30af\u30a8\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u306b\u5931\u6557\u3057\u307e\u3057\u305f: {0} +errors.invalid_header_for_request_file=\u30d8\u30c3\u30c0\u30fc\u884c\u304c\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093: {0} success.update_crawler_params = \u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u66f4\u65b0\u3057\u307e\u3057\u305f\u3002 success.delete_doc_from_index = \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304b\u3089\u6587\u66f8\u3092\u524a\u9664\u3059\u308b\u30d7\u30ed\u30bb\u30b9\u3092\u958b\u59cb\u3057\u307e\u3057\u305f\u3002 diff --git a/src/main/webapp/WEB-INF/view/admin/esreq/admin_esreq.jsp b/src/main/webapp/WEB-INF/view/admin/esreq/admin_esreq.jsp new file mode 100644 index 000000000..6f9107d34 --- /dev/null +++ b/src/main/webapp/WEB-INF/view/admin/esreq/admin_esreq.jsp @@ -0,0 +1,72 @@ +<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> + + + +<la:message key="labels.admin_brand_title" /> | <la:message + key="labels.esreq_configuration" /> + + + +
+ + + + + +
+
+

+ +

+ +
+
+
+
+
+
+

+ +

+
+ +
+ <%-- Message --%> +
+ +
${msg}
+
+ +
+ <%-- List --%> +
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ + + +