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.dict;
17  
18  import java.util.stream.Collectors;
19  import java.util.stream.Stream;
20  
21  import javax.annotation.Resource;
22  
23  import org.codelibs.fess.app.web.api.ApiResult;
24  import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
25  import org.codelibs.fess.dict.DictionaryFile;
26  import org.codelibs.fess.dict.DictionaryItem;
27  import org.codelibs.fess.dict.DictionaryManager;
28  import org.lastaflute.web.Execute;
29  import org.lastaflute.web.response.JsonResponse;
30  
31  public class ApiAdminDictAction extends FessApiAdminAction {
32      @Resource
33      protected DictionaryManager dictionaryManager;
34  
35      // GET /api/admin/dict
36      @Execute
37      public JsonResponse<ApiResult> get$index() {
38          final DictionaryFile<? extends DictionaryItem>[] dictFiles = dictionaryManager.getDictionaryFiles();
39          return asJson(new ApiResult.ApiConfigsResponse<ListBody>()
40                  .settings(Stream.of(dictFiles).map(this::createListBody).collect(Collectors.toList())).status(ApiResult.Status.OK)
41                  .result());
42      }
43  
44      protected ListBody createListBody(final DictionaryFile<? extends DictionaryItem> dictionaryFile) {
45          final ListBody body = new ListBody();
46          body.id = dictionaryFile.getId();
47          body.type = dictionaryFile.getType();
48          body.path = dictionaryFile.getPath();
49          body.timestamp = dictionaryFile.getTimestamp();
50          return body;
51      }
52  }