View Javadoc
1   /*
2    * Copyright 2012-2017 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.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.KeyMatchPager;
25  import org.codelibs.fess.es.config.cbean.KeyMatchCB;
26  import org.codelibs.fess.es.config.exbhv.KeyMatchBhv;
27  import org.codelibs.fess.es.config.exentity.KeyMatch;
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 KeyMatchService {
33  
34      @Resource
35      protected KeyMatchBhv keyMatchBhv;
36  
37      @Resource
38      protected FessConfig fessConfig;
39  
40      public List<KeyMatch> getKeyMatchList(final KeyMatchPager keyMatchPager) {
41  
42          final PagingResultBean<KeyMatch> keyMatchList = keyMatchBhv.selectPage(cb -> {
43              cb.paging(keyMatchPager.getPageSize(), keyMatchPager.getCurrentPageNumber());
44              setupListCondition(cb, keyMatchPager);
45          });
46  
47          // update pager
48          BeanUtil.copyBeanToBean(keyMatchList, keyMatchPager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
49          keyMatchPager.setPageNumberList(keyMatchList.pageRange(op -> {
50              op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger());
51          }).createPageNumberList());
52  
53          return keyMatchList;
54      }
55  
56      public OptionalEntity<KeyMatch> getKeyMatch(final String id) {
57          return keyMatchBhv.selectByPK(id);
58      }
59  
60      public void store(final KeyMatch keyMatch) {
61  
62          keyMatchBhv.insertOrUpdate(keyMatch, op -> {
63              op.setRefreshPolicy(Constants.TRUE);
64          });
65  
66      }
67  
68      public void delete(final KeyMatch keyMatch) {
69  
70          keyMatchBhv.delete(keyMatch, op -> {
71              op.setRefreshPolicy(Constants.TRUE);
72          });
73  
74      }
75  
76      protected void setupListCondition(final KeyMatchCB cb, final KeyMatchPager keyMatchPager) {
77          if (keyMatchPager.id != null) {
78              cb.query().docMeta().setId_Equal(keyMatchPager.id);
79          }
80          // TODO Long, Integer, String supported only.
81  
82          // setup condition
83          cb.query().addOrderBy_Term_Asc();
84  
85          // search
86  
87      }
88  
89  }