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.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.BoostDocPager;
25  import org.codelibs.fess.es.config.cbean.BoostDocumentRuleCB;
26  import org.codelibs.fess.es.config.exbhv.BoostDocumentRuleBhv;
27  import org.codelibs.fess.es.config.exentity.BoostDocumentRule;
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 BoostDocumentRuleService {
33  
34      @Resource
35      protected BoostDocumentRuleBhv boostDocumentRuleBhv;
36  
37      @Resource
38      protected FessConfig fessConfig;
39  
40      public List<BoostDocumentRule> getBoostDocumentRuleList(final BoostDocPager boostDocumentRulePager) {
41  
42          final PagingResultBean<BoostDocumentRule> boostDocumentRuleList = boostDocumentRuleBhv.selectPage(cb -> {
43              cb.paging(boostDocumentRulePager.getPageSize(), boostDocumentRulePager.getCurrentPageNumber());
44              setupListCondition(cb, boostDocumentRulePager);
45          });
46  
47          // update pager
48          BeanUtil.copyBeanToBean(boostDocumentRuleList, boostDocumentRulePager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
49          boostDocumentRulePager.setPageNumberList(boostDocumentRuleList.pageRange(
50                  op -> op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger())).createPageNumberList());
51  
52          return boostDocumentRuleList;
53      }
54  
55      public OptionalEntity<BoostDocumentRule> getBoostDocumentRule(final String id) {
56          return boostDocumentRuleBhv.selectByPK(id);
57      }
58  
59      public void store(final BoostDocumentRule boostDocumentRule) {
60  
61          boostDocumentRuleBhv.insertOrUpdate(boostDocumentRule, op -> op.setRefreshPolicy(Constants.TRUE));
62  
63      }
64  
65      public void delete(final BoostDocumentRule boostDocumentRule) {
66  
67          boostDocumentRuleBhv.delete(boostDocumentRule, op -> op.setRefreshPolicy(Constants.TRUE));
68  
69      }
70  
71      protected void setupListCondition(final BoostDocumentRuleCB cb, final BoostDocPager boostDocumentRulePager) {
72          if (boostDocumentRulePager.id != null) {
73              cb.query().docMeta().setId_Equal(boostDocumentRulePager.id);
74          }
75          // TODO Long, Integer, String supported only.
76  
77          // setup condition
78          cb.query().addOrderBy_SortOrder_Asc();
79          cb.query().addOrderBy_CreatedTime_Asc();
80  
81          // search
82  
83      }
84  
85      public List<BoostDocumentRule> getAvailableBoostDocumentRuleList() {
86          return boostDocumentRuleBhv.selectList(cb -> {
87              cb.query().matchAll();
88              cb.query().addOrderBy_SortOrder_Asc();
89              cb.fetchFirst(fessConfig.getPageDocboostMaxFetchSizeAsInteger());
90          });
91      }
92  
93  }