View Javadoc
1   /*
2    * Copyright 2012-2025 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 org.codelibs.core.beans.util.BeanUtil;
21  import org.codelibs.core.lang.StringUtil;
22  import org.codelibs.fess.Constants;
23  import org.codelibs.fess.app.pager.BoostDocPager;
24  import org.codelibs.fess.mylasta.direction.FessConfig;
25  import org.codelibs.fess.opensearch.config.cbean.BoostDocumentRuleCB;
26  import org.codelibs.fess.opensearch.config.exbhv.BoostDocumentRuleBhv;
27  import org.codelibs.fess.opensearch.config.exentity.BoostDocumentRule;
28  import org.dbflute.cbean.result.PagingResultBean;
29  import org.dbflute.optional.OptionalEntity;
30  
31  import jakarta.annotation.Resource;
32  
33  /**
34   * Service class for boost document rule management operations.
35   * Provides CRUD operations for boost document rules.
36   */
37  public class BoostDocumentRuleService extends FessAppService {
38      /**
39       * Default constructor for BoostDocumentRuleService.
40       */
41      public BoostDocumentRuleService() {
42          super();
43      }
44  
45      /** Database behavior for boost document rule operations. */
46      @Resource
47      protected BoostDocumentRuleBhv boostDocumentRuleBhv;
48  
49      /** Fess configuration. */
50      @Resource
51      protected FessConfig fessConfig;
52  
53      /**
54       * Gets a paginated list of boost document rules.
55       * @param boostDocumentRulePager The pager with search criteria and pagination settings.
56       * @return List of boost document rules matching the criteria.
57       */
58      public List<BoostDocumentRule> getBoostDocumentRuleList(final BoostDocPager boostDocumentRulePager) {
59  
60          final PagingResultBean<BoostDocumentRule> boostDocumentRuleList = boostDocumentRuleBhv.selectPage(cb -> {
61              cb.paging(boostDocumentRulePager.getPageSize(), boostDocumentRulePager.getCurrentPageNumber());
62              setupListCondition(cb, boostDocumentRulePager);
63          });
64  
65          // update pager
66          BeanUtil.copyBeanToBean(boostDocumentRuleList, boostDocumentRulePager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
67          boostDocumentRulePager.setPageNumberList(
68                  boostDocumentRuleList.pageRange(op -> op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger())).createPageNumberList());
69  
70          return boostDocumentRuleList;
71      }
72  
73      /**
74       * Gets a boost document rule by its ID.
75       * @param id The boost document rule ID.
76       * @return Optional entity containing the boost document rule if found.
77       */
78      public OptionalEntity<BoostDocumentRule> getBoostDocumentRule(final String id) {
79          return boostDocumentRuleBhv.selectByPK(id);
80      }
81  
82      /**
83       * Stores (inserts or updates) a boost document rule.
84       * @param boostDocumentRule The boost document rule to store.
85       */
86      public void store(final BoostDocumentRule boostDocumentRule) {
87  
88          boostDocumentRuleBhv.insertOrUpdate(boostDocumentRule, op -> op.setRefreshPolicy(Constants.TRUE));
89  
90      }
91  
92      /**
93       * Deletes a boost document rule.
94       * @param boostDocumentRule The boost document rule to delete.
95       */
96      public void delete(final BoostDocumentRule boostDocumentRule) {
97  
98          boostDocumentRuleBhv.delete(boostDocumentRule, op -> op.setRefreshPolicy(Constants.TRUE));
99  
100     }
101 
102     /**
103      * Sets up search conditions for boost document rule list queries.
104      * @param cb The condition bean for the query.
105      * @param boostDocumentRulePager The pager containing search criteria.
106      */
107     protected void setupListCondition(final BoostDocumentRuleCB cb, final BoostDocPager boostDocumentRulePager) {
108         if (StringUtil.isNotBlank(boostDocumentRulePager.urlExpr)) {
109             cb.query().setUrlExpr_Wildcard(wrapQuery(boostDocumentRulePager.urlExpr));
110         }
111         if (StringUtil.isNotBlank(boostDocumentRulePager.boostExpr)) {
112             cb.query().setBoostExpr_Wildcard(wrapQuery(boostDocumentRulePager.boostExpr));
113         }
114         // TODO Long, Integer, String supported only.
115 
116         // setup condition
117         cb.query().addOrderBy_SortOrder_Asc();
118         cb.query().addOrderBy_CreatedTime_Asc();
119 
120         // search
121 
122     }
123 
124 }