فهرست منبع

add backup page

Shinsuke Sugaya 9 سال پیش
والد
کامیت
298a790567

+ 89 - 0
src/main/java/org/codelibs/fess/app/web/admin/backup/AdminBackupAction.java

@@ -0,0 +1,89 @@
+/*
+ * 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.backup;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import javax.annotation.Resource;
+
+import org.codelibs.core.lang.StringUtil;
+import org.codelibs.elasticsearch.runner.net.Curl;
+import org.codelibs.elasticsearch.runner.net.CurlResponse;
+import org.codelibs.fess.app.web.base.FessAdminAction;
+import org.codelibs.fess.helper.SystemHelper;
+import org.codelibs.fess.util.RenderDataUtil;
+import org.codelibs.fess.util.ResourceUtil;
+import org.codelibs.fess.util.StreamUtil;
+import org.lastaflute.web.Execute;
+import org.lastaflute.web.response.ActionResponse;
+import org.lastaflute.web.response.HtmlResponse;
+import org.lastaflute.web.ruts.process.ActionRuntime;
+
+/**
+ * @author shinsuke
+ */
+public class AdminBackupAction extends FessAdminAction {
+
+    @Resource
+    private SystemHelper systemHelper;
+
+    @Override
+    protected void setupHtmlData(final ActionRuntime runtime) {
+        super.setupHtmlData(runtime);
+        runtime.registerData("helpLink", systemHelper.getHelpLink(fessConfig.getOnlineHelpNameLog()));
+    }
+
+    @Execute
+    public HtmlResponse index() {
+        return asIndexHtml();
+    }
+
+    @Execute
+    public ActionResponse download(final String id) {
+        if (StreamUtil.of(fessConfig.getIndexBackupTargetsAsArray()).anyMatch(s -> s.equals(id))) {
+            return asStream(id + ".json").stream(
+                    out -> {
+                        try (CurlResponse response =
+                                Curl.get(ResourceUtil.getElasticsearchHttpUrl() + "/" + id + "/_data").param("format", "json").execute()) {
+                            out.write(response.getContentAsStream());
+                        }
+                    });
+        }
+        throwValidationError(messages -> messages.addErrorsCouldNotFindBackupIndex(GLOBAL), () -> {
+            return asIndexHtml();
+        });
+        return redirect(getClass()); // no-op
+    }
+
+    private List<Map<String, String>> getBackupItems() {
+        return StreamUtil.of(fessConfig.getIndexBackupTargetsAsArray()).filter(name -> StringUtil.isNotBlank(name)).map(name -> {
+            final Map<String, String> map = new HashMap<>();
+            map.put("id", name);
+            map.put("name", name);
+            return map;
+        }).collect(Collectors.toList());
+    }
+
+    private HtmlResponse asIndexHtml() {
+        return asHtml(path_AdminBackup_AdminBackupJsp).renderWith(data -> {
+            RenderDataUtil.register(data, "backupItems", getBackupItems());
+        });
+    }
+
+}

+ 3 - 0
src/main/java/org/codelibs/fess/mylasta/action/FessHtmlPath.java

