فهرست منبع

add #980 Admin API: /api/admin/systeminfo

Keiichi Watanabe 8 سال پیش
والد
کامیت
eb7046d5e1

+ 29 - 10
src/main/java/org/codelibs/fess/app/web/admin/systeminfo/AdminSysteminfoAction.java

@@ -26,6 +26,7 @@ import org.codelibs.core.lang.StringUtil;
 import org.codelibs.core.misc.DynamicProperties;
 import org.codelibs.core.misc.DynamicProperties;
 import org.codelibs.fess.Constants;
 import org.codelibs.fess.Constants;
 import org.codelibs.fess.app.web.base.FessAdminAction;
 import org.codelibs.fess.app.web.base.FessAdminAction;
+import org.codelibs.fess.util.ComponentUtil;
 import org.codelibs.fess.util.RenderDataUtil;
 import org.codelibs.fess.util.RenderDataUtil;
 import org.lastaflute.web.Execute;
 import org.lastaflute.web.Execute;
 import org.lastaflute.web.response.HtmlResponse;
 import org.lastaflute.web.response.HtmlResponse;
@@ -74,56 +75,74 @@ public class AdminSysteminfoAction extends FessAdminAction {
     //                                                                        ============
     //                                                                        ============
 
 
     protected void registerEnvItems(final RenderData data) {
     protected void registerEnvItems(final RenderData data) {
+        RenderDataUtil.register(data, "envItems", getEnvItems());
+    }
+
+    protected void registerPropItems(final RenderData data) {
+        RenderDataUtil.register(data, "propItems", getPropItems());
+    }
+
+    protected void registerFessPropItems(final RenderData data) {
+        RenderDataUtil.register(data, "fessPropItems", getFessPropItems());
+    }
+
+    protected void registerBugReportItems(final RenderData data) {
+        RenderDataUtil.register(data, "bugReportItems", getBugReportItems());
+    }
+
+    public static List<Map<String, String>> getEnvItems() {
         final List<Map<String, String>> itemList = new ArrayList<>();
         final List<Map<String, String>> itemList = new ArrayList<>();
         for (final Map.Entry<String, String> entry : System.getenv().entrySet()) {
         for (final Map.Entry<String, String> entry : System.getenv().entrySet()) {
             itemList.add(createItem(entry.getKey(), entry.getValue()));
             itemList.add(createItem(entry.getKey(), entry.getValue()));
         }
         }
-        RenderDataUtil.register(data, "envItems", itemList);
+        return itemList;
     }
     }
 
 
-    protected void registerPropItems(final RenderData data) {
+    public static List<Map<String, String>> getPropItems() {
         final List<Map<String, String>> itemList = new ArrayList<>();
         final List<Map<String, String>> itemList = new ArrayList<>();
         for (final Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
         for (final Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
             itemList.add(createItem(entry.getKey(), entry.getValue()));
             itemList.add(createItem(entry.getKey(), entry.getValue()));
         }
         }
-        RenderDataUtil.register(data, "propItems", itemList);
+        return itemList;
     }
     }
 
 
-    protected void registerFessPropItems(final RenderData data) {
+    public static List<Map<String, String>> getFessPropItems() {
         final List<Map<String, String>> itemList = new ArrayList<>();
         final List<Map<String, String>> itemList = new ArrayList<>();
+        final DynamicProperties systemProperties = ComponentUtil.getSystemProperties();
         for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) {
         for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) {
             itemList.add(createItem(entry.getKey(), entry.getValue()));
             itemList.add(createItem(entry.getKey(), entry.getValue()));
         }
         }
-        RenderDataUtil.register(data, "fessPropItems", itemList);
+        return itemList;
     }
     }
 
 
-    protected void registerBugReportItems(final RenderData data) {
+    public static List<Map<String, String>> getBugReportItems() {
         final List<Map<String, String>> itemList = new ArrayList<>();
         final List<Map<String, String>> itemList = new ArrayList<>();
         for (final String label : bugReportLabels) {
         for (final String label : bugReportLabels) {
             itemList.add(createPropItem(label));
             itemList.add(createPropItem(label));
         }
         }
 
 
+        final DynamicProperties systemProperties = ComponentUtil.getSystemProperties();
         for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) {
         for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) {
             if (isBugReportTarget(entry.getKey())) {
             if (isBugReportTarget(entry.getKey())) {
                 itemList.add(createItem(entry.getKey(), entry.getValue()));
                 itemList.add(createItem(entry.getKey(), entry.getValue()));
             }
             }
         }
         }
 
 
