diff --git a/src/main/java/org/codelibs/fess/app/web/admin/searchlist/AdminSearchlistAction.java b/src/main/java/org/codelibs/fess/app/web/admin/searchlist/AdminSearchlistAction.java index 8f4a6bcd0..65cb64643 100644 --- a/src/main/java/org/codelibs/fess/app/web/admin/searchlist/AdminSearchlistAction.java +++ b/src/main/java/org/codelibs/fess/app/web/admin/searchlist/AdminSearchlistAction.java @@ -186,34 +186,21 @@ public class AdminSearchlistAction extends FessAdminAction { // ----------------------------------------------------- // Confirm // ------- - @Execute - public HtmlResponse confirmDelete(final ListForm form) { - return asHtml(path_AdminSearchlist_ConfirmDeleteJsp); - } @Execute - public HtmlResponse delete(final ListForm form) { - return deleteByQuery(form); - } - - private HtmlResponse deleteByQuery(final ListForm form) { + public HtmlResponse delete(final DeleteForm form) { + validate(form, messages -> {}, () -> asHtml(path_AdminSearchlist_IndexJsp)); final String docId = form.docId; if (jobHelper.isCrawlProcessRunning()) { - // TODO Error + throwValidationError(messages -> messages.addErrorsCannotDeleteDocBecauseOfRunning(GLOBAL), () -> asHtml(path_AdminSearchlist_IndexJsp)); } - final Thread thread = new Thread(() -> { - if (!jobHelper.isCrawlProcessRunning()) { - System.currentTimeMillis(); - try { - final QueryBuilder query = QueryBuilders.termQuery(fieldHelper.docIdField, docId); - fessEsClient.deleteByQuery(fieldHelper.docIndex, fieldHelper.docType, query); - } catch (final Exception e) { - // TODO Log - } + try { + final QueryBuilder query = QueryBuilders.termQuery(fieldHelper.docIdField, docId); + fessEsClient.deleteByQuery(fieldHelper.docIndex, fieldHelper.docType, query); + saveInfo(messages -> messages.addSuccessDeleteSolrIndex(GLOBAL)); + } catch (final Exception e) { + throwValidationError(messages -> messages.addErrorsFailedToDeleteDocInAdmin(GLOBAL), () -> asHtml(path_AdminSearchlist_IndexJsp)); } - } ); - thread.start(); - saveInfo(messages -> messages.addSuccessDeleteSolrIndex(GLOBAL)); return redirectWith(getClass(), moreUrl("search").params("query", form.query)); } diff --git a/src/main/java/org/codelibs/fess/app/web/admin/searchlist/DeleteForm.java b/src/main/java/org/codelibs/fess/app/web/admin/searchlist/DeleteForm.java new file mode 100644 index 000000000..005ff2234 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/admin/searchlist/DeleteForm.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2015 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.searchlist; + +import java.io.Serializable; + +import javax.validation.constraints.Size; + +import org.lastaflute.web.validation.Required; + +public class DeleteForm implements Serializable { + + private static final long serialVersionUID = 1L; + + @Size(max = 1000) + public String query; + + @Required + public String docId; + +} diff --git a/src/main/java/org/codelibs/fess/app/web/admin/searchlist/ListForm.java b/src/main/java/org/codelibs/fess/app/web/admin/searchlist/ListForm.java index 25c309ddd..2468cbbe1 100644 --- a/src/main/java/org/codelibs/fess/app/web/admin/searchlist/ListForm.java +++ b/src/main/java/org/codelibs/fess/app/web/admin/searchlist/ListForm.java @@ -53,12 +53,6 @@ public class ListForm implements SearchRequestParams, Serializable { public String[] lang; - // @Required - public String docId; - - // @Required - public String url; - @Override public String getQuery() { return query; 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 a8c14927a..98e62a25b 100644 --- a/src/main/java/org/codelibs/fess/mylasta/action/FessMessages.java +++ b/src/main/java/org/codelibs/fess/mylasta/action/FessMessages.java @@ -324,6 +324,12 @@ public class FessMessages extends FessLabels { /** The key of the message: Invalid password. */ public static final String ERRORS_password_does_not_exist_in_session = "{errors.password_does_not_exist_in_session}"; + /** The key of the message: Crawler is running. The document cannot be deteled. */ + public static final String ERRORS_cannot_delete_doc_because_of_running = "{errors.cannot_delete_doc_because_of_running}"; + + /** The key of the message: Failed to delete document. */ + public static final String ERRORS_failed_to_delete_doc_in_admin = "{errors.failed_to_delete_doc_in_admin}"; + /** The key of the message: The given query has unknown condition. */ public static final String ERRORS_invalid_query_unknown = "{errors.invalid_query_unknown}"; @@ -1924,6 +1930,34 @@ public class FessMessages extends FessLabels { return this; } + /** + * Add the created action message for the key 'errors.cannot_delete_doc_because_of_running' with parameters. + *
+     * message: Crawler is running. The document cannot be deteled.
+     * 
+ * @param property The property name for the message. (NotNull) + * @return this. (NotNull) + */ + public FessMessages addErrorsCannotDeleteDocBecauseOfRunning(String property) { + assertPropertyNotNull(property); + add(property, new ActionMessage(ERRORS_cannot_delete_doc_because_of_running)); + return this; + } + + /** + * Add the created action message for the key 'errors.failed_to_delete_doc_in_admin' with parameters. + *
+     * message: Failed to delete document.
+     * 
+ * @param property The property name for the message. (NotNull) + * @return this. (NotNull) + */ + public FessMessages addErrorsFailedToDeleteDocInAdmin(String property) { + assertPropertyNotNull(property); + add(property, new ActionMessage(ERRORS_failed_to_delete_doc_in_admin)); + return this; + } + /** * Add the created action message for the key 'errors.invalid_query_unknown' with parameters. *
diff --git a/src/main/resources/fess_message.properties b/src/main/resources/fess_message.properties
index a4d94f43a..42026ab7d 100644
--- a/src/main/resources/fess_message.properties
+++ b/src/main/resources/fess_message.properties
@@ -129,6 +129,8 @@ errors.failed_to_reload_core=Failed to reload core. Check log files.
 errors.blank_password=Password is required.
 errors.invalid_confirm_password=Confirm Password does not match.
 errors.password_does_not_exist_in_session=Invalid password.
+errors.cannot_delete_doc_because_of_running=Crawler is running. The document cannot be deteled.
+errors.failed_to_delete_doc_in_admin=Failed to delete document.
 
 errors.invalid_query_unknown=The given query has unknown condition.
 errors.invalid_query_quoted=An invalid quote character is used.