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