View Javadoc
1   /*
2    * Copyright 2012-2021 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 javax.annotation.Resource;
19  
20  import org.codelibs.core.beans.util.BeanUtil;
21  import org.codelibs.core.beans.util.CopyOptions;
22  import org.codelibs.core.misc.DynamicProperties;
23  import org.codelibs.fess.app.web.admin.general.AdminGeneralAction;
24  import org.codelibs.fess.app.web.api.ApiResult;
25  import org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse;
26  import org.codelibs.fess.app.web.api.ApiResult.ApiResponse;
27  import org.codelibs.fess.app.web.api.ApiResult.Status;
28  import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
29  import org.lastaflute.web.Execute;
30  import org.lastaflute.web.response.JsonResponse;
31  
32  /**
33   * @author shinsuke
34   */
35  public class ApiAdminGeneralAction extends FessApiAdminAction {
36  
37      // ===================================================================================
38      //                                                                           Attribute
39      //                                                                           =========
40      @Resource
41      protected DynamicProperties systemProperties;
42  
43      // ===================================================================================
44      //
45  
46      // GET /api/admin/general
47      @Execute
48      public JsonResponse<ApiResult> get$index() {
49          final EditBody form = new EditBody();
50          AdminGeneralAction.updateForm(fessConfig, form);
51          form.ldapAdminSecurityCredentials = null;
52          return asJson(new ApiConfigResponse().setting(form).status(Status.OK).result());
53      }
54  
55      // POST /api/admin/general
56      @Execute
57      public JsonResponse<ApiResult> post$index(final EditBody body) {
58          validateApi(body, messages -> {});
59          final EditBody newBody = new EditBody();
60          AdminGeneralAction.updateForm(fessConfig, newBody);
61          BeanUtil.copyBeanToBean(body, newBody, CopyOptions::excludeNull);
62          AdminGeneralAction.updateConfig(fessConfig, newBody);
63          return asJson(new ApiResponse().status(Status.OK).result());
64      }
65  
66  }