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