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 org.apache.logging.log4j.LogManager;
19  import org.apache.logging.log4j.Logger;
20  import org.codelibs.fess.app.service.WebConfigService;
21  import org.codelibs.fess.opensearch.config.bsentity.BsRequestHeader;
22  import org.codelibs.fess.util.ComponentUtil;
23  
24  /**
25   * @author FreeGen
26   */
27  public class RequestHeader extends BsRequestHeader {
28  
29      private static final long serialVersionUID = 1L;
30  
31      private static final Logger logger = LogManager.getLogger(RequestHeader.class);
32  
33      private WebConfig webConfig;
34  
35      public String getId() {
36          return asDocMeta().id();
37      }
38  
39      public void setId(final String id) {
40          asDocMeta().id(id);
41      }
42  
43      public Long getVersionNo() {
44          return asDocMeta().version();
45      }
46  
47      public void setVersionNo(final Long version) {
48          asDocMeta().version(version);
49      }
50  
51      public org.codelibs.fess.crawler.client.http.RequestHeader getCrawlerRequestHeader() {
52          return new org.codelibs.fess.crawler.client.http.RequestHeader(getName(), getValue());
53      }
54  
55      public WebConfig getWebConfig() {
56          if (webConfig == null) {
57              final WebConfigService webConfigService = ComponentUtil.getComponent(WebConfigService.class);
58              try {
59                  webConfig = webConfigService.getWebConfig(getWebConfigId()).get();
60              } catch (final Exception e) {
61                  logger.warn("Web Config {} does not exist.", getWebConfigId(), e);
62              }
63          }
64          return webConfig;
65      }
66  
67      @Override
68      public String toString() {
69          return "RequestHeader [webConfig=" + webConfig + ", createdBy=" + createdBy + ", createdTime=" + createdTime + ", name=" + name
70                  + ", updatedBy=" + updatedBy + ", updatedTime=" + updatedTime + ", value=" + value + ", webConfigId=" + webConfigId
71                  + ", docMeta=" + docMeta + "]";
72      }
73  }