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.web.admin.fileconfig;
17  
18  import org.codelibs.fess.Constants;
19  import org.codelibs.fess.app.web.CrudMode;
20  import org.codelibs.fess.mylasta.direction.FessConfig;
21  import org.codelibs.fess.util.ComponentUtil;
22  import org.codelibs.fess.validation.CustomSize;
23  import org.codelibs.fess.validation.UriType;
24  import org.codelibs.fess.validation.UriTypeValidator.ProtocolType;
25  import org.lastaflute.web.validation.Required;
26  import org.lastaflute.web.validation.theme.conversion.ValidateTypeFailure;
27  
28  import jakarta.validation.constraints.Max;
29  import jakarta.validation.constraints.Min;
30  import jakarta.validation.constraints.Size;
31  
32  /**
33   * The create form for File Config.
34   *
35   */
36  public class CreateForm {
37  
38      /**
39       * Creates a new CreateForm instance.
40       */
41      public CreateForm() {
42      }
43  
44      /** The IDs of label types associated with this file configuration. */
45      public String[] labelTypeIds;
46  
47      /** The CRUD operation mode for this form. */
48      @ValidateTypeFailure
49      public Integer crudMode;
50  
51      /** The name of the file configuration (required, maximum 200 characters). */
52      @Required
53      @Size(max = 200)
54      public String name;
55  
56      /** The description of the file configuration (maximum 1000 characters). */
57      @Size(max = 1000)
58      public String description;
59  
60      /** The file paths to crawl (required, must be valid file URIs). */
61      @Required
62      @UriType(protocolType = ProtocolType.FILE)
63      @CustomSize(maxKey = "form.admin.max.input.size")
64      public String paths;
65  
66      /** The paths to include during crawling (pattern-based). */
67      @CustomSize(maxKey = "form.admin.max.input.size")
68      public String includedPaths;
69  
70      /** The paths to exclude during crawling (pattern-based). */
71      @CustomSize(maxKey = "form.admin.max.input.size")
72      public String excludedPaths;
73  
74      /** The document paths to include in search results (pattern-based). */
75      @CustomSize(maxKey = "form.admin.max.input.size")
76      public String includedDocPaths;
77  
78      /** The document paths to exclude from search results (pattern-based). */
79      @CustomSize(maxKey = "form.admin.max.input.size")
80      public String excludedDocPaths;
81  
82      /** Additional configuration parameters for the file crawler. */
83      @CustomSize(maxKey = "form.admin.max.input.size")
84      public String configParameter;
85  
86      /** The maximum crawling depth (0 to 2147483647, 0 means unlimited). */
87      @Min(value = 0)
88      @Max(value = 2147483647)
89      @ValidateTypeFailure
90      public Integer depth;
91  
92      /** The maximum number of documents to access during crawling (0 means unlimited). */
93      @Min(value = 0)
94      @Max(value = 9223372036854775807L)
95      @ValidateTypeFailure
96      public Long maxAccessCount;
97  
98      /** The number of threads to use for crawling (required, 1 to 2147483647). */
99      @Required
100     @Min(value = 1)
101     @Max(value = 2147483647)
102     @ValidateTypeFailure
103     public Integer numOfThread;
104 
105     /** The interval time between crawl requests in milliseconds (required, 0 to 2147483647). */
106     @Required
107     @Min(value = 0)
108     @Max(value = 2147483647)
109     @ValidateTypeFailure
110     public Integer intervalTime;
111 
112     /** The boost value for search ranking (required). */
113     @Required
114     @ValidateTypeFailure
115     public Float boost;
116 
117     /** Whether this configuration is available for crawling (required, maximum 5 characters). */
118     @Required
119     @Size(max = 5)
120     public String available;
121 
122     /** The permissions required to access documents from this configuration. */
123     @CustomSize(maxKey = "form.admin.max.input.size")
124     public String permissions;
125 
126     /** The virtual hosts associated with this file configuration. */
127     @CustomSize(maxKey = "form.admin.max.input.size")
128     public String virtualHosts;
129 
130     /** The sort order for this configuration (required, 0 to 2147483647). */
131     @Required
132     @Min(value = 0)
133     @Max(value = 2147483647)
134     @ValidateTypeFailure
135     public Integer sortOrder;
136 
137     /** The user who created this file configuration (maximum 1000 characters). */
138     @Size(max = 1000)
139     public String createdBy;
140 
141     /** The timestamp when this file configuration was created. */
142     @ValidateTypeFailure
143     public Long createdTime;
144 
145     /**
146      * Initializes the form with default values for creation mode.
147      */
148     public void initialize() {
149         crudMode = CrudMode.CREATE;
150         final FessConfig fessConfig = ComponentUtil.getFessConfig();
151         includedPaths = fessConfig.getCrawlerDocumentFileDefaultIncludeIndexPatterns();
152         excludedPaths = fessConfig.getCrawlerDocumentFileDefaultExcludeIndexPatterns();
153         includedDocPaths = fessConfig.getCrawlerDocumentFileDefaultIncludeSearchPatterns();
154         excludedDocPaths = fessConfig.getCrawlerDocumentFileDefaultExcludeSearchPatterns();
155         boost = 1.0f;
156         numOfThread = Constants.DEFAULT_NUM_OF_THREAD_FOR_FS;
157         intervalTime = Constants.DEFAULT_INTERVAL_TIME_FOR_FS;
158         sortOrder = 0;
159         createdBy = ComponentUtil.getSystemHelper().getUsername();
160         createdTime = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
161         permissions = fessConfig.getSearchDefaultDisplayPermission();
162     }
163 }