@@ -23,6 +23,9 @@ import org.lastaflute.web.response.next.HtmlNext;
  */
 public interface FessHtmlPath {
 
+    /** The path of the HTML: /admin/backup/admin_backup.jsp */
+    HtmlNext path_AdminBackup_AdminBackupJsp = new HtmlNext("/admin/backup/admin_backup.jsp");
+
     /** The path of the HTML: /admin/badword/admin_badword.jsp */
     HtmlNext path_AdminBadword_AdminBadwordJsp = new HtmlNext("/admin/badword/admin_badword.jsp");
 

+ 9 - 0
src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java

@@ -539,6 +539,9 @@ public class FessLabels extends ActionMessages {
     /** The key of the message: Search */
     public static final String LABELS_menu_search_list = "{labels.menu_search_list}";
 
+    /** The key of the message: Back Up */
+    public static final String LABELS_menu_backup = "{labels.menu_backup}";
+
     /** The key of the message: Search... */
     public static final String LABELS_SIDEBAR_placeholder_search = "{labels.sidebar.placeholder_search}";
 
@@ -2013,6 +2016,12 @@ public class FessLabels extends ActionMessages {
     /** The key of the message: Send TestMail */
     public static final String LABELS_send_testmail = "{labels.send_testmail}";
 
+    /** The key of the message: Back Up */
+    public static final String LABELS_backup_configuration = "{labels.backup_configuration}";
+
+    /** The key of the message: Name */
+    public static final String LABELS_backup_name = "{labels.backup_name}";
+
     /**
      * Assert the property is not null.
      * @param property The value of the property. (NotNull)

+ 17 - 0
src/main/java/org/codelibs/fess/mylasta/action/FessMessages.java

@@ -272,6 +272,9 @@ public class FessMessages extends FessLabels {
     /** The key of the message: Failed to send the test mail. */
     public static final String ERRORS_failed_to_send_testmail = "{errors.failed_to_send_testmail}";
 
+    /** The key of the message: Could not find index for backup. */
+    public static final String ERRORS_COULD_NOT_FIND_BACKUP_INDEX = "{errors.could.not.find.backup.index}";
+
     /** The key of the message: The given query has unknown condition. */
     public static final String ERRORS_invalid_query_unknown = "{errors.invalid_query_unknown}";
 
@@ -1572,6 +1575,20 @@ public class FessMessages extends FessLabels {
         return this;
     }
 
+    /**
+     * Add the created action message for the key 'errors.could.not.find.backup.index' with parameters.
+     * <pre>
+     * message: Could not find index for backup.
+     * </pre>
+     * @param property The property name for the message. (NotNull)
+     * @return this. (NotNull)
+     */
+    public FessMessages addErrorsCouldNotFindBackupIndex(String property) {
+        assertPropertyNotNull(property);
+        add(property, new ActionMessage(ERRORS_COULD_NOT_FIND_BACKUP_INDEX));
+        return this;
+    }
+
     /**
      * Add the created action message for the key 'errors.invalid_query_unknown' with parameters.
      * <pre>

+ 15 - 0
src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java

@@ -273,6 +273,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. true */
     String SMB_ROLE_AS_GROUP = "smb.role.as.group";
 
+    /** The key of the configuration. e.g. .fess_config,.fess_user */
+    String INDEX_BACKUP_TARGETS = "index.backup.targets";
+
     /** The key of the configuration. e.g. admin */
     String AUTHENTICATION_ADMIN_ROLES = "authentication.admin.roles";
 
@@ -1291,6 +1294,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
      */
     boolean isSmbRoleAsGroup();
 
+    /**
+     * Get the value for the key 'index.backup.targets'. <br>
+     * The value is, e.g. .fess_config,.fess_user <br>
+     * comment: backup
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getIndexBackupTargets();
+
     /**
      * Get the value for the key 'authentication.admin.roles'. <br>
      * The value is, e.g. admin <br>
@@ -2407,6 +2418,10 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
             return is(FessConfig.SMB_ROLE_AS_GROUP);
         }
 
+        public String getIndexBackupTargets() {
+            return get(FessConfig.INDEX_BACKUP_TARGETS);
+        }
+
         public String getAuthenticationAdminRoles() {
             return get(FessConfig.AUTHENTICATION_ADMIN_ROLES);
         }

+ 6 - 0
src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java

@@ -124,4 +124,10 @@ public interface FessProp {
         return Constants.TRUE.equalsIgnoreCase(getIndexerThreadDumpEnabled());
     }
 
+    String getIndexBackupTargets();
+
+    public default String[] getIndexBackupTargetsAsArray() {
+        return getIndexBackupTargets().split(",");
+    }
+
 }

+ 3 - 0
src/main/resources/fess_config.properties

@@ -140,6 +140,9 @@ smb.role.from.file=true
 smb.role.as.user=true
 smb.role.as.group=true
 
+# backup
+index.backup.targets=.fess_config,.fess_user
+
 # ========================================================================================
 #                                                                                     Web
 #                                                                                    =====

+ 3 - 0
src/main/resources/fess_label.properties

@@ -173,6 +173,7 @@ labels.menu_log=Log Files
 labels.menu_jobLog=Job Log
 labels.menu_failure_url=Failure URL
 labels.menu_search_list=Search
+labels.menu_backup=Back Up
 labels.sidebar.placeholder_search=Search...
 labels.footer.copyright=Copyright(C) 2009-2015 <a href="https://github.com/codelibs">CodeLibs Project</a>. <span class="br-phone"></span>All Rights Reserved.
 labels.search=Search
@@ -668,3 +669,5 @@ labels.ldap_security_principal=Bind DN
 labels.ldap_base_dn=Base DN
 labels.ldap_account_filter=Account Filter
 labels.send_testmail=Send TestMail
+labels.backup_configuration=Back Up
+labels.backup_name=Name

+ 3 - 0
src/main/resources/fess_label_en.properties

@@ -173,6 +173,7 @@ labels.menu_log=Log Files
 labels.menu_jobLog=Job Log
 labels.menu_failure_url=Failure URL
 labels.menu_search_list=Search
+labels.menu_backup=Back Up
 labels.sidebar.placeholder_search=Search...
 labels.footer.copyright=Copyright(C) 2009-2015 <a href="https://github.com/codelibs">CodeLibs Project</a>. <span class="br-phone"></span>All Rights Reserved.
 labels.search=Search
@@ -668,3 +669,5 @@ labels.ldap_security_principal=Bind DN
 labels.ldap_base_dn=Base DN
 labels.ldap_account_filter=Account Filter
 labels.send_testmail=Send TestMail
+labels.backup_configuration=Back Up
+labels.backup_name=Name

+ 3 - 0
src/main/resources/fess_label_ja.properties

@@ -167,6 +167,7 @@ labels.menu_log = \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb
 labels.menu_jobLog = \u30b8\u30e7\u30d6\u30ed\u30b0
 labels.menu_failure_url = \u969c\u5bb3URL
 labels.menu_search_list = \u691c\u7d22
+labels.menu_backup=\u30d0\u30c3\u30af\u30a2\u30c3\u30d7
 labels.sidebar.placeholder_search = \u691c\u7d22...
 labels.footer.copyright = Copyright(C) 2009-2015 <a href="https://github.com/codelibs">CodeLibs Project</a>. <span class="br-phone"></span>All Rights Reserved.
 labels.search = \u691c\u7d22
@@ -657,3 +658,5 @@ labels.ldap_security_principal=Bind DN
 labels.ldap_base_dn=Base DN
 labels.ldapAccountFilter=\u30a2\u30ab\u30a6\u30f3\u30c8\u30d5\u30a3\u30eb\u30bf
 labels.ldap_account_filter=\u30a2\u30ab\u30a6\u30f3\u30c8\u30d5\u30a3\u30eb\u30bf
+labels.backup_configuration=\u30d0\u30c3\u30af\u30a2\u30c3\u30d7
+labels.backup_name=\u540d\u524d

+ 1 - 0
src/main/resources/fess_message.properties

@@ -112,6 +112,7 @@ errors.invalid_confirm_password=Confirm Password does not match.
 errors.cannot_delete_doc_because_of_running=Crawler is running. The document cannot be deleted.
 errors.failed_to_delete_doc_in_admin=Failed to delete document.
 errors.failed_to_send_testmail=Failed to send the test mail.
+errors.could.not.find.backup.index=Could not find index for backup.
 
 errors.invalid_query_unknown=The given query has unknown condition.
 errors.invalid_query_parse_error=The given query is invalid.

+ 1 - 0
src/main/resources/fess_message_en.properties

@@ -112,6 +112,7 @@ errors.invalid_confirm_password=Confirm Password does not match.
 errors.cannot_delete_doc_because_of_running=Crawler is running. The document cannot be deleted.
 errors.failed_to_delete_doc_in_admin=Failed to delete document.
 errors.failed_to_send_testmail=Failed to send the test mail.
+errors.could.not.find.backup.index=Could not find index for backup.
 
 errors.invalid_query_unknown=The given query has unknown condition.
 errors.invalid_query_parse_error=The given query is invalid.

+ 2 - 0
src/main/resources/fess_message_ja.properties

@@ -116,6 +116,8 @@ errors.invalid_query_unsupported_sort_order = \u6307\u5b9a\u3055\u308c\u305f\u30
 errors.crud_invalid_mode = \u30e2\u30fc\u30c9\u304c\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002({0} \u3067\u306a\u304f\u3001{1} \u3067\u3059)
 errors.crud_failed_to_create_crud_table = \u65b0\u3057\u3044\u30c7\u30fc\u30bf\u306e\u4f5c\u6210\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002
 errors.crud_could_not_find_crud_table = \u30c7\u30fc\u30bf {0} \u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002
+errors.could.not.find.backup.index=\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u7528\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002
+
 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
 success.crawling_info_delete_all = \u30bb\u30c3\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3057\u307e\u3057\u305f\u3002

+ 76 - 0
src/main/webapp/WEB-INF/view/admin/backup/admin_backup.jsp

@@ -0,0 +1,76 @@
+<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title><la:message key="labels.admin_brand_title" /> | <la:message
+		key="labels.backup_configuration" /></title>
+<jsp:include page="/WEB-INF/view/common/admin/head.jsp"></jsp:include>
+</head>
+<body class="skin-blue sidebar-mini">
+	<div class="wrapper">
+		<jsp:include page="/WEB-INF/view/common/admin/header.jsp"></jsp:include>
+		<jsp:include page="/WEB-INF/view/common/admin/sidebar.jsp">
+			<jsp:param name="menuCategoryType" value="log" />
+			<jsp:param name="menuType" value="backup" />
+		</jsp:include>
+		<div class="content-wrapper">
+			<section class="content-header">
+				<h1>
+					<la:message key="labels.backup_configuration" />
+				</h1>
+				<jsp:include page="/WEB-INF/view/common/admin/crud/breadcrumb.jsp"></jsp:include>
+			</section>
+			<section class="content">
+				<div class="row">
+					<div class="col-md-12">
+						<div class="box box-primary">
+							<div class="box-header with-border">
+								<h3 class="box-title">
+									<la:message key="labels.backup_configuration" />
+								</h3>
+							</div>
+							<!-- /.box-header -->
+							<div class="box-body">
+								<%-- Message --%>
+								<div>
+									<la:info id="msg" message="true">
+										<div class="alert alert-info">${msg}</div>
+									</la:info>
+									<la:errors />
+								</div>
+								<%-- List --%>
+								<div class="data-wrapper">
+									<div class="row">
+										<div class="col-sm-12">
+											<table class="table table-bordered table-striped dataTable">
+												<tbody>
+													<tr>
+														<th><la:message key="labels.backup_name" /></th>
+													</tr>
+													<c:forEach var="data" varStatus="s"
+														items="${backupItems}">
+														<tr>
+															<td><la:link href="download/${f:u(data.id)}"
+																	target="_blank">${f:h(data.name)}</la:link></td>
+														</tr>
+													</c:forEach>
+												</tbody>
+											</table>
+										</div>
+									</div>
+								</div>
+								<!-- /.data-wrapper -->
+							</div>
+							<!-- /.box-body -->
+						</div>
+						<!-- /.box -->
+					</div>
+				</div>
+			</section>
+		</div>
+		<jsp:include page="/WEB-INF/view/common/admin/footer.jsp"></jsp:include>
+	</div>
+	<jsp:include page="/WEB-INF/view/common/admin/foot.jsp"></jsp:include>
+</body>
+</html>
+

+ 7 - 0
src/main/webapp/WEB-INF/view/common/admin/sidebar.jsp

@@ -257,6 +257,13 @@
 							<span><la:message key="labels.menu_search_list" /></span>
 						</la:link></li>
 
+					<li
+						<c:if test="${param.menuType=='backup'}">class="active"</c:if>><la:link
+							href="/admin/backup/">
+							<i class='fa fa-circle-o'></i>
+							<span><la:message key="labels.menu_backup" /></span>
+						</la:link></li>
+
 				</ul></li>
 		</ul>
 		<!-- /.sidebar-menu -->