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.Collection;
19 import java.util.List;
20
21 import org.codelibs.core.beans.util.BeanUtil;
22 import org.codelibs.core.lang.StringUtil;
23 import org.codelibs.fess.Constants;
24 import org.codelibs.fess.app.pager.PathMapPager;
25 import org.codelibs.fess.mylasta.direction.FessConfig;
26 import org.codelibs.fess.opensearch.config.cbean.PathMappingCB;
27 import org.codelibs.fess.opensearch.config.exbhv.PathMappingBhv;
28 import org.codelibs.fess.opensearch.config.exentity.PathMapping;
29 import org.codelibs.fess.util.ComponentUtil;
30 import org.dbflute.cbean.result.PagingResultBean;
31 import org.dbflute.optional.OptionalEntity;
32
33 import jakarta.annotation.Resource;
34
35
36
37
38 public class PathMappingService extends FessAppService {
39
40
41
42
43 public PathMappingService() {
44 super();
45 }
46
47
48 @Resource
49 protected PathMappingBhv pathMappingBhv;
50
51
52 @Resource
53 protected FessConfig fessConfig;
54
55
56
57
58
59
60
61 public List<PathMapping> getPathMappingList(final PathMapPager pathMappingPager) {
62
63 final PagingResultBean<PathMapping> pathMappingList = pathMappingBhv.selectPage(cb -> {
64 cb.paging(pathMappingPager.getPageSize(), pathMappingPager.getCurrentPageNumber());
65 setupListCondition(cb, pathMappingPager);
66 });
67
68
69 BeanUtil.copyBeanToBean(pathMappingList, pathMappingPager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
70 pathMappingPager.setPageNumberList(pathMappingList.pageRange(op -> {
71 op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger());
72 }).createPageNumberList());
73
74 return pathMappingList;
75 }
76
77
78
79
80
81
82
83 public OptionalEntity<PathMapping> getPathMapping(final String id) {
84 return pathMappingBhv.selectByPK(id);
85 }
86
87
88
89
90
91
92 public void store(final PathMapping pathMapping) {
93
94 pathMappingBhv.insertOrUpdate(pathMapping, op -> {
95 op.setRefreshPolicy(Constants.TRUE);
96 });
97
98 ComponentUtil.getPathMappingHelper().init();
99 }
100
101
102
103
104
105
106 public void delete(final PathMapping pathMapping) {
107
108 pathMappingBhv.delete(pathMapping, op -> {
109 op.setRefreshPolicy(Constants.TRUE);
110 });
111
112 ComponentUtil.getPathMappingHelper().init();
113 }
114
115
116
117
118
119
120
121 public List<PathMapping> getPathMappingList(final Collection<String> processTypeList) {
122
123 return pathMappingBhv.selectList(cb -> {
124 cb.query().addOrderBy_SortOrder_Asc();
125 cb.query().setProcessType_InScope(processTypeList);
126 cb.fetchFirst(fessConfig.getPagePathMappingMaxFetchSizeAsInteger());
127 });
128 }
129
130
131
132
133
134
135
136 protected void setupListCondition(final PathMappingCB cb, final PathMapPager pathMappingPager) {
137 if (StringUtil.isNotBlank(pathMappingPager.regex)) {
138 cb.query().setRegex_Wildcard(wrapQuery(pathMappingPager.regex));
139 }
140 if (StringUtil.isNotBlank(pathMappingPager.replacement)) {
141 cb.query().setReplacement_Wildcard(wrapQuery(pathMappingPager.replacement));
142 }
143
144
145
146 cb.query().addOrderBy_SortOrder_Asc();
147 cb.query().addOrderBy_CreatedTime_Asc();
148
149
150
151 }
152
153 }