1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
76
77
78 cb.query().addOrderBy_SortOrder_Asc();
79 cb.query().addOrderBy_CreatedTime_Asc();
80
81
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 }