add #980 Admin API: /api/admin/systeminfo
This commit is contained in:
parent
510a3e08d3
commit
eb7046d5e1
3 changed files with 111 additions and 10 deletions
|
@ -26,6 +26,7 @@ import org.codelibs.core.lang.StringUtil;
|
|||
import org.codelibs.core.misc.DynamicProperties;
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.app.web.base.FessAdminAction;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.RenderDataUtil;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.HtmlResponse;
|
||||
|
@ -74,56 +75,74 @@ public class AdminSysteminfoAction extends FessAdminAction {
|
|||
// ============
|
||||
|
||||
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<>();
|
||||
for (final Map.Entry<String, String> entry : System.getenv().entrySet()) {
|
||||
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<>();
|
||||
for (final Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
|
||||
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 DynamicProperties systemProperties = ComponentUtil.getSystemProperties();
|
||||
for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) {
|
||||
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<>();
|
||||
for (final String label : bugReportLabels) {
|
||||
itemList.add(createPropItem(label));
|
||||
}
|
||||
|
||||
final DynamicProperties systemProperties = ComponentUtil.getSystemProperties();
|
||||
for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) {
|
||||
if (isBugReportTarget(entry.getKey())) {
|
||||
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)) {
|
||||
return false;
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
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);
|
||||
map.put(Constants.ITEM_LABEL, label != null ? label.toString() : StringUtil.EMPTY);
|
||||
map.put(Constants.ITEM_VALUE, value != null ? value.toString() : StringUtil.EMPTY);
|
||||
|
|
|
@ -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 {
|
||||
protected String message;
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue