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.opensearch.config.exentity;
17  
18  import java.util.ArrayList;
19  import java.util.Arrays;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.codelibs.core.lang.StringUtil;
24  import org.codelibs.fess.mylasta.direction.FessConfig;
25  import org.codelibs.fess.opensearch.config.bsentity.BsElevateWord;
26  import org.codelibs.fess.opensearch.config.exbhv.ElevateWordToLabelBhv;
27  import org.codelibs.fess.opensearch.config.exbhv.LabelTypeBhv;
28  import org.codelibs.fess.util.ComponentUtil;
29  import org.dbflute.cbean.result.ListResultBean;
30  
31  /**
32   * @author ESFlute (using FreeGen)
33   */
34  public class ElevateWord extends BsElevateWord {
35  
36      private static final long serialVersionUID = 1L;
37  
38      private String[] labelTypeIds;
39  
40      private volatile List<LabelType> labelTypeList;
41  
42      /* (non-Javadoc)
43       * @see org.codelibs.fess.db.exentity.CrawlingConfig#getLabelTypeIds()
44       */
45      public String[] getLabelTypeIds() {
46          if (labelTypeIds == null) {
47              return StringUtil.EMPTY_STRINGS;
48          }
49          return labelTypeIds;
50      }
51  
52      public void setLabelTypeIds(final String[] labelTypeIds) {
53          this.labelTypeIds = labelTypeIds;
54      }
55  
56      public List<LabelType> getLabelTypeList() {
57          if (labelTypeList == null) {
58              synchronized (this) {
59                  if (labelTypeList == null) {
60                      final FessConfig fessConfig = ComponentUtil.getFessConfig();
61                      final ElevateWordToLabelBhv elevateWordToLabelBhv = ComponentUtil.getComponent(ElevateWordToLabelBhv.class);
62                      final ListResultBean<ElevateWordToLabel> mappingList = elevateWordToLabelBhv.selectList(cb -> {
63                          cb.query().setElevateWordId_Equal(getId());
64                          cb.specify().columnLabelTypeId();
65                          cb.paging(fessConfig.getPageLabeltypeMaxFetchSizeAsInteger(), 1);
66                      });
67                      final List<String> labelIdList = new ArrayList<>();
68                      for (final ElevateWordToLabel mapping : mappingList) {
69                          labelIdList.add(mapping.getLabelTypeId());
70                      }
71                      final LabelTypeBhv labelTypeBhv = ComponentUtil.getComponent(LabelTypeBhv.class);
72                      labelTypeList = labelIdList.isEmpty() ? Collections.emptyList() : labelTypeBhv.selectList(cb -> {
73                          cb.query().setId_InScope(labelIdList);
74                          cb.query().addOrderBy_SortOrder_Asc();
75                          cb.fetchFirst(fessConfig.getPageLabeltypeMaxFetchSizeAsInteger());
76                      });
77                  }
78              }
79          }
80          return labelTypeList;
81      }
82  
83      public String[] getLabelTypeValues() {
84          final List<LabelType> list = getLabelTypeList();
85          final List<String> labelValueList = new ArrayList<>(list.size());
86          for (final LabelType labelType : list) {
87              labelValueList.add(labelType.getValue());
88          }
89          return labelValueList.toArray(new String[labelValueList.size()]);
90      }
91  
92      public String getId() {
93          return asDocMeta().id();
94      }
95  
96      public void setId(final String id) {
97          asDocMeta().id(id);
98      }
99  
100     public Long getVersionNo() {
101         return asDocMeta().version();
102     }
103 
104     public void setVersionNo(final Long version) {
105         asDocMeta().version(version);
106     }
107 
108     @Override
109     public String toString() {
110         return "ElevateWord [labelTypeIds=" + Arrays.toString(labelTypeIds) + ", labelTypeList=" + labelTypeList + ", boost=" + boost
111                 + ", createdBy=" + createdBy + ", createdTime=" + createdTime + ", reading=" + reading + ", suggestWord=" + suggestWord
112                 + ", updatedBy=" + updatedBy + ", updatedTime=" + updatedTime + ", docMeta=" + docMeta + "]";
113     }
114 
115 }