1 /*
2 * Copyright 2012-2025 CodeLibs Project and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.codelibs.fess.app.web.api.admin.general;
17
18 import org.codelibs.core.beans.util.BeanUtil;
19 import org.codelibs.core.beans.util.CopyOptions;
20 import org.codelibs.core.misc.DynamicProperties;
21 import org.codelibs.fess.app.web.admin.general.AdminGeneralAction;
22 import org.codelibs.fess.app.web.api.ApiResult;
23 import org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse;
24 import org.codelibs.fess.app.web.api.ApiResult.ApiResponse;
25 import org.codelibs.fess.app.web.api.ApiResult.Status;
26 import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
27 import org.lastaflute.web.Execute;
28 import org.lastaflute.web.response.JsonResponse;
29
30 import jakarta.annotation.Resource;
31
32 /**
33 * API action for admin general settings management.
34 * Provides RESTful API endpoints for managing general system configuration settings in the Fess search engine.
35 * General settings include system-wide parameters, LDAP configuration, and core application settings.
36 *
37 */
38 public class ApiAdminGeneralAction extends FessApiAdminAction {
39
40 // ===================================================================================
41 // Constructor
42 // ===========
43 /**
44 * Default constructor.
45 */
46 public ApiAdminGeneralAction() {
47 super();
48 }
49
50 // ===================================================================================
51 // Attribute
52 // =========
53 /** System properties for dynamic configuration management */
54 @Resource
55 protected DynamicProperties systemProperties;
56
57 // ===================================================================================
58 //
59
60 // GET /api/admin/general
61 /**
62 * Returns the current general system settings.
63 * Excludes sensitive information like LDAP security credentials from the response.
64 *
65 * @return JSON response containing the general settings configuration
66 */
67 @Execute
68 public JsonResponse<ApiResult> get$index() {
69 final EditBody form = new EditBody();
70 AdminGeneralAction.updateForm(fessConfig, form);
71 form.ldapAdminSecurityCredentials = null;
72 return asJson(new ApiConfigResponse().setting(form).status(Status.OK).result());
73 }
74
75 // PUT /api/admin/general
76 /**
77 * Updates the general system settings.
78 * Merges the provided settings with existing configuration and applies changes.
79 *
80 * @param body the general settings data to update
81 * @return JSON response with update status
82 */
83 @Execute
84 public JsonResponse<ApiResult> put$index(final EditBody body) {
85 validateApi(body, messages -> {});
86 final EditBody newBody = new EditBody();
87 AdminGeneralAction.updateForm(fessConfig, newBody);
88 BeanUtil.copyBeanToBean(body, newBody, CopyOptions::excludeNull);
89 AdminGeneralAction.updateConfig(fessConfig, newBody);
90 return asJson(new ApiResponse().status(Status.OK).result());
91 }
92
93 }