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.Collection;
19  import java.util.List;
20  
21  import javax.annotation.Resource;
22  
23  import org.codelibs.core.beans.util.BeanUtil;
24  import org.codelibs.fess.Constants;
25  import org.codelibs.fess.app.pager.PathMapPager;
26  import org.codelibs.fess.es.config.cbean.PathMappingCB;
27  import org.codelibs.fess.es.config.exbhv.PathMappingBhv;
28  import org.codelibs.fess.es.config.exentity.PathMapping;
29  import org.codelibs.fess.mylasta.direction.FessConfig;
30  import org.codelibs.fess.util.ComponentUtil;
31  import org.dbflute.cbean.result.PagingResultBean;
32  import org.dbflute.optional.OptionalEntity;
33  
34  public class PathMappingService {
35  
36      @Resource
37      protected PathMappingBhv pathMappingBhv;
38  
39      @Resource
40      protected FessConfig fessConfig;
41  
42      public List<PathMapping> getPathMappingList(final PathMapPager pathMappingPager) {
43  
44          final PagingResultBean<PathMapping> pathMappingList = pathMappingBhv.selectPage(cb -> {
45              cb.paging(pathMappingPager.getPageSize(), pathMappingPager.getCurrentPageNumber());
46              setupListCondition(cb, pathMappingPager);
47          });
48  
49          // update pager
50          BeanUtil.copyBeanToBean(pathMappingList, pathMappingPager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
51          pathMappingPager.setPageNumberList(pathMappingList.pageRange(op -> {
52              op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger());
53          }).createPageNumberList());
54  
55          return pathMappingList;
56      }
57  
58      public OptionalEntity<PathMapping> getPathMapping(final String id) {
59          return pathMappingBhv.selectByPK(id);
60      }
61  
62      public void store(final PathMapping pathMapping) {
63  
64          pathMappingBhv.insertOrUpdate(pathMapping, op -> {
65              op.setRefreshPolicy(Constants.TRUE);
66          });
67  
68          ComponentUtil.getPathMappingHelper().init();
69      }
70  
71      public void delete(final PathMapping pathMapping) {
72  
73          pathMappingBhv.delete(pathMapping, op -> {
74              op.setRefreshPolicy(Constants.TRUE);
75          });
76  
77          ComponentUtil.getPathMappingHelper().init();
78      }
79  
80      public List<PathMapping> getPathMappingList(final Collection<String> processTypeList) {
81  
82          return pathMappingBhv.selectList(cb -> {
83              cb.query().addOrderBy_SortOrder_Asc();
84              cb.query().setProcessType_InScope(processTypeList);
85              cb.fetchFirst(fessConfig.getPagePathMappingMaxFetchSizeAsInteger());
86          });
87      }
88  
89      protected void setupListCondition(final PathMappingCB cb, final PathMapPager pathMappingPager) {
90          if (pathMappingPager.id != null) {
91              cb.query().docMeta().setId_Equal(pathMappingPager.id);
92          }
93          // TODO Long, Integer, String supported only.
94  
95          // setup condition
96          cb.query().addOrderBy_SortOrder_Asc();
97          cb.query().addOrderBy_CreatedTime_Asc();
98  
99          // search
100 
101     }
102 
103 }