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 org.codelibs.core.beans.util.BeanUtil;
21 import org.codelibs.core.lang.StringUtil;
22 import org.codelibs.fess.Constants;
23 import org.codelibs.fess.app.pager.KeyMatchPager;
24 import org.codelibs.fess.mylasta.direction.FessConfig;
25 import org.codelibs.fess.opensearch.config.cbean.KeyMatchCB;
26 import org.codelibs.fess.opensearch.config.exbhv.KeyMatchBhv;
27 import org.codelibs.fess.opensearch.config.exentity.KeyMatch;
28 import org.dbflute.cbean.result.PagingResultBean;
29 import org.dbflute.optional.OptionalEntity;
30
31 import jakarta.annotation.Resource;
32
33
34
35
36 public class KeyMatchService extends FessAppService {
37
38
39 @Resource
40 protected KeyMatchBhv keyMatchBhv;
41
42
43
44
45 public KeyMatchService() {
46 super();
47 }
48
49
50 @Resource
51 protected FessConfig fessConfig;
52
53
54
55
56
57
58
59 public List<KeyMatch> getKeyMatchList(final KeyMatchPager keyMatchPager) {
60
61 final PagingResultBean<KeyMatch> keyMatchList = keyMatchBhv.selectPage(cb -> {
62 cb.paging(keyMatchPager.getPageSize(), keyMatchPager.getCurrentPageNumber());
63 setupListCondition(cb, keyMatchPager);
64 });
65
66
67 BeanUtil.copyBeanToBean(keyMatchList, keyMatchPager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
68 keyMatchPager.setPageNumberList(keyMatchList.pageRange(op -> {
69 op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger());
70 }).createPageNumberList());
71
72 return keyMatchList;
73 }
74
75
76
77
78
79
80
81 public OptionalEntity<KeyMatch> getKeyMatch(final String id) {
82 return keyMatchBhv.selectByPK(id);
83 }
84
85
86
87
88
89
90 public void store(final KeyMatch keyMatch) {
91
92 keyMatchBhv.insertOrUpdate(keyMatch, op -> {
93 op.setRefreshPolicy(Constants.TRUE);
94 });
95
96 }
97
98
99
100
101
102
103 public void delete(final KeyMatch keyMatch) {
104
105 keyMatchBhv.delete(keyMatch, op -> {
106 op.setRefreshPolicy(Constants.TRUE);
107 });
108
109 }
110
111
112
113
114
115
116
117 protected void setupListCondition(final KeyMatchCB cb, final KeyMatchPager keyMatchPager) {
118 if (StringUtil.isNotBlank(keyMatchPager.term)) {
119 cb.query().setTerm_Wildcard(wrapQuery(keyMatchPager.term));
120 }
121 if (StringUtil.isNotBlank(keyMatchPager.query)) {
122 cb.query().setQuery_Wildcard(wrapQuery(keyMatchPager.query));
123 }
124
125
126
127 cb.query().addOrderBy_Term_Asc();
128
129
130
131 }
132
133 }