-        RenderDataUtil.register(data, "bugReportItems", itemList);
+        return itemList;
     }
     }
 
 
-    private boolean isBugReportTarget(final Object key) {
+    private static boolean isBugReportTarget(final Object key) {
         if ("snapshot.path".equals(key) || "label.value".equals(key)) {
         if ("snapshot.path".equals(key) || "label.value".equals(key)) {
             return false;
             return false;
         }
         }
         return true;
         return true;
     }
     }
 
 
-    protected Map<String, String> createPropItem(final String key) {
+    protected static Map<String, String> createPropItem(final String key) {
         return createItem(key, System.getProperty(key));
         return createItem(key, System.getProperty(key));
     }
     }
 
 
-    protected Map<String, String> createItem(final Object label, final Object value) {
+    protected static Map<String, String> createItem(final Object label, final Object value) {
         final Map<String, String> map = new HashMap<>(2);
         final Map<String, String> map = new HashMap<>(2);
         map.put(Constants.ITEM_LABEL, label != null ? label.toString() : StringUtil.EMPTY);
         map.put(Constants.ITEM_LABEL, label != null ? label.toString() : StringUtil.EMPTY);
         map.put(Constants.ITEM_VALUE, value != null ? value.toString() : StringUtil.EMPTY);
         map.put(Constants.ITEM_VALUE, value != null ? value.toString() : StringUtil.EMPTY);

+ 32 - 0
src/main/java/org/codelibs/fess/app/web/api/ApiResult.java

@@ -189,6 +189,38 @@ public class ApiResult {
         }
         }
     }
     }
 
 
+    public static class ApiSystemInfoResponse extends ApiResponse {
+        protected List<Map<String, String>> envProps;
+        protected List<Map<String, String>> systemProps;
+        protected List<Map<String, String>> fessProps;
+        protected List<Map<String, String>> bugReportProps;
+
+        public ApiSystemInfoResponse envProps(final List<Map<String, String>> envProps) {
+            this.envProps = envProps;
+            return this;
+        }
+
+        public ApiSystemInfoResponse systemProps(final List<Map<String, String>> systemProps) {
+            this.systemProps = systemProps;
+            return this;
+        }
+
+        public ApiSystemInfoResponse fessProps(final List<Map<String, String>> fessProps) {
+            this.fessProps = fessProps;
+            return this;
+        }
+
+        public ApiSystemInfoResponse bugReportProps(final List<Map<String, String>> bugReportProps) {
+            this.bugReportProps = bugReportProps;
+            return this;
+        }
+
+        @Override
+        public ApiResult result() {
+            return new ApiResult(this);
+        }
+    }
+
     public static class ApiErrorResponse extends ApiResponse {
     public static class ApiErrorResponse extends ApiResponse {
         protected String message;
         protected String message;
 
 

+ 50 - 0
src/main/java/org/codelibs/fess/app/web/api/admin/systeminfo/ApiAdminSysteminfoAction.java

@@ -0,0 +1,50 @@
+/*
+ * Copyright 2012-2017 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.api.admin.systeminfo;
+
+import static org.codelibs.fess.app.web.admin.systeminfo.AdminSysteminfoAction.getBugReportItems;
+import static org.codelibs.fess.app.web.admin.systeminfo.AdminSysteminfoAction.getEnvItems;
+import static org.codelibs.fess.app.web.admin.systeminfo.AdminSysteminfoAction.getFessPropItems;
+import static org.codelibs.fess.app.web.admin.systeminfo.AdminSysteminfoAction.getPropItems;
+import java.util.List;
+import java.util.Map;
+
+import org.codelibs.fess.app.web.api.ApiResult;
+import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
+import org.lastaflute.web.Execute;
+import org.lastaflute.web.response.JsonResponse;
+
+/**
+ * @author Keiichi Watanabe
+ */
+public class ApiAdminSysteminfoAction extends FessApiAdminAction {
+
+    // ===================================================================================
+    //                                                                      Search Execute
+    //                                                                      ==============
+
+    // GET /api/admin/systeminfo/info
+    @Execute
+    public JsonResponse<ApiResult> info() {
+        final List<Map<String, String>> bugReportItems = getBugReportItems();
+        final List<Map<String, String>> envItems = getEnvItems();
+        final List<Map<String, String>> fessPropItems = getFessPropItems();
+        final List<Map<String, String>> propItems = getPropItems();
+        return asJson(new ApiResult.ApiSystemInfoResponse().bugReportProps(bugReportItems).envProps(envItems).fessProps(fessPropItems)
+                .systemProps(propItems).status(ApiResult.Status.OK).result());
+    }
+
+}