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.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.CrawlingInfoDbm;
26  import org.codelibs.fess.es.config.cbean.CrawlingInfoCB;
27  import org.codelibs.fess.es.config.cbean.ca.CrawlingInfoCA;
28  import org.codelibs.fess.es.config.cbean.ca.bs.BsCrawlingInfoCA;
29  import org.codelibs.fess.es.config.cbean.cq.CrawlingInfoCQ;
30  import org.codelibs.fess.es.config.cbean.cq.bs.BsCrawlingInfoCQ;
31  import org.dbflute.cbean.ConditionQuery;
32  
33  /**
34   * @author ESFlute (using FreeGen)
35   */
36  public class BsCrawlingInfoCB extends EsAbstractConditionBean {
37  
38      // ===================================================================================
39      //                                                                           Attribute
40      //                                                                           =========
41      protected BsCrawlingInfoCQ _conditionQuery;
42      protected BsCrawlingInfoCA _conditionAggregation;
43      protected HpSpecification _specification;
44  
45      // ===================================================================================
46      //                                                                             Control
47      //                                                                             =======
48      @Override
49      public CrawlingInfoDbm asDBMeta() {
50          return CrawlingInfoDbm.getInstance();
51      }
52  
53      @Override
54      public String asTableDbName() {
55          return "crawling_info";
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      //                                                                         Primary Key
70      //                                                                         ===========
71      public CrawlingInfoCB acceptPK(String id) {
72          assertObjectNotNull("id", id);
73          BsCrawlingInfoCB cb = this;
74          cb.query().docMeta().setId_Equal(id);
75          return (CrawlingInfoCB) this;
76      }
77  
78      @Override
79      public void acceptPrimaryKeyMap(Map<String, ? extends Object> primaryKeyMap) {
80          acceptPK((String) primaryKeyMap.get("_id"));
81      }
82  
83      // ===================================================================================
84      //                                                                               Build
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     //                                                                               Query
112     //                                                                               =====
113     public BsCrawlingInfoCQ query() {
114         assertQueryPurpose();
115         return doGetConditionQuery();
116     }
117 
118     protected BsCrawlingInfoCQ doGetConditionQuery() {
119         if (_conditionQuery == null) {
120             _conditionQuery = createLocalCQ();
121         }
122         return _conditionQuery;
123     }
124 
125     protected BsCrawlingInfoCQ createLocalCQ() {
126         return new CrawlingInfoCQ();
127     }
128 
129     // ===================================================================================
130     //                                                                         Aggregation
131     //                                                                         ===========
132     public BsCrawlingInfoCA aggregation() {
133         assertAggregationPurpose();
134         return doGetConditionAggregation();
135     }
136 
137     protected BsCrawlingInfoCA doGetConditionAggregation() {
138         if (_conditionAggregation == null) {
139             _conditionAggregation = createLocalCA();
140         }
141         return _conditionAggregation;
142     }
143 
144     protected BsCrawlingInfoCA createLocalCA() {
145         return new CrawlingInfoCA();
146     }
147 
148     // ===================================================================================
149     //                                                                             Specify
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 columnCreatedTime() {
180             doColumn("createdTime");
181         }
182 
183         public void columnExpiredTime() {
184             doColumn("expiredTime");
185         }
186 
187         public void columnName() {
188             doColumn("name");
189         }
190 
191         public void columnSessionId() {
192             doColumn("sessionId");
193         }
194     }
195 }