1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.es.config.cbean.bs;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.codelibs.fesen.action.search.SearchRequestBuilder;
23 import org.codelibs.fesen.index.query.QueryBuilder;
24 import org.codelibs.fess.es.config.allcommon.EsAbstractConditionBean;
25 import org.codelibs.fess.es.config.bsentity.dbmeta.RelatedQueryDbm;
26 import org.codelibs.fess.es.config.cbean.RelatedQueryCB;
27 import org.codelibs.fess.es.config.cbean.ca.RelatedQueryCA;
28 import org.codelibs.fess.es.config.cbean.ca.bs.BsRelatedQueryCA;
29 import org.codelibs.fess.es.config.cbean.cq.RelatedQueryCQ;
30 import org.codelibs.fess.es.config.cbean.cq.bs.BsRelatedQueryCQ;
31 import org.dbflute.cbean.ConditionQuery;
32
33
34
35
36 public class BsRelatedQueryCB extends EsAbstractConditionBean {
37
38
39
40
41 protected BsRelatedQueryCQ _conditionQuery;
42 protected BsRelatedQueryCA _conditionAggregation;
43 protected HpSpecification _specification;
44
45
46
47
48 @Override
49 public RelatedQueryDbm asDBMeta() {
50 return RelatedQueryDbm.getInstance();
51 }
52
53 @Override
54 public String asTableDbName() {
55 return "related_query";
56 }
57
58 @Override
59 public boolean hasSpecifiedColumn() {
60 return _specification != null;
61 }
62
63 @Override
64 public ConditionQuery localCQ() {
65 return doGetConditionQuery();
66 }
67
68
69
70
71 public RelatedQueryCB acceptPK(String id) {
72 assertObjectNotNull("id", id);
73 BsRelatedQueryCB cb = this;
74 cb.query().docMeta().setId_Equal(id);
75 return (RelatedQueryCB) this;
76 }
77
78 @Override
79 public void acceptPrimaryKeyMap(Map<String, ? extends Object> primaryKeyMap) {
80 acceptPK((String) primaryKeyMap.get("_id"));
81 }
82
83
84
85
86
87 @Override
88 public SearchRequestBuilder build(SearchRequestBuilder builder) {
89 if (_conditionQuery != null) {
90 QueryBuilder queryBuilder = _conditionQuery.getQuery();
91 if (queryBuilder != null) {
92 builder.setQuery(queryBuilder);
93 }
94 _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
95 builder.addSort(sort);
96 });
97 }
98
99 if (_conditionAggregation != null) {
100 _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
101 }
102
103 if (_specification != null) {
104 builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
105 }
106
107 return builder;
108 }
109
110
111
112
113 public BsRelatedQueryCQ query() {
114 assertQueryPurpose();
115 return doGetConditionQuery();
116 }
117
118 protected BsRelatedQueryCQ doGetConditionQuery() {
119 if (_conditionQuery == null) {
120 _conditionQuery = createLocalCQ();
121 }
122 return _conditionQuery;
123 }
124
125 protected BsRelatedQueryCQ createLocalCQ() {
126 return new RelatedQueryCQ();
127 }
128
129
130
131
132 public BsRelatedQueryCA aggregation() {
133 assertAggregationPurpose();
134 return doGetConditionAggregation();
135 }
136
137 protected BsRelatedQueryCA doGetConditionAggregation() {
138 if (_conditionAggregation == null) {
139 _conditionAggregation = createLocalCA();
140 }
141 return _conditionAggregation;
142 }
143
144 protected BsRelatedQueryCA createLocalCA() {
145 return new RelatedQueryCA();
146 }
147
148
149
150
151 public HpSpecification specify() {
152 assertSpecifyPurpose();
153 if (_specification == null) {
154 _specification = new HpSpecification();
155 }
156 return _specification;
157 }
158
159 protected void assertQueryPurpose() {
160 }
161
162 protected void assertAggregationPurpose() {
163 }
164
165 protected void assertSpecifyPurpose() {
166 }
167
168 public static class HpSpecification {
169 protected List<String> columnList = new ArrayList<>();
170
171 private void doColumn(String name) {
172 columnList.add(name);
173 }
174
175 public void columnId() {
176 doColumn("_id");
177 }
178
179 public void columnCreatedBy() {
180 doColumn("createdBy");
181 }
182
183 public void columnCreatedTime() {
184 doColumn("createdTime");
185 }
186
187 public void columnQueries() {
188 doColumn("queries");
189 }
190
191 public void columnTerm() {
192 doColumn("term");
193 }
194
195 public void columnUpdatedBy() {
196 doColumn("updatedBy");
197 }
198
199 public void columnUpdatedTime() {
200 doColumn("updatedTime");
201 }
202
203 public void columnVirtualHost() {
204 doColumn("virtualHost");
205 }
206 }
207 }