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.DataConfigPager;
25  import org.codelibs.fess.es.config.cbean.DataConfigCB;
26  import org.codelibs.fess.es.config.exbhv.DataConfigBhv;
27  import org.codelibs.fess.es.config.exentity.DataConfig;
28  import org.codelibs.fess.mylasta.direction.FessConfig;
29  import org.dbflute.cbean.result.PagingResultBean;
30  import org.dbflute.optional.OptionalEntity;
31  
32  public class DataConfigService {
33  
34      @Resource
35      protected DataConfigBhv dataConfigBhv;
36  
37      @Resource
38      protected FessConfig fessConfig;
39  
40      public List<DataConfig> getDataConfigList(final DataConfigPager dataConfigPager) {
41  
42          final PagingResultBean<DataConfig> dataConfigList = dataConfigBhv.selectPage(cb -> {
43              cb.paging(dataConfigPager.getPageSize(), dataConfigPager.getCurrentPageNumber());
44  
45              setupListCondition(cb, dataConfigPager);
46          });
47  
48          // update pager
49          BeanUtil.copyBeanToBean(dataConfigList, dataConfigPager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
50          dataConfigPager.setPageNumberList(dataConfigList.pageRange(op -> {
51              op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger());
52          }).createPageNumberList());
53  
54          return dataConfigList;
55      }
56  
57      public void delete(final DataConfig dataConfig) {
58          dataConfigBhv.delete(dataConfig, op -> {
59              op.setRefreshPolicy(Constants.TRUE);
60          });
61      }
62  
63      public OptionalEntity<DataConfig> getDataConfig(final String id) {
64          return dataConfigBhv.selectByPK(id);
65      }
66  
67      public void store(final DataConfig dataConfig) {
68  
69          dataConfigBhv.insertOrUpdate(dataConfig, op -> {
70              op.setRefreshPolicy(Constants.TRUE);
71          });
72  
73      }
74  
75      protected void setupListCondition(final DataConfigCB cb, final DataConfigPager dataConfigPager) {
76          if (dataConfigPager.id != null) {
77              cb.query().docMeta().setId_Equal(dataConfigPager.id);
78          }
79          // TODO Long, Integer, String supported only.
80  
81          // setup condition
82          cb.query().addOrderBy_SortOrder_Asc();
83          cb.query().addOrderBy_Name_Asc();
84  
85          // search
86  
87      }
88  
89  }