View Javadoc
1   /*
2    * Copyright 2012-2019 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.service;
17  
18  import java.util.List;
19  
20  import javax.annotation.Resource;
21  
22  import org.codelibs.core.beans.util.BeanUtil;
23  import org.codelibs.fess.Constants;
24  import org.codelibs.fess.app.pager.FileConfigPager;
25  import org.codelibs.fess.es.config.cbean.FileConfigCB;
26  import org.codelibs.fess.es.config.exbhv.FileAuthenticationBhv;
27  import org.codelibs.fess.es.config.exbhv.FileConfigBhv;
28  import org.codelibs.fess.es.config.exentity.FileConfig;
29  import org.codelibs.fess.mylasta.direction.FessConfig;
30  import org.dbflute.cbean.result.PagingResultBean;
31  import org.dbflute.optional.OptionalEntity;
32  
33  public class FileConfigService {
34  
35      @Resource
36      protected FileConfigBhv fileConfigBhv;
37  
38      @Resource
39      protected FileAuthenticationBhv fileAuthenticationBhv;
40  
41      @Resource
42      protected FessConfig fessConfig;
43  
44      public List<FileConfig> getFileConfigList(final FileConfigPager fileConfigPager) {
45  
46          final PagingResultBean<FileConfig> fileConfigList = fileConfigBhv.selectPage(cb -> {
47              cb.paging(fileConfigPager.getPageSize(), fileConfigPager.getCurrentPageNumber());
48              setupListCondition(cb, fileConfigPager);
49          });
50  
51          // update pager
52          BeanUtil.copyBeanToBean(fileConfigList, fileConfigPager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
53          fileConfigPager.setPageNumberList(fileConfigList.pageRange(op -> {
54              op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger());
55          }).createPageNumberList());
56  
57          return fileConfigList;
58      }
59  
60      public void delete(final FileConfig fileConfig) {
61  
62          final String fileConfigId = fileConfig.getId();
63  
64          fileConfigBhv.delete(fileConfig, op -> {
65              op.setRefreshPolicy(Constants.TRUE);
66          });
67  
68          fileAuthenticationBhv.queryDelete(cb -> {
69              cb.query().setFileConfigId_Equal(fileConfigId);
70          });
71      }
72  
73      public OptionalEntity<FileConfig> getFileConfig(final String id) {
74          return fileConfigBhv.selectByPK(id);
75      }
76  
77      public void store(final FileConfig fileConfig) {
78          fileConfigBhv.insertOrUpdate(fileConfig, op -> {
79              op.setRefreshPolicy(Constants.TRUE);
80          });
81      }
82  
83      protected void setupListCondition(final FileConfigCB cb, final FileConfigPager fileConfigPager) {
84          if (fileConfigPager.id != null) {
85              cb.query().docMeta().setId_Equal(fileConfigPager.id);
86          }
87          // TODO Long, Integer, String supported only.
88  
89          // setup condition
90          cb.query().addOrderBy_SortOrder_Asc();
91          cb.query().addOrderBy_Name_Asc();
92  
93          // search
94  
95      }
96  
97  }