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