View Javadoc
1   /*
2    * Copyright 2012-2019 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.WebConfigPager;
25  import org.codelibs.fess.es.config.cbean.WebConfigCB;
26  import org.codelibs.fess.es.config.exbhv.RequestHeaderBhv;
27  import org.codelibs.fess.es.config.exbhv.WebAuthenticationBhv;
28  import org.codelibs.fess.es.config.exbhv.WebConfigBhv;
29  import org.codelibs.fess.es.config.exentity.WebConfig;
30  import org.codelibs.fess.mylasta.direction.FessConfig;
31  import org.dbflute.cbean.result.PagingResultBean;
32  import org.dbflute.optional.OptionalEntity;
33  
34  public class WebConfigService {
35  
36      @Resource
37      protected WebConfigBhv webConfigBhv;
38  
39      @Resource
40      protected WebAuthenticationBhv webAuthenticationBhv;
41  
42      @Resource
43      protected RequestHeaderBhv requestHeaderBhv;
44  
45      @Resource
46      protected FessConfig fessConfig;
47  
48      public List<WebConfig> getWebConfigList(final WebConfigPager webConfigPager) {
49  
50          final PagingResultBean<WebConfig> webConfigList = webConfigBhv.selectPage(cb -> {
51              cb.paging(webConfigPager.getPageSize(), webConfigPager.getCurrentPageNumber());
52              setupListCondition(cb, webConfigPager);
53          });
54  
55          // update pager
56          BeanUtil.copyBeanToBean(webConfigList, webConfigPager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
57          webConfigPager.setPageNumberList(webConfigList.pageRange(op -> {
58              op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger());
59          }).createPageNumberList());
60  
61          return webConfigList;
62      }
63  
64      public void delete(final WebConfig webConfig) {
65  
66          final String webConfigId = webConfig.getId();
67  
68          webConfigBhv.delete(webConfig, op -> {
69              op.setRefreshPolicy(Constants.TRUE);
70          });
71  
72          webAuthenticationBhv.queryDelete(cb -> {
73              cb.query().setWebConfigId_Equal(webConfigId);
74          });
75  
76          requestHeaderBhv.queryDelete(cb -> {
77              cb.query().setWebConfigId_Equal(webConfigId);
78          });
79      }
80  
81      public OptionalEntity<WebConfig> getWebConfig(final String id) {
82          return webConfigBhv.selectByPK(id);
83      }
84  
85      public void store(final WebConfig webConfig) {
86          webConfigBhv.insertOrUpdate(webConfig, op -> {
87              op.setRefreshPolicy(Constants.TRUE);
88          });
89      }
90  
91      protected void setupListCondition(final WebConfigCB cb, final WebConfigPager webConfigPager) {
92          if (webConfigPager.id != null) {
93              cb.query().docMeta().setId_Equal(webConfigPager.id);
94          }
95          // TODO Long, Integer, String supported only.
96  
97          // setup condition
98          cb.query().addOrderBy_SortOrder_Asc();
99          cb.query().addOrderBy_Name_Asc();
100 
101         // search
102 
103     }
104 
105 }